Skip to content

Instantly share code, notes, and snippets.

View pancurster's full-sized avatar

Łukasz Panek pancurster

  • Chełm
View GitHub Profile
@pancurster
pancurster / latency.txt
Created November 6, 2015 16:55 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@pancurster
pancurster / bit_table.c
Created May 19, 2013 18:50
Implementacja i przykład tablicy bitów
#include <limits.h> /* for CHAR_BIT */
#define BITMASK(b) (1 << ((b) % CHAR_BIT))
#define BITSLOT(b) ((b) / CHAR_BIT)
#define BITSET(a, b) ((a)[BITSLOT(b)] |= BITMASK(b))
#define BITCLEAR(a, b) ((a)[BITSLOT(b)] &= ~BITMASK(b))
#define BITTEST(a, b) ((a)[BITSLOT(b)] & BITMASK(b))
#define BITNSLOTS(nb) ((nb + CHAR_BIT - 1) / CHAR_BIT)
(If you don't have <limits.h>, try using 8 for CHAR_BIT.)
Here are some usage examples. To declare an ``array'' of 47 bits:
/*
* My MEM-TEST-SUITE based on Michael Barr code
*/
/* badanie zwarc miedzy nogami */
int mem_short_test(U8* saddr, int size)
{
char buf[256];
U8 pattern = 0xAA;
int addr_mask = size-1;
@pancurster
pancurster / tcp.c
Created August 17, 2012 06:10
lwIP fragment?
do { \
pcb->next = *&tcp_bound_pcbs; \
*(&tcp_bound_pcbs) = pcb; \
tcp_timer_needed(); \
} while (0)
@pancurster
pancurster / domkniecia.js
Created August 1, 2012 22:04
Domknięcia w JS
var foo = function() {
if (typeof foo.i == 'undefined') {
foo.i = 0;
}
++foo.i;
return [ function() {
return --foo.i;
},
@pancurster
pancurster / bi.c
Created July 22, 2012 20:38
Bit setter
#include <stdio.h>
#include <stdlib.h>
void setbit(int* data, char from, char len, int val)
{
unsigned int b = ~0;
b >>= sizeof(int)*8 - len;
*data &= ~(b << from-len);
*data |= (val << from-len);
}
@pancurster
pancurster / bit_pack.c
Created July 18, 2012 08:33
rozwiazanie pakowania bitow do bufora
uint b = 0;
uchar k = 0;
uchar dop = 0;
uchar last_reg = 0;
i = 0;
uchar reg = 0;
// Przepisywanie wartosci do rejestrow
/*
for (k=0; k<4; ++k) {
uchar pelne = roz[k] / 8;
setInterval(function(){
$.ajax({ url: "server", success: function(data){
//Update your dashboard gauge
salesGauge.setValue(data.value);
}, dataType: "json"});
}, 30000);
(function poll(){
setTimeout(function(){
$.ajax({ url: "server", success: function(data){
@pancurster
pancurster / for_each.c
Created March 18, 2012 15:27
for_each in C
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#define for_each(i, list) \
for(i = list; \
i != NULL; \
i = i->next)
struct lista {
@pancurster
pancurster / mib_js_fill.htm
Created March 7, 2012 20:38
Jak wypełnić formy zmiennymi z MIB'a
<form name="userinfo" method="get" action="info.html">
<p>Please give us your information, so that we can send
you spam.</p>
<p>Name: <input type="text" name="name"/></p>
<p>E-Mail: <input type="text" name="email"/></p>
<p>Sex: <select name="sex">
<option>Male</option>
<option>Female</option>
<option>Other</option>
</select></p>