Skip to content

Instantly share code, notes, and snippets.

Avatar
🇭🇰

Lio李歐 lionello

🇭🇰
View GitHub Profile
View wol.c
// Portable Wake-On-Lan by Lionello Lunesu, placed in the public domain
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#ifdef _MSC_VER
#pragma comment(lib, "ws2_32.lib")
#endif
#else
#include <sys/socket.h>
@lionello
lionello / cas128.c
Last active Apr 7, 2022
__sync_val_compare_and_swap for __uint128_t GCC built-in
View cas128.c
/*
__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
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
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
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
const WCHAR root[] = L"..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\.git\\HEAD";
int __stdcall _main() {
@lionello
lionello / .vimrc
Last active Aug 5, 2019
My .vimrc
View .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
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
lionello / nrf_ws2812.h
Last active Sep 16, 2017
Bit-banging a WS2812/WS2812B LED on Nordic nRF51 platform (nRF51422 or nRF51822)
View nrf_ws2812.h
#define NOP() __asm volatile ( "NOP" )
void ws2812_init(void)
{
NRF_GPIO->PIN_CNF[PIN_WS_DIN] = (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos)
| (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
| (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
| (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
}
View bootstrap.lua
wifi.setmode(wifi.STATION)
wifi.sta.config('XinCheJian','imakestuff')
c=net.createConnection(net.TCP, 0)
c:on('connection',function(conn) c:send('GET /api/values/0 HTTP/1.1\r\nHost: thenounproxy.azurewebsites.net\r\nConnection: close\r\n\r\n') file.open('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 )
c:connect(80,'thenounproxy.azurewebsites.net')
@lionello
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,
的:d,一:y,是:s,在:z,人:r,有:y,不:b,国:g,这:z,了:l,中:z,和:h,为:w,们:m,他:t,我:w,个:g,以:y,大:d,上:s,地:d,要:y,会:[h,k],对:d,时:s,到:d,于:y,来:l,生:s,能:n,年:n,可:k,而:e,行:[h,x],出:c,发:f,用:y,作:z,种:z,就:j,法:f,所:s,成:c,学:x,自:z,经:j,方:f,之:z,理:l,定:d,也:y,部:b,说:s,分:f,家:j,同:t,主:z,其:q,后:h,动:d,过:g,多:d,现:x,进:j,得:d,本:b,如:r,业:y,民:m,者:z,下:x,事:s,实:s,工:g,当:d,性:x,因:y,些:x,机:j,与:y,它:t,力:l,产:c,日:r,关:g,政:z,公:g,第:d,使:s,然:r,物:w,面:m,由:y,体:t,制:z,那:n,或:h,但:d,全:q,都:d,应:y,从:[c,z],子:z,前:q,意:y,利:l,开:k,军:j,并:b,重:[c,z],合:[h,g],此:c,样:y,美:m,十:s,将:j,加:j,无:w,外:w,化:h,新:x,最:z,高:g,里:l,明:m,长:[c,z],起:q,等:d,相:x,还:h,代:d,战:z,度:d,间:j,文:w,你:n,道:d,正:z,内:n,表:b,三:s,果:g,天:t,特:t,情:q,心:x,问:w,着:z,没:m,及:j,月:y,系:x,资:z,被:b,只:[q,z],提:[d,t],论:l,已:y,通:t,二:e,斯:s,义:y,务:w,任:r,建:j,题:t,员:y,教:j,好:h,各:g,世:s,西:x,点:d,量:l,数:s,向:x,市:s,么:[
@lionello
lionello / slowprint.sh
Last active May 5, 2017
Print contents of a text file to stdout, slowly...
View slowprint.sh
#!/bin/bash
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