Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
"I'm in"

Jessica Kerr jessitron

🚀
"I'm in"
View GitHub Profile
@jessitron
jessitron / speakerStats.scala
Created Oct 18, 2012
Play with the CodeMash API to analyze gender distribution of speakers
View speakerStats.scala
import scala.xml._
// curl http://rest.codemash.org/api/speakers > speakers.xml
val speakers = xml.XML.loadFile("codemashSpeakers.xml") \ "Speaker"
// curl http://rest.codemash.org/api/sessions > sessions.xml
val sessions = xml.XML.loadFile("sessions.xml") \ "Session"
val masculineWords = List("he","his")
val feminineWords = List("she","her","hers","lady")
def bioContainsAnyWord( strings : Seq[String], speakerNode : Node) =
@jessitron
jessitron / transformers
Created Jan 14, 2013
These methods perform transformations on their input. They'll be tied together in different ways separately. Look for the blog post at blog.jessitron.com.
View transformers
// from https://github.com/jessitron/BlogCode/blob/master/optionAsFlow.scala
object transformers {
def openFile(n: String) : Option[java.io.File] = {
val f = new java.io.File(n) // catch IOException
if (f.exists)
Some(f)
else
None
@jessitron
jessitron / gist:4526987
Created Jan 14, 2013
The transformers now return a Result, with more detail on failure than an Option holds. See blog.jessitron.com for the purpose of this post.
View gist:4526987
// from https://github.com/jessitron/BlogCode/blob/master/optionToCustom.scala
object transformers {
def openFile(n: String) : Result[java.io.File] = {
val f = new java.io.File(n) // catch IOException
if (f.exists)
Success(f)
else
Failure("File does not exist: " + n)
@jessitron
jessitron / gist:5129618
Created Mar 10, 2013
Ruby: Hash.each treats blocks and lambdas differently when the arity is 2
View gist:5129618
#
# Ruby 2.0 hashes: they treat lambdas inconsistently from blocks.
# Pass in a block straight-up, and each (or each_pair) looks at the arity of the block.
# A block that accepts one argument gets an array of two elements, key and value.
# A block that accepts two arguments gets the key and value separately. How nice.
#
# But, if you pass in a lambda as a block, you always get just one argument.
# No key-value separation for you!
#
View gem_cleaner.rb
require 'bundler'
# Required for Bundler::LockfileParser. This can be empty though.
`touch Gemfile` unless File.exists?("Gemfile")
# Add the paths to the Gemfile.lock files, the gems in which
# need to be protected
@jessitron
jessitron / ExplicitErrorReturning
Created Jun 15, 2013
This is in response to a giant twitter thread. Thanks to @CraigBuchek, @brianbuttonxp, @adkron, @heathborders, and @marioaquino for the discussion. Post is at blog.jessitron.com, titled "What's dirtier than comments? Exceptions!"
View ExplicitErrorReturning
case class Error(message:String)
case class AuthLevel(value: Int)
object AuthLevel {
val GUEST = AuthLevel(0)
}
class SettingGetter {
def get_setting(settingName: String): Either[Error, String] = Right("Fred")
View jquery-plugins.md

Writing jQuery Plugins for Fun and (non)Profit

We all love jQuery - it's easy, efficient, and there's tons of information online. But with that mass of information comes confusion: When you want to abstract some of your code into a plugin, how do you structure it? How do you take in options, and how can you be sure you haven't broken the way jQuery works? And when you're done, where do you put it and how do distribute it to the masses?

This talk will run through some of the basics and guide you in the right direction. In particular, we'll cover:

  • structuring your plugin code
  • making your code testable - and testing it!
  • tracking your code on github
  • getting your plugin on the jQuery site
@jessitron
jessitron / gist:8376139
Created Jan 11, 2014
scala: print all URLs on classpath
View gist:8376139
def urlses(cl: ClassLoader): Array[java.net.URL] = cl match {
case null => Array()
case u: java.net.URLClassLoader => u.getURLs() ++ urlses(cl.getParent)
case _ => urlses(cl.getParent)
}
val urls = urlses(getClass.getClassLoader)
println(urls.filterNot(_.toString.contains("ivy")).mkString("\n")
@jessitron
jessitron / gist:8777503
Created Feb 3, 2014
The magic of blocking { ... } in Scala's global ExecutionContext: it leads to the creation of more threads, so the CPUs don't get bored
View gist:8777503
val des = scala.concurrent.ExecutionContext.global
import scala.concurrent._
import duration._
def ct = Thread.currentThread.getName
val n = Runtime.getRuntime.availableProcessors
def hogThread(sec:Int) = future {
@jessitron
jessitron / gist:9191499
Created Feb 24, 2014
StackOverflow in scalaz-stream. My trampoline is not bouncy enough
View gist:9191499
import scalaz.stream._
import Process._
import scalaz.concurrent.Task
import scala.concurrent.duration._
// git bisect identifies the offending commit as
// https://github.com/scalaz/scalaz-stream/commit/721716ed7af0c126593e9ee227c0f36f21c5b7ed
object Test {
You can’t perform that action at this time.