Skip to content

Instantly share code, notes, and snippets.

@andrusha
andrusha / python.vim
Created May 2, 2011 23:17
Pretty math symbols for python
" place it in ~/.vim/after/syntax/python.vim
" we need the conceal feature (vim ≥ 7.3)
if !has('conceal')
finish
endif
" remove the keywords. we'll re-add them below
syntax clear pythonOperator
syntax keyword pythonOperator is
@andrusha
andrusha / windows_xp.sh
Created May 31, 2011 16:06
Windows XP QEMU virtual machine startup script with KVM, VDE networking & Samba
#!/bin/sh
TAP_INTERFACE="tap0"
IMAGE_DIR="/media/files/virtual"
ARGS="-enable-kvm -drive file=$IMAGE_DIR/winxp.img,index=0,cache=writeback,media=disk -boot c -net nic,vlan=0,macaddr=52:54:00:00:EE:02,model=rtl8139 -net vde,vlan=0 -m 1024 -localtime -usbdevice tablet -vga std -smb qemu -cpu Nehalem"
if [ "$(lsmod | grep kvm | wc -l)" -eq 0 ]
then
echo "Loading KVM modules..."
sudo modprobe kvm
sudo modprobe kvm-intel
@andrusha
andrusha / inhex.py
Created June 30, 2011 03:49
inheritance example
In [1]: class Ellipse(object):
...: def setSize(self, x, y):
...: pass
...:
...:
In [2]: class Circle(Ellipse):
...: def setSize(self, x):
...: pass
...:
@andrusha
andrusha / inh_ex.php
Created June 30, 2011 04:40
Inheritance example for habrahabr
<?php
class A {
public function setSize($x, $y) {
print('A');
}
}
class B extends A {
public function setSize($x) {
class User < ActiveRecord:Base
ROLE_TYPES = %W[Company Developer]
validates_presence_of :email, :allow_blank => false, :allow_nil => false
validates_uniqueness_of :email
validates_email_format_of :email
attr_accessible :email
end
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
Or like:
{% if condition %} print {%=object.something %}{% endif %}
This, of course, completely screws up Django templates,
@andrusha
andrusha / gist:2713435
Created May 16, 2012 19:53
Lambda-calculus beta-reduction algorithm
import Data.Traversable
data Term a =
Var a
| Lambda a (Term a)
| Apply (Term a) (Term a)
instance Show a => Show (Term a) where
show (Var v) = show v
show (Lambda n t) = "/" ++ (show n) ++ "." ++ (show t)
@andrusha
andrusha / gist:3969506
Created October 28, 2012 19:10
Word document readers benchmark results
❯ /usr/bin/time -l antiword ~/Projects/universiteam/spec/support/files/lorem.complex.doc
0.02 real 0.00 user 0.00 sys
688128 maximum resident set size
0 average shared memory size
0 average unshared data size
0 average unshared stack size
157 page reclaims
32 page faults
0 swaps
7 block input operations
@andrusha
andrusha / test_file.rb
Created December 16, 2012 10:54
A support library to abstract usage of files in tests
# As a separate module, because we might want to
# mock some files in the future or use generator
# for the same reason it returns opened instance of file
#
# Each method check if corresponding file exists in
# spec/support/files/file.name.kitten.ext
# if method has `_path` in the end Pathname instance would be returned
# otherwise it will be File instance
module TestFiles
def self.respond_to?(method)
@andrusha
andrusha / vk_audio_remove
Last active August 22, 2023 13:16
Remove all audio files from vkontakte profile (javascript console snippet). Удалить все аудиозаписи из профиля вконтакте.
var nodes = document.querySelectorAll(".audio_remove"), i = 0, inter = setInterval( function() { if (i == nodes.length) { clearInterval(inter);}; var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("click", true, true, nodes[i], 0, 0, 0, 0, 0, false, false, false, false, 0, null); nodes[i].dispatchEvent(evt); i++; }, 350);