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:7946062
Created December 13, 2013 15:36
using other data sources in lapis config
import config from require "lapis.config"
json_file = (fname) ->
json = require "cjson"
file = assert io.open fname
with json.decode file\read "*a"
file\close!
config {"production", "development"}, ->
@leafo
leafo / gist:7837657
Last active December 30, 2015 13:48
local lapis = require("lapis")
local app = lapis.Application()
app:match("/user/:id", function(self)
return "Hello user " .. self.params.id
end)
-- named route
app:match("about", "/about", function()
return "welcome to the about page"
worker_processes 1;
error_log stderr notice;
daemon off;
# Adding these will make the second server correct
# env LUA_PATH;
# env LUA_CPATH;
events {
worker_connections 1024;
@leafo
leafo / gist:7780535
Last active December 30, 2015 05:09
select sum(count) from downloads_daily where date >= '2013-12-01' and date < '2014-1-1';
6852
select count(*) from games where published and not deleted and created_at >= '2013-12-01' and created_at < '2014-1-1';
170
select count(*) from purchases where status = 1 and created_at >= '2013-12-01' and created_at < '2014-1-1';
1403
select (sum(price)/100.0)::money from purchases where status = 1 and created_at >= '2013-12-01' and created_at < '2014-1-1';
@leafo
leafo / gist:7745145
Last active December 29, 2015 23:49
worker_processes 1;
error_log stderr notice;
daemon off;
events {
worker_connections 1024;
}
http {
server {
@leafo
leafo / gist:7461977
Created November 14, 2013 05:39
some itch.io stats
-- total games
itchio=# select count(*) from games where not deleted and published;
count
-------
258
(1 row)
-- total downloads
@leafo
leafo / gist:7427317
Last active December 28, 2015 02:19
postgres function to update game full text search table
create or replace function update_game_search(_game_id integer) returns text as $$
declare
game record;
game_words tsvector;
game_facets tsvector;
index_lang regconfig := 'english';
begin
select title, short_text, p_windows, p_linux, p_osx, deleted, published,
min_price, genre, "type"
into game
@leafo
leafo / gist:7380556
Last active December 27, 2015 19:58
gup
function _annotate() {
echo "$(tput setaf 4)>>$(tput sgr0) $@"
$@
}
function gup() {
branch=$([[ -n "$1" ]] && echo "$1" || git rev-parse --abbrev-ref HEAD)
dirty=$(git diff --shortstat 2> /dev/null | tail -n1)
_annotate git fetch || return
@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)
@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|