Skip to content

Instantly share code, notes, and snippets.

View skakri's full-sized avatar
🖱️
Click to enable Adobe Flash Player

Kristaps Karlsons skakri

🖱️
Click to enable Adobe Flash Player
View GitHub Profile
@skakri
skakri / mc_status.php
Created March 20, 2012 12:16
Minecraft status (PHP, returns MOTD, online user count, slots, request time)
<?php
/**
* @author Kristaps Karlsons <[email protected]>
* Licensed under MPL 1.1
*/
function mc_status($host,$port='25565') {
$timeInit = microtime();
// TODO: implement a way to store data (memcached or MySQL?) - please don't overload target server
$fp = fsockopen($host,$port,$errno,$errstr,$timeout=10);
@skakri
skakri / twitter_test.php
Created November 17, 2012 15:49
Twitter streaming API + URL unshortening
<?php
/**
* Unshorten links
*
* @param string $text
* @return string
*/
function unshorten_links($text) {
$pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
$callback = create_function('$matches', '
@skakri
skakri / worker-manager
Created December 17, 2012 19:33
Dreamwidth worker-manager init.d script
#!/bin/bash
# /etc/init.d/worker-manager
# version 0.1 2012-12-17 (YYYY-MM-DD)
### BEGIN INIT INFO
# Provides: worker-manager
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@skakri
skakri / vardadienas.json
Created March 22, 2013 21:50
Latviešu vārda dienu JSON
[{"0":["Laimnesis","Solvija","Solvita"],"1":["Indulis","Iva","Ivis","Ivo"],"2":["Miervalda","Miervaldis","Ringolds"],"3":["Ilva","Ilvita","Spodra"],"4":["S\u012bmanis","Zintis"],"5":["Arnita","Spulga"],"6":["Digm\u0101rs","Juli\u0101ns","Rota","Zigm\u0101rs"],"7":["Gatis","Ivanda"],"8":["Aksels","Alta","Kaspars"],"9":["Dorisa","Tatjana"],"10":["Franciska","Smaida"],"11":["Reina","Reinholds","Reinis","Ren\u0101ts"],"12":["Aira","\u0100rijs","\u0100ris","Harijs"],"13":["Raitis","Raits","Roberta","Roberts"],"14":["Felicita","F\u0113likss"],"15":["Lida","Lidija"],"16":["Dravis","Tenis"],"17":["Antis","Antonijs","Antons"],"18":["Alnis","Andulis"],"19":["Al\u0123is","A\u013c\u0123irds","O\u013c\u0123erts","Orests"],"20":["Agne","Agnese","Agnija"],"21":["Austris"],"22":["Grieta","Strauta","Rebeka"],"23":["Eglons","Kri\u0161s","Ksenija"],"24":["Sigurds","Sigvards","Zigurds"],"25":["Agneta","Agnis","Ansis"],"26":["Ildze","Ilze","Izolde"],"27":["K\u0101rlis","Spodris"],"28":["Aivars","Val\u0113rijs"],"29":["P\u0101rsla
@skakri
skakri / gist:5282381
Created March 31, 2013 23:10
Traceback for "Flask example - missing relation 'social_auth_usersocialauth'" issue (project: omab/python-social-auth)
Traceback (most recent call last):
File "/home/skakri/projects/test/virtualenv/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/home/skakri/projects/test/virtualenv/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/api/web_transaction.py", line 780, in __call__
result = application(environ, _start_response)
File "/home/skakri/projects/test/virtualenv/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/api/object_wrapper.py", line 220, in __call__
self._nr_instance, args, kwargs)
File "/home/skakri/projects/test/virtualenv/lib/python2.7/site-packages/newrelic-1.10.2.38/newrelic/api/function_trace.py", line 93, in literal_wrapper
return wrapped(*args, **kwargs)
File "/home/skakri/projects/test/virtualenv/lib/python2.7/site-packages/flask/app.py", line 1689, in wsgi_app
@skakri
skakri / gist:6426697
Last active December 22, 2015 05:49
xkcd time twitter profile image changer (in action - https://twitter.com/skakri)
import Image
import ImageChops
from twython import Twython
with open('current.txt', 'r+') as f:
index = int(f.read().strip())
new_index = index + 1
f.seek(0)
f.truncate(0)
f.write(str(new_index))
@skakri
skakri / gist:9090925
Last active August 29, 2015 13:56 — forked from jorilallo/gist:1701845
haystack + tastypie symbiosis
from django.conf.urls.defaults import *
from tastypie.paginator import Paginator
from tastypie.exceptions import BadRequest
from tastypie.resources import ModelResource
from tastypie.utils import trailing_slash
from haystack.query import SearchQuerySet, EmptySearchQuerySet
from clips.models import Clip
/**
* Based off of the Lucene prolog parser in the wordnet contrib package within the
* main Lucene project. It has been modified to remove the Lucene bits and generate
* a synonyms.txt file suitable for consumption by Solr. The idea was mentioned in
* a sidebar of the book Solr 1.4 Enterprise Search Server by Eric Pugh.
*
* @see <a href="http://lucene.apache.org/java/2_3_2/lucene-sandbox/index.html#WordNet/Synonyms">Lucene Sandbox WordNet page</a>
* @see <a href="http://svn.apache.org/repos/asf/lucene/dev/trunk/lucene/contrib/wordnet/">SVN Repository of the WordNet contrib</a>
* @see <a href="https://www.packtpub.com/solr-1-4-enterprise-search-server/book">Solr 1.4 Enterprise Search Server Book</a>
*/
@skakri
skakri / snips.py
Created April 3, 2014 06:44
Python snippets
#
# Django
#
# better solution than model_to_dict, if you need model instance dict, which holds m2m field values
# source: https://djangosnippets.org/snippets/2278/ (gabipurcaru)
from types import NoneType
from django.db.models.manager import Manager
from django.db.models import Model
@skakri
skakri / LV-CVE-2014-0160.txt
Last active August 29, 2015 13:59
CVE-2014-0160
19.lv
2m.lv
3000.lv
32maijs.lv
4dance.lv
4metri.lv
57paralele.lv
5ezeri.lv
5g.lv
a4d.lv