View merge_sort.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sort(l): | |
if len(l) <= 1: | |
return l | |
mid = len(l) // 2 | |
return merge(sort(l[:mid]), sort(l[mid:])) | |
def merge(l, r): | |
out = [] | |
while l and r: | |
if l[0] <= r[0]: |
View dj_rest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic import View | |
from django.http import ( | |
QueryDict, HttpResponse, HttpResponseBadRequest, | |
HttpResponseNotFound, HttpResponseNotAllowed, | |
) | |
from django.core.serializers.json import DjangoJSONEncoder | |
from django.core.exceptions import ( | |
ObjectDoesNotExist, ValidationError, | |
) | |
from django.db import transaction |
View django_login_wrapper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import HttpResponse | |
from json import dumps | |
def errorify(message): | |
return HttpResponse(dumps({ | |
'error': message | |
}), content_type = 'application/json') | |
View db_query_stringify.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"database/sql" | |
"fmt" | |
_ "github.com/lib/pq" | |
) | |
// Connection pool as a singleton | |
var dbConn *sql.DB | |
/* Returns an open connection to the database |
View tetris.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import choice | |
from copy import deepcopy | |
from sys import exit | |
# Initial shape matrices for the five Tetrominos | |
shapes = [[[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]], | |
[[1, 0, 0], [1, 0, 0], [1, 1, 0]], | |
[[0, 0, 1], [0, 0, 1], [0, 1, 1]], | |
[[0, 0, 1], [0, 1, 1], [0, 1, 0]], [[1, 1], [1, 1]]] |
View map_n_merge.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The last I checked, this gist can be run at: | |
http://play.golang.org/p/5keNQZLqfR | |
*/ | |
package main | |
import ( | |
"fmt" | |
"encoding/json" | |
) |
View gist:5637eef8fe4d6593b26f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hids [][]string | |
db, err := sql.Open("postgres", "user=myuser dbname=mydb sslmode=disable") | |
if err != nil { | |
log.Fatal(err) | |
os.Exit(1) | |
} else { | |
defer db.Close() | |
rows, err := db.Query(my_query) | |
if err != nil { | |
log.Println(err) |
View gist:7133657
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This fork removes the request parameter for use with Flask framework | |
class JsonSerializableMixin(object): | |
def __json__(self): | |
""" | |
Converts all the properties of the object into a dict for use in json. | |
You can define the following in your class | |
_json_eager_load : |
View mfrootdaemon.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -c /etc/rc.d/mfmrootdaemon /etc/rc.d/mfmrootdaemon.new | |
*** /etc/rc.d/mfmrootdaemon 2010-09-21 20:52:50.000000000 +0200 | |
--- /etc/rc.d/mfmrootdaemon.new 2010-09-22 21:27:34.382440785 +0200 | |
*************** | |
*** 95,101 **** | |
then | |
rm -rf $CIAODIR/* | |
# aplay /usr/share/sounds/mintfb-logout.wav & | |
! pm-suspend | |
fi |