Skip to content

Instantly share code, notes, and snippets.

View creotiv's full-sized avatar

Andrey Nikishaev creotiv

View GitHub Profile
@creotiv
creotiv / get_coordinates_by_cell_phone.py
Created September 13, 2012 11:51
Getting coordinates without gps by cell phone
country = 'fr'
device = "Nokia N95 8Gb"
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
mmap_url = 'http://www.google.com/glm/mmap'
geo_url = 'http://maps.google.com/maps/geo'
from struct import pack, unpack
from httplib import HTTP
import urllib2
@creotiv
creotiv / django_browser_detection_middleware.py
Created September 13, 2012 12:01
Django browser detection middleware
import re
"""
Detect browser and it's version.
Now it works only for few moct common browsers. Full list of browsers and
theire user-agent you can find here: http://www.useragentstring.com/pages/useragentstring.php
Version: 0.1
Author: Andrey Nikishaev
Site: http://creotiv.in.ua/
@creotiv
creotiv / getXPath
Created December 14, 2012 19:20
Geting XPath of selected DOM element and highlighting it
function getPathTo(element) {
if (element.id!=='')
return 'id("'+element.id+'")';
if (element===document.body)
return element.tagName;
var ix= 0;
var siblings= element.parentNode.childNodes;
for (var i= 0; i<siblings.length; i++) {
var sibling= siblings[i];
@creotiv
creotiv / gist:4475510
Last active December 10, 2015 18:38
Pinterest friends adder and liker
var urls = $('.convo .ImgLink');
urls = $.makeArray(urls);
setTimeout(follow,300);
function follow() {
var a = urls.pop();
if(!a) return;
var h = a.href;
if(h!='http://pinterest.com/30artworks/') {
$.ajax({url:h+'follow/',type:'POST'});
@creotiv
creotiv / backup.sh
Created September 23, 2013 11:01 — forked from karussell/backup.sh
# TO_FOLDER=/something
# FROM=/your-es-installation
DATE=`date +%Y-%m-%d_%H-%M`
TO=$TO_FOLDER/$DATE/
echo "rsync from $FROM to $TO"
# the first times rsync can take a bit long - do not disable flusing
rsync -a $FROM $TO
# now disable flushing and do one manual flushing
@creotiv
creotiv / checktype
Created January 15, 2014 11:51
Decorator to check method param types. This solution give possibility to check method param type, raise needed exception type, and also have good readability in the decorator definition.
def accepts(exception,**types):
def check_accepts(f):
assert len(types) == f.func_code.co_argcount, \
'accept number of arguments not equal with function number of arguments in "%s"' % f.func_name
def new_f(*args, **kwds):
for i,v in enumerate(args):
if types.has_key(f.func_code.co_varnames[i]) and \
not isinstance(v, types[f.func_code.co_varnames[i]]):
raise exception("arg '%s'=%r does not match %s" % \
(f.func_code.co_varnames[i],v,types[f.func_code.co_varnames[i]]))
@creotiv
creotiv / gfs.py
Last active August 25, 2021 17:34
GFS in python. Simple example
"""
A brief summary of GFS is as follows. GFS consists of three components: a client,
a master, and one or more chunkservers. The client is the only user-visible,
that is programmer-accessible, part of the system. It functions similarly to a
standard POSIX file library. The master is a single server that holds all metadata
for the filesystem. By metadata we mean the information about each file, its
constituent components called chunks, and the location of these chunks on various
chunkservers. The chunkservers are where the actual data is stored, and the
vast majority of network traffic takes place between the client and the chunkservers,
to avoid the master as a bottleneck. We will give more detailed descriptions
@creotiv
creotiv / gist:10103885
Created April 8, 2014 09:21 — forked from ivanvanderbyl/gist:4222308
Postgres update from 9.1 to 9.2
sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
sudo apt-get install postgresql-9.2 postgresql-server-dev-9.2 postgresql-contrib-9.2
sudo su -l postgres
psql -d template1 -p 5433
CREATE EXTENSION IF NOT EXISTS hstore;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
service postgresql stop
/usr/lib/postgresql/9.2/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.2/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.2/main/ -O "-c config_file=/etc/postgresql/9.2/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"
<?php
class ImageDiff {
// not bigger 20
private $matrix = 15;
public function getImageInfo($image_path){
list($width, $height, $type, $attr) = getimagesize($image_path);
$image_type = '';
@creotiv
creotiv / GoogleFormLimit
Last active June 21, 2020 13:01
Setting limits for Google Form
/* Time zone used from your Google Callendar */
FORM_OPEN_DATE = "2014-12-20 08:00";
FORM_CLOSE_DATE = "2014-12-25 23:30";
RESPONSE_COUNT = "100";
/* Init the from and set triggers */
function Initialize() {
deleteTriggers_();