Skip to content

Instantly share code, notes, and snippets.


Lio李歐 lionello

View GitHub Profile
lionello / even.c
Created Feb 23, 2014
even: skip every other byte in file/stdin
View even.c
/* even, by Lionello Lunesu, placed in the public domain */
#include <stdio.h>
int even(FILE * f)
char buf[4096];
int r, read, wrote;
while (1)
read = fread(buf, 1, sizeof(buf), f);
lionello / gb.cpp
Last active Aug 29, 2015
__git_ps1 for 4NT/TCC, shows current GIT branch in prompt
View gb.cpp
@cl "/Tp%~f0" /nologo /GS- /link /SUBSYSTEM:console /nodefaultlib /entry:_main kernel32.lib
@goto :EOF
__git_ps1 for 4NT/TCC, by Lionello Lunesu, placed in the Public Domain
Usage: prompt %%@exec[@gb.exe]$e[1m$P$e[0m$_$+$g
#include <windows.h>
const WCHAR root[] = L"..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\.git\\HEAD";
int __stdcall _main() {
View bootstrap.lua
c=net.createConnection(net.TCP, 0)
c:on('connection',function(conn) c:send('GET /api/values/0 HTTP/1.1\r\nHost:\r\nConnection: close\r\n\r\n')'init.lua','w') h='' end )
c:on('receive',function(c,p) if h then h=h..p local i=h:find('\r\n\r\n') if i then file.write(h:sub(i+4)) h=nil end else file.write(p) end end )
c:on('disconnection',function() file.close() dofile('init.lua') end )
View wol.c
// Portable Wake-On-Lan by Lionello Lunesu, placed in the public domain
#ifdef _WIN32
#include <windows.h>
#include <winsock2.h>
#ifdef _MSC_VER
#pragma comment(lib, "ws2_32.lib")
#include <sys/socket.h>
View patchbin.c
/* patchbin.c, Patch a binary file, by Lionello Lunesu, placed in the public domain */
struct FILE;
extern struct FILE* fopen(char*, char*);
extern int fwrite(void*, int, int, struct FILE*);
extern int fread(void*, int, int, struct FILE*);
extern int fseek(struct FILE*, long int, int);
#define SEEK_SET 0
extern int memcmp(void*, void*, int);
int main(int argc, char** argv)
lionello / pinyinmap.js
Last active Oct 22, 2016
`convertToPinYinSearch` converts text into ascii string with first PinYin letter for each Chinese character for autocomplete
View pinyinmap.js
var a='a',b='b',c='c',d='d',e='e',f='f',g='g',h='h',i='i',j='j',k='k',l='l',m='m',n='n',o='o',p='p',q='q',r='r',s='s',t='t',u='u',v='v',w='w',x='x',y='y',z='z';
var pinyinmap={a:a,b:b,c:c,d:d,e:e,f:f,g:g,h:h,i:i,j:j,k:k,l:l,m:m,n:n,o:o,p:p,q:q,r:r,s:s,t:t,u:u,v:v,w:w,x:x,y:y,z:z,
lionello / parseder.d
Created May 5, 2017
Parse a DER or PEM (base64) encoded ASN.1 file (certificates, keys, ...)
View parseder.d
import std.file : read;
import std.stdio;
import std.base64;
import std.string;
import std.conv;
import std.algorithm : map;
enum DerTag {
EndOfContent = 0x0,
Bool = 0x1,
lionello / countingkeywords.d
Created May 5, 2017
Count/detect popular words in social media messages
View countingkeywords.d
#!/usr/bin/env dmd -run
import std.range;
struct Words(R,int maxWordLen = 4)
int wordLen;
R inner;
dchar[maxWordLen] buffer;
this(R inner) {
this.inner =;//refRange(&inner);
foreach (ref d; buffer) {
lionello /
Last active May 5, 2017
Print contents of a text file to stdout, slowly...
echo -e $'\e[2J\e[32m'
while true; do
while IFS= read -rn1 i; do
printf %s "${i:-$'\n'}"
sleep 0.$(($RANDOM / 20000))
done < objects.txt
lionello / robo.ino
Created May 5, 2017
A simple wall-following robot in Arduino (from Xinchejian roborace)
View robo.ino
#define MOTOR_L_F 6
#define MOTOR_L_B 5
#define MOTOR_R_B 9
#define MOTOR_R_F 10
#define SENSOR_L 11
#define SENSOR_F 12
void left(int speed)