Skip to content

Instantly share code, notes, and snippets.

View kopos's full-sized avatar
🎯
Focusing

Poorna Shashank kopos

🎯
Focusing
View GitHub Profile
@kopos
kopos / distillery-demo.sh
Last active November 17, 2017 07:34
Commands to hot deploy with distillery
git clone https://github.com/wmnnd/distillery-demo.git
cd distillery-demo
# Add distillery as dependency in mix.exs
mix deps.get
# To create the initial release
MIX_ENV=prod mix release.init
MIX_ENV=prod mix release
def dynamic_load(fqcn):
parts = [
x.strip()
for x in fqcn.split('.')
if x.strip()
]
module = __import__('.'.join(parts[:-1]),
globals(),
locals(),
[])
@kopos
kopos / 100.py
Last active August 21, 2019 12:15
List of all english words with sum equal to 100
# Sick of all people who keep sending posts where attitude seems to mean everything
import operator
word_sum = lambda s: reduce(operator.add, [ord(i) - ord('a') + 1 for i in s])
words = None
with open('/usr/share/dict/words') as d:
words = filter(lambda w: word_sum(w.strip()) == 100, d)
print words
@kopos
kopos / Number to Words
Created June 19, 2016 01:40
Simple data-driven program to convert number to words
def two_digit_words(n):
words = dict([
(1, 'one'),
(2, 'two'),
(3, 'three'),
(4, 'four'),
(5, 'five'),
(6, 'six'),
(7, 'seven'),
(8, 'eight'),
expr = "28+30+++39+32"
filter(bool, expr.split("+"))
filter(None, expr.split("+"))
bool(None) == bool('') == bool() == False
@kopos
kopos / borg.py
Created December 24, 2013 09:13
The Borg Design Anti-Pattern Hack
class Borg:
_shared_state = {}
def __init__(self):
self.__dict__ = self._shared_state
b = Borg()
b.name = 'Borg'
c = Borg()
@kopos
kopos / learning.scala
Created November 5, 2013 12:05
scala tests
// Use as sum(4, 5)
// Use as sum(sum(4, 5), sum(1, 2))
def sum(x: Int, y: Int): Int = {
x + y;
}
// Use as sum(4, 5)
// Use as sum(sum(4, 5), sum(1, 2))
def sum = (x: Int, y: Int) => { x + y; }
@kopos
kopos / funsvr.scala
Last active December 26, 2015 07:59
Trying to grok funsvr.pdf
/*
* Combinators in Finagle:
*
* - flatMap
* - rescue
* - collect
* - andThen
* -
*/
@kopos
kopos / command_streaming.php
Created September 4, 2013 15:03
Print the output from a system command unbuffered
<?php
/**
* @func: Executes the command passed to it as argument and prints the
* command console output line by line onto the html output stream hence
* giving the illusion of having the command executing in the html window itself.
*/
function html_exec_cmd($cmd) {
$proc = popen("($cmd)2>&1", "r");
echo '<pre>';
while(!feof($proc)) {
@kopos
kopos / shuffle.py
Last active December 20, 2015 23:18
Shuffle code for shuffling a set of cards http://www.codinghorror.com/blog/2007/12/shuffling.html
import random
import uuid
import hashlib
items = [8, 19, 1, 03, 52, 62, 23, 62, 236, 9, 0, 12]
sorted(items, key=lambda x: hashlib.md5(uuid.uuid1().hex).hexdigest())