Skip to content

Instantly share code, notes, and snippets.

View vorushin's full-sized avatar

Roman Vorushin vorushin

View GitHub Profile
% GNU Octave file (may also work with MATLAB(R) )
Fs=44100;minF=10;maxF=Fs/2;
sweepF=logspace(log10(minF),log10(maxF),200);
preemph_coeff = 1
b0 = 1 * preemph_coeff
b1 = -1.700724000000000e+00 * preemph_coeff + (1 - preemph_coeff)
b2 = 7.029381524255900e-01 * preemph_coeff
a0 = 2.380612232632074e-01 * preemph_coeff + (1 - preemph_coeff)
a1 = -1.718545401961680e-01 * preemph_coeff
a2 = -4.429177968575995e-02 * preemph_coeff
@vorushin
vorushin / prng.py
Created July 4, 2012 10:59
My python implementation of pseudo-rng algorithm from http://amca01.wordpress.com/2012/07/02/a-conceptually-simple-prng/
def prng(n):
p = (1 << 31) - 1
arr = [0 for i in range(n + 1)]
arr[0] = 7
arr[1] = 7
for i in range(2, n + 1):
arr[i] = pow_mod(7, arr[i - 1], p) + pow_mod(7, arr[i - 2], p)
return arr
@vorushin
vorushin / dancing.py
Created April 15, 2012 05:23
Dancing Googlers problem solution (Google Code Jam 2012 qualification round)
def max_googlers(total_points, num_of_surprizing, max_point):
res = 0
for total in total_points:
if max(unsurprizing(total)) >= max_point:
res += 1
elif num_of_surprizing > 0 and max(surprizing(total)) >= max_point:
res += 1
num_of_surprizing -= 1
return res
@vorushin
vorushin / gunicorn.conf
Created November 7, 2011 13:23
Example of gunicorn.conf upstart config file
description "Gunicorn for answers"
start on runlevel [2345]
stop on runlevel [!2345]
kill timeout 5
respawn
env VENV="/home/django/answers/env"
env LOG="/home/django/log/answers.log"
env PID="/home/django/run/answers.pid"
@vorushin
vorushin / jquery-csrf.js
Created June 24, 2011 08:51
Small jQuery plugin for adding csrf-token to Ajax/Ajaj requests
$.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]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
#encoding: utf-8
import uno
def open_document(url):
local = uno.getComponentContext()
resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
document = desktop.loadComponentFromURL(url, "_blank", 0, ())
return document
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import com.adobe.serialization.json.JSON;
from django.core.urlresolvers import reverse
from django.test import TestCase
class Test(TestCase):
def test_api(self):
response = self.client.post(reverse('vk.views.start_wall_post'), {})
self.assertContains(response, 'errors')
response = self.client.post(reverse('vk.views.start_wall_post'),
{'image': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAEsCAYAAAAfPc2WAAAO60lEQVR4Ae3WMQ0A',
class AutocompleteWidget(forms.Select):
def __init__(self, attrs=None, choices=(), js_options={}):
super(AutocompleteWidget, self).__init__(attrs, choices)
self.js_options = js_options
def render(self, name, value, attrs=None, choices=()):
output = u'<input name="%(name)s" id="id_%(name)s" type="hidden">\n' % {'name': name}
value_text = ''
for ch in self.choices:
if str(ch[0]) == str(value):