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:
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 |
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] |
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) |
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:
# 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 |
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]} |
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: |
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) |