https://github.com/vprelovac/python-speed
I main… | Read the rest of https://www.webhostingtalk.com/showthread.php?t=1839597&goto=newpost
New and Fresh Private + Public Proxies Lists Everyday!
Get and Download New Proxies from NewProxyLists.com
https://github.com/vprelovac/python-speed
I main… | Read the rest of https://www.webhostingtalk.com/showthread.php?t=1839597&goto=newpost
There are a number of issues in this very short program.
Unless there are coding standards that require otherwise, it is better to use typedef
to define types rather than #define
.
You are calling standard C libraries when you call printf()
, scanf()
, memmove()
and strlen()
unless you have written all of these functions on your own and linking in some sort of special manner.
It is not a good idea to redefine size_t
at any point since it is defined by the system header files and may be different on different platforms (the Windows version of size_t
is different than the Fedora Linux version of size_t
for example).
The code contains a possible buffer overflow when performing the scanf()
. The array ch
is only 50 characters. This can lead to undefined behavior.
You don’t need a long long
for an array that is a maximum of 50 characters.
I’m writing a little library for some undocumented file formats. The original program uses a path string to find files in an archive and this function tries to do the same.
The archive contains a magic string, an offset into the file list, the data in the files and the file list itself. A entry in the filelist consists of a path (256 bytes long, 0-padded) and three numbers, the second one being the offset from the archive start to the entry file. The entries are sorted alphabetically respecting case; here are some mockup paths to demonstrate the ordering:
Entry/Graphics/Sprite.cgf
Entry/Sound/Ding.wav
Quit/Graphics/exit.cgf
_RAW8123
Here are the relevant utility functions and defines. These are defined in Utils.h
and Utils.c
, I’ve put them here together for context.
#define BYTESZE sizeof(char)
typedef unsigned int uint;
typedef unsigned char byte;
uint readU4L(FILE* file) {
byte buf(4);
fread(buf, BYTESZE, 4, file);
return buf(3) << 24 | buf(2) << 16 | buf(1) << 8 | buf(0);
}
Finally, here’s the “library”:
// ====== BIGfile.h
#define BIG_MAGIC_LEN 7
#define BIG_SEEK_SUCC 1
#define BIG_SEEK_FAIL 0
typedef struct BIGFile {
char magic(BIG_MAGIC_LEN);
uint offset;
FILE* read;
} BIGFile;
BIGFile* load_BIGFile(char* fpath);
int seekToEntry(BIGFile* bigfile, char* path);
// ====== BIGFile.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Utils.h"
#include "BIGFile.h"
BIGFile* load_BIGFile(char* fpath) {
BIGFile* bigfile = malloc(sizeof(BIGFile));
fopen_s(&(bigfile->read), fpath, "rb");
if (!bigfile->read) {
printf("Can't open file.n");
return 0;
}
fread(bigfile->magic, BYTESZE, BIG_MAGIC_LEN, bigfile->read);
bigfile->offset = readU4L(bigfile->read);
return bigfile;
}
int seekToEntry(BIGFile* bigfile, char* path) {
fseek(bigfile->read, bigfile->offset, SEEK_SET);
byte buf(256);
int pos = 0;
// while not EOF, read string part
while (fread(buf, BYTESZE, 256, bigfile->read)) {
// seek over entry data
fseek(bigfile->read, 12, SEEK_CUR);
// loop until given path != read path
while (path(pos)==buf(pos)) {
pos++;
// path has ended, so buf == path
if (!path(pos)) {
// seek back into entry data
fseek(bigfile->read, -8, SEEK_CUR);
// read unsigned little endian 4-byte int
uint res = readU4L(bigfile->read);
// seek there and return success
fseek(bigfile->read, res, SEEK_SET);
//printf("found at %dn", res);
return BIG_SEEK_SUCC;
}
}
// path char is smaller than buf char
// we seeked past where the entry could bem return failure
if (path(pos)<buf(pos)) {
return BIG_SEEK_FAIL;
}
}
// EOF, return failure
return BIG_SEEK_FAIL;
}
I’d like some feedback on general style, as well as on the seekToEntry
function, perhaps this can be improved somehow? Thanks in advance!
let i = 1;
function myFunction(){
n = i.toString();
let theInput = document.getElementById('input').value;
if(theInput == ""){
return false;
}
else{
let input = `<li class = list id = div${n}>` + theInput +` <button onclick = myFunction2("div${n}")>Done</button>`;
newDiv = document.createElement(`div${n}`);
newDiv.innerHTML = input;
const currentDiv = document.getElementById("div0");
currentDiv.insertBefore(newDiv, currentDiv.nextSibling);
i++;
}
}
const myFunction2 = function(id){
let dou = document.getElementById(id)
dou.remove();
}
const myFunction3 = function(className){
let elements = document.getElementsByClassName(className);
while(elements.length > 0){
elements(0).parentNode.removeChild(elements(0));
}
}
h1{
font-family: Kufam;
font-size: 50px;
border-color: black;
border-style: solid;
border-width: 12px;
border-radius: 8px;
text-align: center;
}
.list{
font-family: Kufam;
font-size: 25px;
text-align: center;
}
<!DOCTYPE html>
<html>
<title>To do List</title>
<header>
<link href="https://fonts.googleapis.com/css?family=Kufam" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="todoliststyle.css">
<script type="text/javascript" src="functionList.js"></script>
<h1>
<br>To do List <br>
<input id="input" type="text" placeholder="what to do" required maxlength="50">
<button onclick="myFunction()" >Add</button>
<button onclick="myFunction3(`list`)">Clear All</button> <br><br>
</h1>
<div id="div0">
</header>
</html>
I intend to write a parser for SGF. Since I don’t have any previous experience in parsing, I’m looking for critique regarding the simple lexer implementation I just did. Any suggestions on using modern c++ features or issues with the code are also appreciated.
The SGF format specification: https://www.red-bean.com/sgf/sgf4.html#1
This what the format basically look like
(;FF(4)C(root)SZ(19);B(aa);W(ab))
Here’s the parser.hpp:
#ifndef SGF_PARSER_SGF_PARSER_HPP
#define SGF_PARSER_SGF_PARSER_HPP
#include <iostream>
namespace sgf {
enum tokentype {
left_paren, // 0. (
right_paren,// 1. )
left_brkt, // 2. (
right_brkt, // 3. )
semi_colon, // 4. ;
text, // 5. any other letter
};
struct token {
tokentype type;
std::string value;
};
token get_token(std::string &game);
}// namespace sgf
#endif//SGF_PARSER_SGF_PARSER_HPP
parser.cpp:
#include "parser.hpp"
sgf::token sgf::get_token(std::string &game) {
sgf::token current;
bool done = false;
std::string text;
while (!done && !game.empty()) {
// In order to simplify looping
// copy the value and remove from the string till it's empty
char c = game.at(0);
if (!text.empty() && (c ==';' || c =='(' || c ==')' || c =='(' || c ==')')) {
current.type = sgf::text;
current.value = text;
return current;
}
// only destroy it after checking if we gonna use it
game.erase(game.begin());
switch (c) {
case ';': {
current.type = sgf::semi_colon;
current.value = ';';
done = true;
break;
}
case '(': {
current.type = sgf::left_paren;
current.value = '(';
done = true;
break;
}
case ')': {
current.type = sgf::right_paren;
current.value = ')';
done = true;
break;
}
case '(': {
current.type = sgf::left_brkt;
current.value = '(';
done = true;
break;
}
case ')': {
current.type = sgf::right_brkt;
current.value = ')';
done = true;
break;
}
default:
text.push_back(c);
}
}
return current;
}
I will create a simple but Professional HTML5 website – One page or Multi PageFor Busines presentations, Corporate, Creative, Education etc…You can show me some examples of the websites if you want it to look similar.Also you will have to describe me what the website is about, so i can know how should the website look.I am front end developer, professional in HTML5.Conact me before the ordering
.
The program transfers a data array from a Zynq-7000 PS DDR to a BRAM IP (block RAM) memory in a PL part of a FPGA due to a PL AXI DMA IP. Inferring a xilinx axi dma driver (not scatter-gather mode), an interrupt controller and the vendor’s printf function the data array is carried from the DDR to the BRAM.
main.c
#include "xstatus.h"
#include "platform_.h"
#include "axi_dma_intr_poll.h"
#define TX_BUFFER (uint32_t *) 0x01100000
#define RX_BUFFER (uint32_t *) XPAR_BRAM_0_BASEADDR
#define RESET_TIMEOUT_CNTR_VAL 0x1000
#define MAX_TX_VALUE 0x100
#define PAYLOAD_SIZE MAX_TX_VALUE
volatile _Bool tx_done_flag, rx_done_flag, tx_error, rx_error;
axi_dma_init_str init;
axi_dma_poll_str poll;
axi_dma_handler_str handler;
static void tx_intr_handler(void *callback);
static void rx_intr_handler(void *callback);
static inline void printf_array(uint32_t *p_array, size_t size);
int main(void) {
uint8_t mul_coefficient = 0;
const uint8_t c_ascii_num_offset = 0x30;
uint32_t i = 0;
memset((uint8_t *) XPAR_BRAM_0_BASEADDR,0,0x100);
init.dma_id = XPAR_AXIDMA_0_DEVICE_ID;
init.rx_intr_handler = rx_intr_handler;
init.tx_intr_handler = tx_intr_handler;
init.rx_intr_id = XPAR_FABRIC_AXIDMA_0_S2MM_INTROUT_VEC_ID;
init.tx_intr_id = XPAR_FABRIC_AXIDMA_0_MM2S_INTROUT_VEC_ID;
poll.p_tx_buf = TX_BUFFER;
poll.p_rx_buf = RX_BUFFER;
poll.size = PAYLOAD_SIZE;
axi_dma_init(&init, &handler);
while(1) {
xil_printf("AXI DMA %d: ready. Insert multiplier coefficient (1 - 9): ", init.dma_id);
mul_coefficient = inbyte();
mul_coefficient -= c_ascii_num_offset;
xil_printf("%dnr", mul_coefficient);
for(i = 0; i < MAX_TX_VALUE; i++) {
poll.p_tx_buf(i) = (i * mul_coefficient) % MAX_TX_VALUE;
}
tx_done_flag = FALSE;
rx_done_flag = FALSE;
axi_dma_poll(&poll, &handler.axi_dma, init.dma_id);
xil_printf("AXI DMA %d: waiting completion of the poll...", init.dma_id);
while((FALSE == tx_done_flag) || (FALSE == rx_done_flag)) {
asm("NOP");
}
if ((TRUE == tx_error) || (TRUE == rx_error)) {
xil_printf("AXI DMA %d ERROR: the polling ERROR", init.dma_id);
}
else {
xil_printf("nnrAXI DMA %d: the tx buffer:nr", init.dma_id);
printf_array(TX_BUFFER ,PAYLOAD_SIZE);
xil_printf("nnrAXI DMA %d: the rx buffer:nr", init.dma_id);
printf_array(RX_BUFFER, PAYLOAD_SIZE);
}
xil_printf("nnr");
}
return XST_SUCCESS;
}
static void tx_intr_handler(void *callback) {
uint32_t status = 0;
int reset_cntr = RESET_TIMEOUT_CNTR_VAL;
XAxiDma *axi_dma = (XAxiDma *) callback;
status = XAxiDma_IntrGetIrq(axi_dma, XAXIDMA_DMA_TO_DEVICE);
XAxiDma_IntrAckIrq(axi_dma, status, XAXIDMA_DMA_TO_DEVICE);
tx_done_flag = TRUE;
if (FALSE != (status & XAXIDMA_IRQ_ALL_MASK) &&
(TRUE == (status & XAXIDMA_IRQ_ERROR_MASK))) {
tx_error = TRUE;
XAxiDma_Reset(axi_dma);
while (reset_cntr--) {
if (XAxiDma_ResetIsDone(axi_dma)) {
break;
}
}
}
}
static void rx_intr_handler(void *callback)
{
uint32_t status = 0;
int reset_cntr = RESET_TIMEOUT_CNTR_VAL;
XAxiDma *axi_dma = (XAxiDma *) callback;
status = XAxiDma_IntrGetIrq(axi_dma, XAXIDMA_DEVICE_TO_DMA);
XAxiDma_IntrAckIrq(axi_dma, status, XAXIDMA_DEVICE_TO_DMA);
rx_done_flag = TRUE;
if ((FALSE != (status & XAXIDMA_IRQ_ALL_MASK)) &&
(TRUE == (status & XAXIDMA_IRQ_ERROR_MASK))) {
rx_error = TRUE;
XAxiDma_Reset(axi_dma);
while (reset_cntr--) {
if (XAxiDma_ResetIsDone(axi_dma)) {
break;
}
}
}
}
static inline void printf_array(uint32_t *p_array, size_t size) {
const uint8_t c_values_per_line = 10;
uint32_t i = 0;
for(i = 0; i < size; i++) {
xil_printf("%d ", *(TX_BUFFER + i));
if (FALSE == (i % c_values_per_line) && (0 != i)) {
xil_printf("nr");
}
}
}
axi_dma_intr_poll.c
#include "xil_exception.h"
#include "axi_dma_intr_poll.h"
static int enable_intr_(axi_dma_handler_str *p_handler, axi_dma_init_str *p_init);
int axi_dma_init(axi_dma_init_str *p_init, axi_dma_handler_str *p_handler) {
if ((NULL == p_init) || (NULL == p_handler)) {
xil_printf("AXI DMA %d ERROR: the entire axi_dma_init function ERRORrn", p_init->dma_id);
return XST_FAILURE;
}
memset(p_handler, 0, sizeof(axi_dma_handler_str));
p_handler->p_config = XAxiDma_LookupConfig(p_init->dma_id);
if (NULL == p_handler->p_config) {
xil_printf("AXI DMA %d ERROR: the dma lookup config FAILEDrn", p_init->dma_id);
return XST_FAILURE;
}
if (XST_SUCCESS != XAxiDma_CfgInitialize(&(p_handler->axi_dma), p_handler->p_config)) {
xil_printf("AXI DMA %d ERROR: the dma initialization FAILEDrn", p_init->dma_id);
return XST_FAILURE;
}
if(TRUE == XAxiDma_HasSg(&(p_handler->axi_dma))){
xil_printf("AXI DMA %d ERROR: the device configured as SG modern", p_init->dma_id);
return XST_FAILURE;
}
if (XST_SUCCESS != enable_intr_(p_handler, p_init)) {
xil_printf("AXI DMA %d ERROR: the interrupt setup FAILEDrn");
return XST_FAILURE;
}
return XST_SUCCESS;
}
int axi_dma_poll(axi_dma_poll_str *p_poll, XAxiDma *p_axi_dma, uint32_t dma_id) {
if ((NULL == p_poll) || (NULL == p_axi_dma)) {
xil_printf("AXI DMA %d ERROR: the entire axi_dma_poll function ERRORrn", dma_id);
return XST_FAILURE;
}
Xil_DCacheFlushRange((UINTPTR) (p_poll->p_tx_buf), p_poll->size);
if (XST_SUCCESS != XAxiDma_SimpleTransfer(p_axi_dma,(UINTPTR) (p_poll->p_tx_buf),
p_poll->size, XAXIDMA_DMA_TO_DEVICE)) {
xil_printf("AXI DMA %d ERROR: the tx buffer setting FAILEDrn", dma_id);
return XST_FAILURE;
}
if (XST_SUCCESS != XAxiDma_SimpleTransfer(p_axi_dma,(UINTPTR) (p_poll->p_rx_buf),
p_poll->size, XAXIDMA_DEVICE_TO_DMA)) {
xil_printf("AXI DMA %d ERROR: the rx buffer setting FAILEDrn", dma_id);
return XST_FAILURE;
}
return XST_SUCCESS;
}
int axi_dma_release(XScuGic *p_scu_gic, uint32_t tx_intr_id, uint32_t rx_intr_id) {
if ((NULL == p_scu_gic) || (0 == tx_intr_id) || (0 == rx_intr_id)) {
xil_printf("AXI DMA %d ERROR: the entire axi_dma_release function ERRORrn", p_scu_gic->Config->DeviceId);
return XST_FAILURE;
}
XScuGic_Disconnect(p_scu_gic, tx_intr_id);
XScuGic_Disconnect(p_scu_gic, rx_intr_id);
return XST_SUCCESS;
}
static int enable_intr_(axi_dma_handler_str *p_handler, axi_dma_init_str *p_init) {
const uint8_t c_priority = 0xA0, c_trigger_type = 0x3;
p_handler->p_intc_config = XScuGic_LookupConfig(XPAR_SCUGIC_SINGLE_DEVICE_ID);
if (NULL == p_handler->p_intc_config) {
xil_printf("AXI DMA %d ERROR: the scu gic lookup config FAILEDrn", p_init->dma_id);
return XST_FAILURE;
}
if (XST_SUCCESS != XScuGic_CfgInitialize(&(p_handler->scu_gic), p_handler->p_intc_config,
p_handler->p_intc_config->CpuBaseAddress)) {
xil_printf("AXI DMA %d ERROR: the scu gic initialization FAILEDrn", p_init->dma_id);
return XST_FAILURE;
}
XScuGic_SetPriorityTriggerType(&(p_handler->scu_gic), p_init->tx_intr_id, c_priority, c_trigger_type);
XScuGic_SetPriorityTriggerType(&(p_handler->scu_gic), p_init->rx_intr_id, c_priority, c_trigger_type);
if (XST_SUCCESS != XScuGic_Connect(&(p_handler->scu_gic), p_init->tx_intr_id,
(Xil_InterruptHandler)p_init->tx_intr_handler,
&(p_handler->axi_dma))) {
xil_printf("AXI DMA %d ERROR: the scu gic tx connection FAILEDrn", p_init->dma_id);
return XST_FAILURE;
}
if (XST_SUCCESS != XScuGic_Connect(&(p_handler->scu_gic), p_init->rx_intr_id,
(Xil_InterruptHandler)p_init->rx_intr_handler,
&(p_handler->axi_dma))) {
xil_printf("AXI DMA %d ERROR: the scu gic rx connection FAILEDrn", p_init->dma_id);
return XST_FAILURE;
}
XScuGic_Enable(&(p_handler->scu_gic), p_init->tx_intr_id);
XScuGic_Enable(&(p_handler->scu_gic), p_init->rx_intr_id);
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XScuGic_InterruptHandler,
(void *)&(p_handler->scu_gic));
Xil_ExceptionEnable();
XAxiDma_IntrDisable(&(p_handler->axi_dma), XAXIDMA_IRQ_ALL_MASK,
XAXIDMA_DMA_TO_DEVICE);
XAxiDma_IntrDisable(&(p_handler->axi_dma), XAXIDMA_IRQ_ALL_MASK,
XAXIDMA_DEVICE_TO_DMA);
XAxiDma_IntrEnable(&(p_handler->axi_dma), XAXIDMA_IRQ_ALL_MASK,
XAXIDMA_DMA_TO_DEVICE);
XAxiDma_IntrEnable(&(p_handler->axi_dma), XAXIDMA_IRQ_ALL_MASK,
XAXIDMA_DEVICE_TO_DMA);
return XST_SUCCESS;
}
axi_dma_intr_poll.h
#ifndef INC_AXI_DMA_POLL_H
#define INC_AXI_DMA_POLL_H
#include "xaxidma.h"
#include "xscugic.h"
#include "platform_.h"
typedef struct {
uint32_t *p_tx_buf;
uint32_t *p_rx_buf;
size_t size;
} axi_dma_poll_str;
typedef struct {
uint32_t tx_intr_id;
uint32_t rx_intr_id;
void (*rx_intr_handler)(void *);
void (*tx_intr_handler)(void *);
uint32_t dma_id;
} axi_dma_init_str;
typedef struct {
XAxiDma axi_dma;
XAxiDma_Config *p_config;
XScuGic scu_gic;
XScuGic_Config *p_intc_config;
} axi_dma_handler_str;
int axi_dma_init(axi_dma_init_str *p_init, axi_dma_handler_str *p_handler);
int axi_dma_poll(axi_dma_poll_str *p_poll, XAxiDma *p_axi_dma, uint32_t dma_id);
int axi_dma_release(XScuGic *p_scu_gic, uint32_t tx_intr_id, uint32_t rx_intr_id);
#endif
Let $S$ be a compact surface and $g$ its genus defined in terms of Euler characteristic.
Why is $g$ the maximum number of simple closed curves that can be embedded in the surface without disconnecting it?
I would be grateful if anyone could tell me how to prove it or give me a reference. Thanks.
So the main problem is
def f(x,y):
return (2*x,2*y)
def g(x,y):
return (-x,-y)
z = g(0,1)
print(z)
print(f(z))
it’s an example. I have one function and returned two values.
And I want to print the f(g(0,1)), do you have any idea with it?