This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pandas import * | |
import dateutil | |
import os, os.path | |
csvdir = os.getcwd() | |
filenames = [os.path.join(csvdir,csvfile) | |
for csvfile in os.listdir(csvdir) | |
if csvfile[-4:] == '.csv'] | |
dfs = [io.parsers.read_csv(filename, | |
converters={0:dateutil.parser.parse}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defprotocol Dateable | |
"Convertible to a Java Date" | |
(to-date [this] "Convert to Java Date")) | |
(defrecord TimeMs [timeInMs] | |
Dateable | |
(to-date [this] (new Date (long (:timeInMs this))))) | |
(defrecord TimeOffset [offsetString] | |
Dateable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Script to find folders with bad nesting patterns | |
(eg, in an arist-album organized music collection) | |
""" | |
import os,os.path,sys,shutil,pdb | |
colroot = sys.argv[1] | |
skiplist = ['desktop.ini','.DS_Store','Thumbs.db','FINDER.DAT'] | |
log_f = open('nest_log.txt','w') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val mutant = collection.mutable.ListBuffer[Int]() | |
mutant: scala.collection.mutable.ListBuffer[Int] = ListBuffer() | |
scala> (0 until 4).map{idx => { | |
mutant.append(idx); idx > 0}}.exists(identity) | |
res0: Boolean = true | |
scala> mutant | |
res1: scala.collection.mutable.ListBuffer[Int] = | |
ListBuffer(0, 1, 2, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val myRegex = """Foo=([0-9]+) Bar=([A-Z]+)""".r | |
myRegex: scala.util.matching.Regex = Foo=([0-9]+) Bar=([A-Z]+) | |
scala> val m = myRegex.findFirstMatchIn("Foo=123 Bar=ABC").get | |
m: scala.util.matching.Regex.Match = Foo=123 Bar=ABC | |
scala> val foo = m.group(1) | |
foo: String = 123 | |
scala> val bar = m.group(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val myRegex = """Foo=([0-9]+) Bar=([A-Z]+)""".r | |
myRegex: scala.util.matching.Regex = Foo=([0-9]+) Bar=([A-Z]+) | |
scala> "Foo=123 Bar=ABC" match { | |
| case myRegex(foo, bar) => | |
| println("foobar looks like %s-%s".format(foo,bar)) | |
| case _ => println("not a match") | |
| } | |
foobar looks like 123-ABC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val mutant = collection.mutable.ListBuffer[Int]() | |
mutant: scala.collection.mutable.ListBuffer[Int] = ListBuffer() | |
scala> (0 until 4).view.map{idx => { | |
mutant.append(idx); idx > 0}}.exists(identity) | |
res3: Boolean = true | |
scala> mutant | |
res4: scala.collection.mutable.ListBuffer[Int] = | |
ListBuffer(0, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// record progress every second | |
val loggingInterval = 1000 | |
var lastLogTime = System.currentTimeMillis() | |
// count how many elements we've processed | |
var lastCounter = 0 | |
var counter = 0 | |
elements.foreach { element => { | |
process(element) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assumes WMA files end in *.wma | |
for f in `ls | grep "\.wma" | rev | cut -d \. -f 2- | rev`; do ffmpeg -i "$f.wma" -acodec libmp3lame -ab 160k -ac 2 -ar 44100 "$f.mp3"; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Python script to help programmatically tidy up Google contacts | |
Example workflow: | |
1) export Google contacts and back this file up somewhere | |
(must use Outlook CSV format b/c Python csv chokes on Unicode) | |
2) run this script to generate a cleaned-up CSV contacts file | |
3) in Google contacts, delete all and re-import from this new CSV | |
4) use Google contacts merge/delete for finishing touches | |
""" |