Skip to content

Instantly share code, notes, and snippets.

View valkheim's full-sized avatar
🔥
ORUGKIDHMFWWKCQ=

valkheim

🔥
ORUGKIDHMFWWKCQ=
View GitHub Profile
/* Implementation of Dekker's algorithm */
/* It allows two threads to share a single-use resource without conflict */
/* It uses only a shared memory for communication. */
#include <stdio.h>
#include <stdbool.h>
#include <pthread.h>
/* The counter threads will increment */
static unsigned int c;
@valkheim
valkheim / own_dump.c
Last active March 29, 2019 20:00
Dump itself
#include <stdio.h>
extern char __executable_start;
extern char __etext;
static void dump(const void* data, size_t size)
{
char ascii[17];
size_t i, j;
@valkheim
valkheim / sin.c
Created September 15, 2018 10:18
#include <stdio.h>
#include <math.h>
char wav_to_char(const float f)
{
return "_,.-*`''"[(unsigned char)((f + 1.f) * (7.f / 2.f))];
}
int main(void)
{
@valkheim
valkheim / Lexer.java
Created September 1, 2018 20:24
Basic java lexer
// http://www.giocc.com/writing-a-lexer-in-java-1-7-using-regex-named-capturing-groups.html
// javac Lexer.java && java Lexer
import java.util.ArrayList;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Lexer {
private static enum Token {
NUMBER("-?[0-9]+"), OPERATOR("[*|/|+|-]"), SKIP("[ \t\f\r\n]+");
@valkheim
valkheim / MifareClassicDump.ino
Created August 15, 2018 22:03
Révision du dump exemple fourni avec la lib Adafruit pour le pn532
#include <Adafruit_PN532.h>
#define PN532_IRQ (2)
#define PN532_RESET (3) // Not connected by default on the NFC Shield
// Shield with an I2C connection:
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
void setup(void) {
Serial.begin(115200);
@valkheim
valkheim / levensthein_distance.js
Created April 23, 2018 16:06
Levenshtein distance
'use strict'
const levenshtein = (a, b) => {
if (a.length == 0) return b.length
if (b.length == 0) return a.length
// swap to save some memory O(min(a,b)) instead of O(a)
if (a.length > b.length)
b = [a, a = b][0]
let row = []
for (let i = 0 ; i <= a.length ; ++i)
package main
import (
"fmt"
"reflect"
)
type Plop struct {
A string
}
package main
import (
"errors"
"fmt"
)
type queue struct {
Type string
Q []interface{}
@valkheim
valkheim / treq.ml
Created April 9, 2018 07:09
chameau
let rec appartenance f e = match e with
|[]-> false
|t::q-> if f=t then true else (appartenance f q);;
let res = appartenance ["valkheim"] ["valkheim";"niflheim";"muspelheim"];;
let rec ajout f e = match e with
|[]-> [f]
|t::q-> if f=t then e else t::(ajout f q);;
@valkheim
valkheim / pi.c
Created February 15, 2018 18:14
pi, the ascii way
#define _ F-->00 || F-OO--;
long F=00,OO=00;
main(){F_OO();printf("%1.3f\n", 4.*-F/OO/OO);}F_OO()
{
_-_-_-_
_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_