Skip to content

Instantly share code, notes, and snippets.

View tkrajina's full-sized avatar
🏠
Working from home

Tomo Krajina tkrajina

🏠
Working from home
View GitHub Profile
@tkrajina
tkrajina / gist:5252035
Created March 27, 2013 05:58
Minimalistic javascript assert with stacktrace.
if(!window.assert) {
window.assert = function() {
if(!arguments.length || arguments < 2) {
alert('Invalid assert, use assert(expression, message1, message2, ...)')
return
}
var expression = arguments[0]
if(!expression) {
var message = ''
for(i = 1; i < arguments.length; i++) message += ' ' + arguments[i]
@tkrajina
tkrajina / gist:5418085
Created April 19, 2013 04:07
OpenStreetMap images layer on Google Map
map.mapTypes.set("OSM", new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
var imagesPerUnit = Math.pow(2, zoom);
// Stitch horizontaly:
var x = coord.x < 0 ? imagesPerUnit + (coord.x % imagesPerUnit) : coord.x;
var x = x >= imagesPerUnit ? 0 : x;
// Do not stitch verticaly, if overflow -- don't show:
if(coord.y < 0 || coord.y >= imagesPerUnit)
@tkrajina
tkrajina / xwindows_and_PIDs.c
Created December 13, 2013 10:20
List of windows + their PIDs
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <stdlib.h>
#include <stdio.h>
void print_window_properties(Display *display, Window *window) {
char *window_name;
int pid;
{
@tkrajina
tkrajina / gist:8095177
Created December 23, 2013 11:01
String not startding with str1, str2, str3, ...
^(?!(str1)|(str2)|(str3)|(str4)).*$
# -*- coding: utf-8 -*-
import logging as mod_logging
import cartesius.main as mod_cartesius
import cartesius.charts as mod_charts
import cartesius.colors as mod_colors
import srtm as mod_srtm
import gpxpy.geo as mod_geo
mod_logging.basicConfig(level=mod_logging.DEBUG,
import sys
from django.conf import settings
from django.conf.urls import patterns
from django.http import HttpResponse
from django.core.management import execute_from_command_line
settings.configure(
DEBUG=True,
SECRET_KEY='trla_baba_lan',
@tkrajina
tkrajina / pyctags.sh
Created April 15, 2014 04:44
ctags for python projects
ctags -R . $(python -c "import sys;print(' '.join(sys.path))")
@tkrajina
tkrajina / mysite.com
Created April 17, 2014 12:45
Minimal apache mod_wsgi config
<VirtualHost *:80>
ServerName mysite.com
#ServerAlias ...
ServerAdmin webmaster@mysite.com
DocumentRoot .../projects/mysite
#Alias /robots.txt .../projects/qreminder-on-email/static/robots.txt
#Alias /favicon.ico .../projects/qreminder-on-email/static/favicon.ico
@tkrajina
tkrajina / django_paginator_with_raw_query.py
Created April 25, 2014 18:35
Django paginator with RawQuerySet
# Dummy model:
class DbCounter(models.Model):
count = models.IntegerField()
def get_count(table, where):
# Check strings for sql injections here before doing this!
return DbCounter.objects.raw('select 1 as id, count(*) as count from %s where %s' % (table, where))[0].count
# View:
def index(request):
@tkrajina
tkrajina / extract_unicode_words.py
Created April 27, 2014 05:33
Extract unicode words from string
# -*- coding: utf-8 -*-
import unicodedata as mod_unicodedata
all_unicode = ''.join(unichr(i) for i in xrange(65536))
UNICODE_LETTERS = ''.join(c for c in all_unicode if mod_unicodedata.category(c)=='Lu' or mod_unicodedata.category(c)=='Ll')
UNICODE_LETTERS_AND_NUMBERS = '1234567890' + UNICODE_LETTERS
def extract_unicode_words(text, allowed_chars=None):
if text.__class__ != unicode: