Skip to content

Instantly share code, notes, and snippets.

@dnene
dnene / excel_column_headers.scala
Created January 4, 2012 17:57
Converting column numbers into excel column headers. Convert integers into strings as follows 0=> "A", 25=>"Z",26=>"AA",701=>"ZZ", 702=>"AAA"
import scala.collection.mutable.ListBuffer
object Coordinates {
def main(args: Array[String]): Unit = {
println(numToStr(0))
println(numToStr(25))
println(numToStr(26))
println(numToStr(51))
println(numToStr(52))
println(numToStr(700))
println(numToStr(701))
@dnene
dnene / GradleDemo.scala
Created January 17, 2012 03:39
Using gradle for build and release management with Scala and Java - Part 1. Accompanying code
package in.vayana.blog.gradle_demo
object GradleDemo {
def main(args: Array[String]) = {
println("hello world!")
}
}
@dnene
dnene / python_computer_scientists.py
Created January 17, 2012 14:40
python is for computer scientists ?
import csv
import StringIO
data = """Bob,Dobbs,[email protected],25.00
Rocket J.,Squirrel,[email protected],0.00
Bullwinkle,Moose,[email protected],0.25
Vim,Wibner,[email protected],25.00"""
data_stream = StringIO.StringIO(data)
@dnene
dnene / pom_modify.groovy
Created January 25, 2012 15:56
gradle snippet to modify pom contents
install.repositories.mavenInstaller.pom.whenConfigured { pom ->
excludedJars = project.bnd.exclusions.tokenize(",").collect{ dep ->
splitDep = dep.split(':')
[splitDep[0],splitDep[1]]
}
deps = project.configurations['compile'].dependencies.collect {dep ->[dep.group,dep.name]}
pom.dependencies.removeAll {dep -> !excludedJars.contains([dep.groupId,dep.artifactId])}
}
@dnene
dnene / bar.py
Created February 9, 2012 04:32
Redirecting print - a) by reassigning to print b) creating a different variable
from functools import partial
mode = "debug"
def get_logger(stream = None) :
if stream is None :
return __builtins__.print
else :
return partial(__builtins__.print,file=stream)
def main() :
@dnene
dnene / primes.scala
Created March 19, 2012 20:45
Find prime numbers between 1 and 100
package misc
import scala.math
object Prime {
def prime(num: Int) =
num > 1 &&
(2 to (math.sqrt(num) toInt)).forall ( num % _ != 0)
def main(args: Array[String]): Unit = {
1 to 100 filter prime foreach println
@dnene
dnene / polynomial.py
Created March 21, 2012 05:26
Polynomial library
# Copied from http://pastebin.com/Vg9Reb0Z to preserve from accidental deletion
# A library for manipulating polynomials in arbitrarily many
# indeterminates and of arbitrary degree. This library is 13 lines of
# code, excluding whitespace and comments. This isn't the smartest or
# most efficient way to do things, but I thought it was a cool way to
# demonstrate the power of itertools
#
# Monomials are pairs of a coefficient and a list of exponents;
# polynomials are lists of monomials.
@dnene
dnene / input.txt
Created April 15, 2012 21:47
Solution to Google Code Jam Problem - Problem A. Speaking in Tongues
3
ejp mysljylc kd kxveddknmc re jsicpdrysi
rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd
de kr kd eoya kw aej tysr re ujdr lkgc jv
@dnene
dnene / progress_bar.py
Created January 1, 2013 20:07
Progress Bars in Python 3.x
import time
import sys
def do_task():
time.sleep(0.1)
def example_1(n):
steps = n/10
for i in range(n):
do_task()
if i%steps == 0:
@dnene
dnene / myop.py
Created September 3, 2013 06:55
client side helper for operator based syntactic sugar to assist lambda creation
>>> import operator
>>> def myop(optype, second): return lambda first: optype(first,second)
...
>>> myop(operator.lt,60)(45)
True
>>> myop(operator.lt,60)(80)
False