Skip to content

Instantly share code, notes, and snippets.

View yne's full-sized avatar
✔️
Not a virus

Rémy F. yne

✔️
Not a virus
View GitHub Profile
@yne
yne / ftp_proxy.c
Created December 18, 2015 22:58
Offer an active FTP interface over a passiv FTP server
#include <stdlib.h>//exit
#include <stdio.h>
#include <pthread.h>
#include <netdb.h> //NI_NUMERICHOST
#include <string.h>//strlen
#include <unistd.h>//read write close fork
#define ss2sa(ss) ((struct sockaddr *)(ss))
#define $(X) if((err=(X))<0)die(__LINE__,err)
#define Write(A,B) write(A,B,strlen(B))
#define Read(A,B) len=read(A,B,sizeof(B));buf[len]=0;
@yne
yne / bms_player_sdl.c
Created December 18, 2015 23:13
Easily hackable SDL based BMS player
/*
http://bm98.yaneu.com/bm98/bmsformat.html
http://fileformats.wikia.com/wiki/Be-Music_Script
http://mrqqn.net/dotclear/public/beatmaker/bms-specification.txt
http://hitkey.nekokan.dyndns.info/cmds.htm
*/
#include <malloc.h>
#include <string.h>
#include <fcntl.h>
#include <SDL/SDL.h>
@yne
yne / gluminess.c
Created December 19, 2015 00:17
Luminess in pure OpenGL
#include <windows.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/wglext.h>
#include <sys/time.h>
#define COUNT(A) (sizeof(A)/sizeof(A[0]))
#define BLOC_EXIST (1<<0)
#define BLOC_COLOR (1<<1)
@yne
yne / bin_extract.c
Created December 20, 2015 22:14
Extract from a blob using file header
#include <stdio.h>
#include <string.h>
char* headers[]={
"ID3",
"GIF89",
"‰PNG",
"OggS",
"ÿØÿà",
"BM6x",
@yne
yne / glx.c
Created January 11, 2016 00:28
X11+OpenGL Cube demo
#include <stdio.h>
#include <stdlib.h>
#include <X11/X.h>
#include <GL/gl.h>
#include <GL/glx.h>
GLuint texture[1];
int initGL(GLfloat width,GLfloat height){
uint8_t pixels[32*32*3];
FILE*f=fopen("sprite2.bmp","rb");
@yne
yne / web2fs.py
Last active February 27, 2016 10:20
Website as filesystem testing
#!/usr/bin/env python
import os,re,sys,json,errno,urllib2,urllib,threading
from fuse import FUSE, FuseOSError, Operations
class MyWebsite(Operations):
def __init__(self, root):
self.root = root
self.files = {}
self.cache = {}
@yne
yne / wav_play.c
Created June 9, 2016 21:04
Play argv wavs using ALSA
#include <alloca.h> /*needed (yet not included) by asoundlib in c99*/
#include <alsa/asoundlib.h>/* build with -lasound */
#include <stdint.h>
#define $(x) if ((x) < 0) { fprintf(stderr, "Error:%s", # x); return -1; }
#define MIN(A, B) ((A) < (B) ? (A) : (B))
typedef struct {
char RIFF[4];
uint32_t ChunkSize;
char WAVE[4];
char fmt[4];
@yne
yne / cli_chat.c
Created June 12, 2016 17:26
Console based Chat UI Mockup
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
#include <string.h>
#define POS(ROW,COL) printf("\033[%i;%iH", ROW, COL)
struct winsize w;
@yne
yne / json.c
Last active October 10, 2016 23:43
Smart json import/update into internal structure
#include <json-c/json.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
typedef enum{
diff_none,
diff_type,
diff_value,
diff_removed,
@yne
yne / kh_diff.c
Created February 13, 2017 23:45
khash diff example
#include <inttypes.h>
#include <stdio.h>
//#include "klist.h"
#include "khash.h"
#define kh_forall(h) for(khint_t __i=kh_begin(h);__i!=kh_end(h);++__i)if(kh_exist(h,__i))
#define kh_diff(name, old, new, on_add, on_keep, on_del)\
kh_forall(new){/*find added(exist in new, not in old) and kept(exist in both) entries */\
khiter_t __j = kh_get(name, old, kh_key(new,__i));\
if((__j==kh_end(old))||(!kh_exist(old,__j))){on_add;}else{on_keep;}\