Skip to content

Instantly share code, notes, and snippets.

View leafo's full-sized avatar
🐔
bock bock

leaf leafo

🐔
bock bock
View GitHub Profile
@leafo
leafo / gist:6788652
Last active May 1, 2019 13:28
Making nonblocking http requests with lua-ev and LuaSocket
bit = require "bit"
ev = require "ev"
ltn12 = require "ltn12"
socket = require "socket"
-- make protect and newtry coroutine friendly
socket.protect = (fn) -> fn
socket.newtry = (finalizer) ->
(...) ->
@leafo
leafo / gist:5997612
Last active December 19, 2015 18:18
-- Iterate through each item in each array table passed to iterator
-- doesn't have any allocations
all_values = do
y = coroutine.yield
free_workers = setmetatable {}, __mode: "k"
process_head = (skip, first, ...) ->
y nil if skip
return if first == nil
lapis = require "lapis"
db = require "lapis.db"
lapis.serve class extends lapis.Application
"/": =>
json: db.query "select * from v_domains"
lpeg 0.10
Timings:
* assign p: 1.814ms c: 0.816ms
* bubbling p: 1.772ms c: 3.925ms
* class p: 2.610ms c: 18.459ms
* comprehension p: 2.478ms c: 3.077ms
* cond p: 2.801ms c: 2.379ms
* destructure p: 2.561ms c: 2.183ms
pt_in_box = (px, py, x1, y1, x2, y2) ->
if x2 < x1
x1,x2 = x2, x1
if y2 < y1
y1,y2 = y2, y1
not (px < x1 or px > x2 or py < y1 or py > y2)
line_intersection = (x1, y1, x2, y2, x3, y3, x4, y4, is_axis=false) ->
.test(left, @color) {
border-left: 1px solid @color;
}
.test(right, @color) {
border-right: 1px solid @color;
}
div {
.test(right, blue);
}
port = 8989
http = require "http"
spawn = require("child_process").spawn
banned = [
# "172.16.22.195"
# "172.16.22.149"
# "172.16.22.166"
# "172.16.22.98"
@leafo
leafo / gist:1683661
Created January 26, 2012 16:34
screenshot sharing
#!/bin/bash
scrot '%Y-%m-%d_%H-%M-%S.png' -s -e 'scp $f [email protected]:www/shotsnb;echo -n "http://leafo.net/shotsnb/$f" | xclip; rm $f'
notify-send -u normal -t 1000 'Screenshot Ready'