Skip to content

Instantly share code, notes, and snippets.

@arjan
arjan / splash9patch
Created May 23, 2014 16:15
Quickly create a 9-patch image suitable as splash screen (Android)
#!/bin/bash
FILE="$1"
OUT=$(echo $FILE|sed -e 's/\./.9./')
$(identify -format "export WIDTH=%w" splash.png)
$(identify -format "export HEIGHT=%h" splash.png)
convert $FILE -bordercolor none -border 1 $OUT
-module(router).
-export([g/0]).
%% [{attribute,1,file,
%% {"/home/arjan/devel/zotonic/src/router.erl",1}},
%% {attribute,1,module,router},
%% {attribute,1,lager_records,[]},
%% {attribute,3,export,[{route,1}]},
%% {function,5,route,1,
@arjan
arjan / dbtestresults.txt
Created October 8, 2014 19:27
Speedup results of replacing the Zotonic database driver in release 0.11.0
SERIAL TESTS
------------
Old Zotonic PGSQL implementation w/ custom pgsql_pool
11:38:26.495 [info] squery test result: 42667 queries in 15000 ms (select now())
11:38:41.495 [info] squery test result: 43696 queries in 15000 ms (select true)
11:38:56.495 [info] squery test result: 46251 queries in 15000 ms (select 'hello')
11:39:11.495 [info] squery test result: 28560 queries in 15000 ms (select count(*) from rsc)
import gtk
import webkit
view = webkit.WebView()
sw = gtk.ScrolledWindow()
sw.add(view)
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.add(sw)
@arjan
arjan / controller.ex
Last active August 29, 2015 14:18
Twitter authorization controller
defmodule TestApp.TwitterController do
use Phoenix.Controller
# Routing configuration:
#
# scope "/twitter", TestApp do
# pipe_through :browser_session
# get "/:lang/authorize", TwitterController, :authorize
# get "/redirect", TwitterController, :authorize_return
@arjan
arjan / gist:92f45c10c1511ac16f33
Created June 30, 2015 06:35
GET /api/goldenage/favorites
"cards": [
{
"author": 356,
"category": "card",
"hashtags": [
{
"category": "hashtag",
"id": 355,
"title": "#gianluca"
import time
from smartcard.CardType import AnyCardType
from smartcard.CardRequest import CardRequest
from smartcard.util import toHexString
from smartcard.System import readers
print readers()
import webbrowser
cardtype = AnyCardType()
@arjan
arjan / timex_date_json.ex
Created November 6, 2015 01:45
Automatically encode Timex datetimes as ISO in JSON
defimpl Poison.Encoder, for: Timex.DateTime do
use Timex
def encode(d, _options) do
fmt = DateFormat.format!(d, "{ISO}")
"\"#{fmt}\""
end
end
@arjan
arjan / genserver_interface.ex
Created February 16, 2016 15:53
GenServer macros
defmodule GenServer.Interface do
defmacro defcall(function, arity) do
args = for n <- :lists.seq(1,arity), do: {"arg" <> Integer.to_string(n) |> String.to_atom, [], Elixir}
quote do
def unquote(function)(server, unquote_splicing(args)) do
GenServer.call(server, {unquote(function), unquote_splicing(args)})
end
end
end
@arjan
arjan / datetime.ex
Created April 25, 2016 12:58
Serialize Timex.DateTime to JSON automatically
defimpl Poison.Encoder, for: Timex.DateTime do
use Timex
def encode(d, _options) do
fmt = DateFormat.format!(d, "{ISO}")
"\"#{fmt}\""
end
end