Skip to content

Instantly share code, notes, and snippets.

@debetimi
debetimi / .vimrc
Created October 12, 2015 23:24
Clojure Dev Setup for Vim, everything you need.
set nocompatible
filetype off
"execute pathogen#infect()
"call pathogen#helptags()
" Packages
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
@debetimi
debetimi / mnemonic.py
Last active August 29, 2015 14:24
Returns mnemonics for a phone number
pad = {0: ['0'], 1: ['1'], 2: ['A', 'B', 'C'], 3: ['D', 'E', 'F'], 4: ['G', 'H', 'I'],\
5: ['J', 'K', 'L'], 6:['M', 'N', 'O'], 7:['P', 'Q','R', 'S'], 8: ['T', 'U', 'V'],\
9: ['W', 'X', 'Y', 'Z']}
def list_mnemonics(number):
a = set()
if number == '':
a.add('')
return a
chars = pad[int(number[0])]
@debetimi
debetimi / frequency.py
Last active August 29, 2015 14:24
Top ten most frequent letters in a string.
def character_frequency(words):
words = words.upper().split(' ')
counts = [0] * 26
for word in words:
for char in word:
counts[ord(char) - ord('A')] += 1
letters = [chr(x+ord('A')) for x in range(26)]
return sorted(zip(counts, letters))[-1: -11: -1]
@debetimi
debetimi / permutation.py
Last active August 29, 2015 14:24
Permutation
def memoize(func):
cache = {}
def memo(string):
if not string in cache:
cache[string] = func(string)
return cache[string]
return memo
@memoize
def permutations(string):
@debetimi
debetimi / Var.py
Last active August 29, 2015 14:02
Reactive Programming Baby Steps
from collections import namedtuple
enum = namedtuple('Operations', ['add', 'subtract', 'multiply', 'divide'])
operations = enum(add='+', subtract="-", multiply="*", divide="/")
class Relation:
def __init__(self, a, b, op):
self.a = a
self.b = b
@debetimi
debetimi / Access Okay
Created May 30, 2014 17:08
Liberator Friend
timi-$: curl -v --data "username=tom@gmail.com&password=password" localhost:3000/registration
* Adding handle: conn: 0x7fe4c9036400
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fe4c9036400) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 3000 (#0)
* Trying ::1...
* Connected to localhost (::1) port 3000 (#0)
> POST /registration HTTP/1.1
import copy
import functools
def memoize(obj):
cache = obj.cache = {}
@functools.wraps(obj)
def memoizer(*args, **kwargs):
key = str(args) + str(kwargs)
if key not in cache:
cache[key] = obj(*args, **kwargs)
@debetimi
debetimi / workflow.clj
Last active August 29, 2015 14:01
This is an example of getting Friend to work with an AJAX request, and redirect set to null. When the request is not JSON/EDN works as normal and redirects.
(ns foo.auth.core
(:require [cemerick.friend :as friend]
[cemerick.friend.util :refer [gets]]
[cemerick.friend.workflows :as workflow]
[cemerick.friend.credentials :as creds]
[tickets.routes.user :refer [login-friend]]
[ring.util.request :as req]
[noir.response]))
" File: clojure.vim (conceal enhancement)
" Author: Jeb Beich (jebbeich@gmail.com)
" Last Change: 2013-05-24
" Version: 1.0.0
" Require:
" set nocompatible
" somewhere on your .vimrc
" Vim 7.3 or Vim compiled with conceal patch.
if !has('conceal') || &enc != 'utf-8'
@debetimi
debetimi / challenge.py
Last active August 29, 2015 13:58
That problem
#If the integers from 1 to 999,999,999 are written as words, sorted alphabetically, and concatenated, what is the 51 billionth letter?
#where strings have no spaces
import time
singles = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
singles.sort()
teens = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "nineteen"]