Skip to content

Instantly share code, notes, and snippets.

View dreikanter's full-sized avatar

Alex Musayev dreikanter

View GitHub Profile
@dreikanter
dreikanter / include-conf.py
Created May 24, 2012 10:58
Dynamic #configuration file inclusion demo
# Dynamic configuration file inclusion example.
# This script is intended for demo purposes and home usage only.
# There are intentionally no any security checks.
import imp
import sys
if len(sys.argv) < 2:
print "Specify a configuration file to include"
exit(1)
@dreikanter
dreikanter / read_gist_feed.py
Created May 25, 2012 09:49
Parse Gist feed using feedparser and demonstrate Atom data structure #python #feeds
import feedparser
from time import mktime
from datetime import datetime
def format_datetime(struct_time):
return datetime.fromtimestamp(mktime(struct_time))
def read_gist_feed(github_user):
@dreikanter
dreikanter / py-bat-shebang-demo.bat
Created June 3, 2012 14:06
Shebang analog for Windows to run Python code directly included to batch files
@echo off &python -x %0 %* &goto :eof
print("Hello Python!")
@dreikanter
dreikanter / introrx.md
Created October 10, 2015 10:28 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@dreikanter
dreikanter / README.md
Last active November 22, 2015 12:33
Comment author name

The first image version is a normal thread. Second one has redundant user names removed.

@dreikanter
dreikanter / ngram.rb
Last active December 5, 2015 13:07
N-grams counter
require 'pp'
WORDS = %w(correct horse battery staple)
LENGTH = 100
SOURCE = (0..LENGTH).map { WORDS.sample }
puts "Source: #{SOURCE.join(', ')}"
###
@dreikanter
dreikanter / enum1.rb
Last active December 13, 2015 18:15
More meaningful ActiveRecord::Enum
class Enum
def self.value(key, value = nil)
@enum ||= {}
@enum[key] = value || @enum.size
define_singleton_method(key) { @enum[key] }
end
def self.enum
@enum
end
@dreikanter
dreikanter / constants.py
Created May 27, 2013 13:48
How to kill a process using Python
PID_FILE = 'pid.txt'
@dreikanter
dreikanter / wishlist.md
Last active December 19, 2015 04:48
My Wishlist 2013
  • «Сила воли», Келли Макгонигалhttp://b23.ru/hm6s
  • «Искусство визуализации в бизнесе», Нейтан Яу → http://b23.ru/hm6e
  • «Позитивная иррациональность», Дэн Ариели → http://b23.ru/hmzu
  • «Естественный бег», Дэнни Эбшир и Брайан Метцлер → http://b23.ru/hmzt
  • «Рожденный бежать», Кристофер Макдугл → http://b23.ru/hm4n
  • «Стив Джобс», Уолтер Айзексонhttp://b23.ru/hm4l
  • «Бэтман Аполло», Виктор Пелевинhttp://b23.ru/hm46
  • Мобильное зарядное устройство (USB, на 5000+ mAh). Что-то типа такого: http://b23.ru/hm6j
  • Bluetooth аудио адаптерhttp://b23.ru/hm89
  • Европейский переходник для блока питания от макбука: http://b23.ru/hm8m
@dreikanter
dreikanter / strchr.py
Created July 8, 2013 16:58
Little trick to support both Python 2 an 3 dealing with string and char types
PY2 = sys.version_info[0] == 2
if not PY2:
strtype = str
chrtype = chr
else:
strtype = unicode
chrtype = unichr