Skip to content

Instantly share code, notes, and snippets.

View gdamjan's full-sized avatar

Дамјан Георгиевски gdamjan

View GitHub Profile
@gdamjan
gdamjan / title.alert.js
Created September 12, 2011 00:49
a simple javascript module to flash the window title
var $TitleAlert = (function(document, window, undefined) {
var options = {
count: 2, // by default flash 2 times
period: 1200, // default period 1200ms
flashTitle: " --- ** --- "
}
// private
var origTitle = document.title;
var intervalID = undefined;
@gdamjan
gdamjan / proplist_to_record.hrl
Created September 13, 2011 12:41
Erlang macro to create proplist_to_record functions
%%% This is a clever Erlang macro that given a record name will create a new function
%%% that converts from a property list to the record (which really is a taged tuple).
-define(proplist_to_record(Record),
fun(Proplist) ->
Fields = record_info(fields, Record),
[Tag| Values] = tuple_to_list(#Record{}),
Defaults = lists:zip(Fields, Values),
L = lists:map(fun ({K,V}) -> proplists:get_value(K, Proplist, V) end, Defaults),
list_to_tuple([Tag|L])
@gdamjan
gdamjan / count-github-commits.py
Created September 25, 2011 20:18
A python script to count commits in all of your own repositories on github (not cheking branches)
#! /usr/bin/env python2
import json
import requests
def count_user_commits(user):
r = requests.get('https://api.github.com/users/%s/repos' % user)
repos = json.loads(r.content)
for repo in repos:
@gdamjan
gdamjan / new.js
Created October 3, 2011 00:47
CouchDB update function to collect data from the github POST hook
/*
see http://wiki.apache.org/couchdb/Document_Update_Handlers
in a couchapp this would be updates/new.js or something
you then setup githubs POST hook to this update function, something like:
http://hostname.example.net/database/_design/github/_update/new
see http://help.github.com/post-receive-hooks/
*/
function (_doc, req) {
if (req.method !== 'POST') {
@gdamjan
gdamjan / record_to_list.hrl
Created October 8, 2011 19:45
An erlang macro that creates a function to convert a record to a key-value list
%%% This macro will create a function that converts a record to
%%% a {key, value} list (a proplist)
-define(record_to_list(Record),
fun(Val) ->
Fields = record_info(fields, Record),
[_Tag| Values] = tuple_to_list(Val),
lists:zip(Fields, Values)
end
).
@gdamjan
gdamjan / make-pxe-environment.sh
Created October 10, 2011 22:20
Make and start a PXE server
#!/bin/sh
mkdir /home/tftproot
# install syslinux from package and symlink it or just download and extract it
ln -s /usr/lib/syslinux /home/tftproot/syslinux
mkdir /home/tftproot/pxelinux.cfg/
cat > /home/tftproot/pxelinux.cfg/default <<EOF
@gdamjan
gdamjan / longpoll-xhr-watchdog.js
Created October 15, 2011 13:20
watchdog for longpoll connections in a browser - the demo gevent server pings the browser 10 times, then stalls. The javascript watchdog should detect this and abort the connection.
function xhr_watchdog(httpRequest, interval) {
const max_tries = 2
function _watchdog(last_length, n) {
if (httpRequest.readyState <= 3) {
var new_length = httpRequest.responseText.length
if (new_length > last_length) {
document.body.innerHTML +="Connection alive<br>\n"
window.setTimeout(_watchdog, interval, new_length, max_tries)
} else if (n > 0) {
n = n - 1;
@gdamjan
gdamjan / _config
Created October 21, 2011 13:37
my kernel config / 32bit
#
# Automatically generated file; DO NOT EDIT.
# Linux/x86 3.10.0 Kernel Configuration
#
# CONFIG_64BIT is not set
CONFIG_X86_32=y
CONFIG_X86=y
CONFIG_INSTRUCTION_DECODER=y
CONFIG_OUTPUT_FORMAT="elf32-i386"
CONFIG_ARCH_DEFCONFIG="arch/x86/configs/i386_defconfig"
@gdamjan
gdamjan / index.html
Created October 21, 2011 14:02
stretch input field to 100%
<html>
<!-- WILL NOT WORK with the HTML5 doctype -->
<div class="text-stretch">
<input />
</div>
</html>
@gdamjan
gdamjan / 3g
Created December 2, 2011 21:37
connect to 3G from command line (with pppd and chat)
# file: /etc/ppp/peers/3g
# usage: pppd call 3g
connect '/etc/ppp/peers/dial -V -Upublicinternet -T*99***1#'
user internet
password internet
noauth
usepeerdns