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: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: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: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: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: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';
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: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"
@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"}, ->
this.is.a.long.line
-- in coffee script we can do this:
this
.is.a
.long.line
-- but in moonscript, with's syntax uses the . as prefix for line
with something
@leafo
leafo / moonscript.lua
Created December 22, 2013 18:53
all of moonscript
package.preload['moonscript.transform.names'] = function()
local build
do
local _obj_0 = require("moonscript.types")
build = _obj_0.build
end
local unpack
do
local _obj_0 = require("moonscript.util")
unpack = _obj_0.unpack