Skip to content

Instantly share code, notes, and snippets.

@dudarev
dudarev / record.py
Created June 3, 2014 09:34
Take screenshots regularly
#! /usr/bin/env python
"""
Take screenshots every SLEEP_TIME seconds.
"""
import time
import subprocess
SLEEP_TIME = 10
COMMAND = "import -window root -format png data/{timestamp}.png"
@dudarev
dudarev / gist:3315ceb427fe9ed3425b
Created September 17, 2014 08:54
m101js.hw5.3.js
db.grades.aggregate([
{$unwind: '$scores'},
{$match:
{"scores.type": {$in: ["exam", "homework"]}}},
{$group:
{
_id: {
'student_id': '$student_id',
'class_id': '$class_id'
},
@dudarev
dudarev / gist:bf7067f713a1e0fa901b
Created September 17, 2014 08:56
m101js.hw5.4.js
db.zips.aggregate([
{$project:
{
first_char: {$substr : ["$city",0,1]},
pop: 1
}
},
{$match:
{
first_char: {$lt: 'A'}
@dudarev
dudarev / gist:10f94ac617aab949ecc5
Created October 20, 2014 19:56
Some ways to select k random elements from a list
"""
Some solutions for @bobuk's problem discussed in
http://www.radio-t.com/p/2014/10/18/podcast-414/
"""
import random
L_TEST = [1234, 1, 23, 252, 13523, 829, 2378, 234555, 912394]
K_TEST = 3
@dudarev
dudarev / gist:1431275
Created December 4, 2011 21:07
Number of Saturdays in odd and even weeks
"""Take third Saturdays of each month.
Calculate number of them in odd and even weeks"""
from datetime import datetime
y = 2012
odd_counter = 0
even_counter = 0
@dudarev
dudarev / .bashrc
Created January 12, 2012 13:44 — forked from troolee/.bashrc
prompt
### PROMPT ####################
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
import xml.dom.minidom
from exceptions import QueryRequired
import experiment
import analysis
class Result(object):
experiment_xml = None
analysis_xml = None
pass
from lxml import objectify
from exceptions import QueryRequired
def request(query=None, file_name=None):
"""
Makes a request to CGHub web service or gets data from a file.
Returns parsed Response object.
"""
# assume the following directory structure where contents of doc/
# and source/ are already checked into repo., with the exception
# of the _build directory (i,e. you can check in _themes or _sources
# or whatever else).
#
# proj/
# source/
# doc/
# remove doc/_build/html if present
@dudarev
dudarev / gist:4348689
Last active January 29, 2017 09:56 — forked from evildmp/gist:3094281
Django deployment with nging and uwsgi

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

  • virtualenv
  • Django
  • nginx
  • uwsgi