Skip to content

Instantly share code, notes, and snippets.

View lionello's full-sized avatar
🇭🇰

Lio李歐 lionello

🇭🇰
View GitHub Profile
@lionello
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
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
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
const WCHAR root[] = L"..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\.git\\HEAD";
int __stdcall _main() {
@lionello
lionello / bootstrap.lua
Last active August 31, 2015 06:07
ELLA test
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 / wol.c
Created September 8, 2013 02:48
Wake-On-LAN
// 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>
/* 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 / 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,
的: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 / parseder.d
Created May 5, 2017 12:16
Parse a DER or PEM (base64) encoded ASN.1 file (certificates, keys, ...)
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
lionello / countingkeywords.d
Created May 5, 2017 12:18
Count/detect popular words in social media messages
#!/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 = inner.save;//refRange(&inner);
foreach (ref d; buffer) {
@lionello
lionello / slowprint.sh
Last active May 5, 2017 12:19
Print contents of a text file to stdout, slowly...
#!/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
@lionello
lionello / robo.ino
Created May 5, 2017 12:25
A simple wall-following robot in Arduino (from Xinchejian roborace)
#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)
{