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:1683661
Created January 26, 2012 16:34
screenshot sharing
#!/bin/bash
scrot '%Y-%m-%d_%H-%M-%S.png' -s -e 'scp $f leaf@leafo.net:www/shotsnb;echo -n "http://leafo.net/shotsnb/$f" | xclip; rm $f'
notify-send -u normal -t 1000 'Screenshot Ready'
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"
.test(left, @color) {
border-left: 1px solid @color;
}
.test(right, @color) {
border-right: 1px solid @color;
}
div {
.test(right, blue);
}
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) ->
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
lapis = require "lapis"
db = require "lapis.db"
lapis.serve class extends lapis.Application
"/": =>
json: db.query "select * from v_domains"
@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
@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:6880781
Created October 8, 2013 07:09
testing code coverage tool for moonscript
(master) ~/code/lua/moonscript > bin/moon -c test_cov.moon > /dev/null
Starting code coverage
Stopping code coverage
------| @test_cov.moon
1|
2|
* 3| hello = ->
* 4| x = 5 + 4
* 5| print "hello", x
6|
@leafo
leafo / gist:7191404
Last active December 26, 2015 17:59
Clone a function and its upvalues
local function clone_function(fn)
local dumped = string.dump(fn)
local cloned = loadstring(dumped)
local i = 1
while true do
local name, val = debug.getupvalue(fn, i)
if not name then
break
end
debug.setupvalue(cloned, i, val)