Skip to content

Instantly share code, notes, and snippets.

View ydm's full-sized avatar

Йордан Миладинов ydm

  • Sofia, Bulgaria
View GitHub Profile
char *c[]={
"ENTER",
"NEW",
"POINT",
"FIRST"
};
char **cp[]={c+3,c+2,c+1,c};
char ***cpp=cp;
main()
{
@ydm
ydm / align-numbers.el
Created March 11, 2014 19:24
Align numeric sequences in Python programs
(defun align-numbers (start end)
(interactive "r")
(let* ((reg (buffer-substring-no-properties start end))
(parts (mapcar #'y:string-strip (split-string reg ",")))
(widest (apply #'max (mapcar #'length parts)))
(full (mapcar (lambda (s)
(concat (make-string (- widest (length s)) ? ) s))
parts))
(line (mapconcat #'identity full ", ")))
(delete-region start end)
@ydm
ydm / montyhall.py
Created March 13, 2014 21:27
Monty Hall problem
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import multiprocessing
def gen_case():
return ['goat' if e else 'car' for e in random.sample(range(3), 3)]
;; http://forums.bgdev.org/index.php?showtopic=44083
(defvar ace (/ 1 13))
(defvar heart0 (/ 13 51))
(defvar heart1 (/ 12 51))
(defvar heart (/ (+ heart1 (* 3 heart0)) 4))
(defvar probability (* ace heart))
;; Our deck of cards:
;; 0-12 -- spades (2 3 4 5 6 7 8 9 10 jack queen king ace)
# -*- coding: utf-8 -*-
import importlib
import os
class ImproperlyConfigured(Exception):
pass
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from __future__ import print_function
from itertools import count
from math import sqrt
seqsum = lambda step, end: (step + end - (end % step)) * (end // step) // 2
@ydm
ydm / looper.py
Last active August 29, 2015 14:05
PyQt4 + UI Looper
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import Queue
import functools
import itertools
import sys
import threading
import time
@ydm
ydm / south2django17.bash
Last active August 29, 2015 14:07
Automates the process of converting south applications to Django 1.7. Use at your own risk
#!/bin/bash
# Usage:
# south2django17 PROJECT_ROOT_WHERE_ALL_THE_APPS_ARE
# This script will:
# 1. Backup all South migration files to /tmp
# 2. Delete these files
# 3. Run manage.py makemigrations
# 4. Run manage.py migrate
# http://is.gd/fbtuPF
@ydm
ydm / proxy.lua
Last active August 29, 2015 14:12
Proxy object that wraps another object and delegates everything
local Proxy = {}
function Proxy:new(wrapped)
local instance = { __wrapped = wrapped }
setmetatable(instance, self)
return instance
end
function Proxy.__index(instance, attrname)
local attr = instance.__wrapped[attrname]
@ydm
ydm / trycatch.cpp
Created March 16, 2015 16:34
Try / catch always creates copy of thrown object
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <string>
class Humanizator
{
public: