Skip to content

Instantly share code, notes, and snippets.

@89465127
89465127 / HelloJson.scala
Created October 5, 2013 15:52
Simple json deserialization in Scala
package com.example.json
import net.liftweb.json._
object HelloJson extends App {
case class Address(city: String, state: String)
case class Person(name: String, addresses: List[Address])
implicit val formats = DefaultFormats
@89465127
89465127 / longest_palandrome.py
Created September 19, 2013 16:50
Find the longest palandrom in a given string, using functional programming and recursion in python.
def sliding(iterable, n):
return [iterable[i:i+n] for i in range(len(iterable) - n + 1)]
def xsliding(iterable, n):
for i in range(len(iterable) - n + 1):
yield iterable[i:i+n]
def reversed_iter(iterable):
return iterable[::-1]
@89465127
89465127 / Palandrome.scala
Created September 18, 2013 23:02
Longest Palandrome in Scala
object Palandrome {
def main(args: Array[String]) {
val s = "meow woow ooooooo doggies aaadddfffdddaaa wow"
println("finding the longest palandrome of: " + s)
println(longestPal(s))
}
def longestPal(s: String) = {
longestPalN(s, s.length)
@89465127
89465127 / README.md
Last active December 19, 2015 03:08 — forked from rduplain/README.md

Goal: Connect to MSSQL using FreeTDS / ODBC in Python.

Host: Linux Mint 15 x86_64

Install:

sudo apt-get install python-dev python-pip freetds-dev freetds-bin unixodbc-dev tdsodbc
pip install pyodbc

In /etc/odbcinst.ini:

@89465127
89465127 / aws_instances.py
Created June 25, 2013 20:09
Give a summary of currently running/pending AWS instances, and how many are being used out of the limit.
# Setup:
# 1) sudo pip install awscli
# 2) the following environment variables must be set
# - $ export AWS_ACCESS_KEY_ID=<access_key>
# - $ export AWS_SECRET_ACCESS_KEY=<secret_key>
import collections
import datetime
import json
import subprocess
@89465127
89465127 / filter_dict.py
Created June 13, 2013 20:05
python filter a dictionary by keys or values
d = {1:11, 2:22, 3:33}
# filter by key
d2 = {k : v for k,v in filter(lambda t: t[0] in [1, 3], d.iteritems())}
# filter by value
d3 = {k : v for k,v in d.iteritems() if k in [2,3]}
@89465127
89465127 / First singleton character in string.ipynb
Last active December 18, 2015 10:28
Interview Question: find the first character that occurs only once in a string.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@89465127
89465127 / open_hadoop.py
Created June 6, 2013 18:10
Read in flat hadoop files into python. Uses a generator, so it is memory efficient.
import glob
import os
def filelist(path, _filter="part-*"):
basepath = os.path.abspath(os.path.expanduser(path))
return [filename for filename in glob.glob(basepath + '/' + _filter)]
def hfile(path, _filter="part-*"):
for filename in filelist(path, _filter):
with open(filename) as f:
@89465127
89465127 / classpath.bash
Created May 23, 2013 23:07
How to compile and run Java and Scala programs by setting the classpath properly.
javac -cp ".:*" Program.java && java -cp ".:*" Program
# : is the delimiter
# This method is useful to include all items in the current directory
import paramiko
class SSH():
def __init__(self, host, key_file, user="root"):
''' Open up a SSH connection using paramiko '''
key = paramiko.RSAKey.from_private_key_file(key_file)
self.client = paramiko.SSHClient()
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.client.connect(hostname=host, username=user, pkey=key)