Skip to content

Instantly share code, notes, and snippets.

@kipanshi
kipanshi / fibonacci_fast_double.js
Created October 19, 2017 14:12
Fibbonaci Fast dobule Algo
var yourself = {
fibonacci: function(n) {
return this._fib(n)[0]
},
_fib : function(n) {
if (n === 0) {
return [0, 1]
} else {
let half = this._fib(Math.floor(n / 2));
@kipanshi
kipanshi / notes_#wearedevs2017.yml
Created May 19, 2017 17:46
#WeAreDevelopers 2017 notes
Martin Wezowski:
"We need to be visioneers, empathic and human".
| |
| | * <- linear growth (what is in heads)
| / *
| * /
| * /
| * /
| * ____/ <- exponential growth (real life)
| * ______/
@kipanshi
kipanshi / make_unique_quiz.py
Created December 6, 2013 04:29
``Make unique`` quiz research
import unittest
import cProfile
import pstats
import StringIO
import random
import string
def make_unique_orig(list=[]):
"""
@kipanshi
kipanshi / gist:5335881
Created April 8, 2013 10:44
Testing oDesk API using ``python-odesk`` package
"""
(1) Create pair of oAuth 1.0 keys with "Desktop" types. Allow permissions for time and financial reports.
(2) Download ``odesk_meter.py`` from https://github.com/kipanshi/odesk_meter
(3) In the shell run the follwing:
"""
from odesk_meter import get_client
@kipanshi
kipanshi / gist:4046702
Created November 9, 2012 16:33
Exception handling
extern mod std;
extern mod docopt;
use send_map::linear::LinearMap;
use io::{ReaderUtil, WriterUtil};
/// Reads whole stream and outputs it as string
fn read_whole_stream_to_str(input_stream: io::Reader) -> ~str {
let mut buf = ~[];
@kipanshi
kipanshi / gist:4007717
Created November 3, 2012 15:53
Django float format and intcomma optimization
import cProfile
from django.template.defaultfilters import floatformat as floatformat_django
from django.contrib.humanize.templatetags.humanize import intcomma as intcomma_django
num = 100000
float_num = 1 / 3.0
def floatformat(value, places=2):
@kipanshi
kipanshi / gist:3859962
Created October 9, 2012 16:43
Django refresh and update model instance helpers
def refresh(instance):
"""Select and return instance from database.
Usage: ``instance = refresh(instance)``
"""
return instance.__class__.objects.get(pk=instance.pk)
def update(instance, **data):
@kipanshi
kipanshi / gist:2946670
Created June 18, 2012 03:08
Stub object
class _Stub(object):
"""Class for creating stub object.
For internal use.
"""
def __getattribute__(self, *args, **kwargs):
return self
def next(self):
raise StopIteration
@kipanshi
kipanshi / gist:2759479
Created May 20, 2012 20:47
Overriding settings in Django tests
class SettingsContextManager(object):
"""Allow to change ``settings.*`` in ``with`` context."""
def __init__(self, *settings_tuples):
self.settings = dict(settings_tuples)
self.orig_settings = dict([(key, getattr(settings, key))
for key in self.settings])
def __enter__(self, *args, **kwargs):
[setattr(settings, key, self.settings[key])
for key in self.settings]
@kipanshi
kipanshi / load_dump.sh
Created May 7, 2012 19:07
Django autoloading Postgres sql dump
#!/bin/sh
# This script needs to be run from inside the project folder
# since it needs access to settings.py
#
# DISCLAMER: Use _only_ on local dev installation!
DB_NAME=`python -c "import settings; print settings.DATABASES['default']['NAME']"`
DB_USER=`python -c "import settings; print settings.DATABASES['default']['USER']"`
DB_PASS=`python -c "import settings; print settings.DATABASES['default']['PASSWORD\
']"`