Skip to content

Instantly share code, notes, and snippets.

View samhocevar's full-sized avatar
💭
😄

Sam Hocevar samhocevar

💭
😄
View GitHub Profile
<Multi_key> <backslash> <#> <space> : "#" # \#
<Multi_key> <backslash> <$> <space> : "$" # \$
<Multi_key> <backslash> <%> <space> : "%" # \%
<Multi_key> <backslash> <&> <space> : "&" # \&
<Multi_key> <backslash> <l> <b> <r> <a> <c> <k> <space> : "[" # \lbrack
<Multi_key> <backslash> <b> <a> <c> <k> <s> <l> <a> <s> <h> <space> : "\\" # \backslash
<Multi_key> <backslash> <r> <b> <r> <a> <c> <k> <space> : "]" # \rbrack
<Multi_key> <backslash> <_> <space> : "_" # \_
<Multi_key> <backslash> <{> <space> : "{" # \{
<Multi_key> <backslash> <}> <space> : "}" # \}
function inflate(s,p,l)local r={}for i=0,255 do r[i]=0 for j=0,7 do r[i]+=band(i,2^j)*128/4^j end end local u={}for i=1,58 do u[sub("0123456789abcdefghijklmnopqrstuvwxyz!#%(){}[]<>+=/*:;.,~_ ",i,i)]=i end local e=0local sb=0local sb2=0local sn=0local o={}local op=1local function flb(n)sn-=n sb=lshr(sb,n)end local function h(n)while sn<n do if l and l>0then sb+=shr(peek(p),16-sn)sn+=8 p+=1 l-=1 elseif e==0then local x=2^-16local t={9,579}local p=0sb2=0 for i=1,8 do local c=u[sub(s,i,i)]or 0 sb2+=x%1*c p+=(lshr(x,16)+(t[i-6]or 0))*c x*=59 end s=sub(s,9)sb+=sb2%1*2^sn sn+=16 e+=1 sb2=p+shr(sb2,16)elseif e==1then sb+=sb2%1*2^sn sn+=16 e+=1 else sb+=lshr(sb2,16)*2^sn sn+=15 e=0 end end return lshr(shl(sb,32-n),16-n)end local function g(n)return h(n),flb(n)end local function v(t)h(t.n)local h=r[band(shl(sb,16),255)]local l=r[band(shl(sb,8),255)]local v=band(shr(256*h+l,16-t.n),2^t.n-1)flb(t[v]%1*16)return flr(t[v])end local function w(n)local d=(op)%1local p=flr(op)o[p]=n*256^(4*d-2)+(o[p]or 0)op+=1/4 end local fun
def make_meta_file_from_list(loc_list, url, params=None, flag=None,
progress=lambda x: None, progress_percent=True):
"""Make a single .torrent file for a given list of items"""
if params is None:
params = {}
if flag is None:
flag = threading.Event()
tree = bttree_from_list(loc_list)
@samhocevar
samhocevar / gist:781ed03690972c56de3f
Created May 4, 2015 22:13
Using a PRNG to hash integers
#include <stdio.h>
#include <stdlib.h>
int const WIDTH = 512;
int const HEIGHT = 512;
int main(int argc, char *argv[])
{
/* Pass the seed as the first argument */
int seed = argc > 1 ? atoi(argv[1]) : 0;
@samhocevar
samhocevar / gist:00eec26d9e9988d080ac
Last active September 5, 2024 15:58
Configure sshd on MSYS2 and run it as a Windows service
#!/bin/sh
#
# msys2-sshd-setup.sh — configure sshd on MSYS2 and run it as a Windows service
#
# Please report issues and/or improvements to Sam Hocevar <sam@hocevar.net>
#
# Prerequisites:
# — MSYS2 itself: http://sourceforge.net/projects/msys2/
# — admin tools: pacman -S openssh cygrunsrv mingw-w64-x86_64-editrights
#