Skip to content

Instantly share code, notes, and snippets.

lionello / wol.c
Created September 8, 2013 02:48
// 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>
lionello / cas128.c
Last active April 7, 2022 00:26
__sync_val_compare_and_swap for __uint128_t GCC built-in
__sync_val_compare_and_swap that works with __uint128_t, by Lionello Lunesu.
Placed in the public domain
#undef NDEBUG
#include <assert.h>
inline __uint128_t InterlockedCompareExchange128( volatile __uint128_t * src, __uint128_t cmp, __uint128_t with )
__asm__ __volatile__
lionello / even.c
Created February 23, 2014 03:39
even: skip every other byte in file/stdin
/* 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 August 29, 2015 13:56
__git_ps1 for 4NT/TCC, shows current GIT branch in prompt
@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() {
lionello / .vimrc
Last active August 5, 2019 07:11
My .vimrc
set nocompatible " be iMproved, required
filetype off " required
" Set the runtime path to include Vundle and initialize
"set rtp+=~/.vim/bundle/Vundle.vim
"call vundle#begin()
"Plugin 'VundleVim/Vundle.vim'
"Plugin 'Valloric/YouCompleteMe'
" All of your Plugins must be added before the following line
"call vundle#end() " required
/* 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 / nrf_ws2812.h
Last active September 16, 2017 01:08
Bit-banging a WS2812/WS2812B LED on Nordic nRF51 platform (nRF51422 or nRF51822)
#define NOP() __asm volatile ( "NOP" )
void ws2812_init(void)
lionello / bootstrap.lua
Last active August 31, 2015 06:07
ELLA test
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 )
lionello / pinyinmap.js
Last active October 22, 2016 18:25
`convertToPinYinSearch` converts text into ascii string with first PinYin letter for each Chinese character for autocomplete
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 /
Last active May 5, 2017 12:19
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