Skip to content

Instantly share code, notes, and snippets.

View AyumuKasuga's full-sized avatar
🤔
🤔

Andrei Kostakov AyumuKasuga

🤔
🤔
View GitHub Profile
@AyumuKasuga
AyumuKasuga / gist:6619898
Created September 19, 2013 06:55
django csrf ajax
$.ajaxSetup({
beforeSend: function(xhr, settings) {
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
@AyumuKasuga
AyumuKasuga / templater.js
Created August 16, 2012 19:50
simple js templater
function render(template, kwargs){
this.template = template
this.kwargs = kwargs
this.render_str = function(temp, kwargs){
re = /{{(.*?)}}/g
if(kwargs == undefined){kwargs=this.kwargs}
return temp.replace(re, function(a,b){
clean_key = b.trim();
if(kwargs[clean_key]){
@AyumuKasuga
AyumuKasuga / saveimage.py
Created June 21, 2012 14:11
save images from 2ch.so
#!/usr/bin/env python2
#coding: utf-8
import gevent.monkey
gevent.monkey.patch_socket()
import sys
import os
from urlparse import urlparse
import urllib
@AyumuKasuga
AyumuKasuga / gist:2838980
Created May 30, 2012 21:05
expiremantal generator
all = '0123456789abcdefghijklmnopqrstuvwxyz'
l=len(all)
t=8248398492887
r=list()
while True:
p,t=t%l,t//l
r.append(p)
if t<l:
r.append(t) if t is not 0 else None
break
@AyumuKasuga
AyumuKasuga / miralinks.py
Created May 10, 2012 12:20
miralinks.ru finance parser
#coding: utf-8
import pyinotify
import os
class action(pyinotify.ProcessEvent):
def process_IN_MODIFY(self, event):
l = open(os.path.join(event.path, event.name)).readlines()[-1]
#print os.path.join(event.path, event.name), l
@AyumuKasuga
AyumuKasuga / backlight.py
Created April 12, 2012 13:33
backlight up/down on samsung R428
import sys
import os
class backlight():
def __init__(self, cmd):
self.path = "echo '%s' > /sys/class/backlight/samsung/brightness"
self.limit_down, self.limit_up = 1, 7
self.current = int(os.popen("cat /sys/class/backlight/samsung/brightness").read().strip())
self.cmd = cmd.strip()
self.setbacklight()