Skip to content

Instantly share code, notes, and snippets.

View jessitron's full-sized avatar
🚀
"I'm in"

Jessica Kerr jessitron

🚀
"I'm in"
View GitHub Profile
@jessitron
jessitron / methodAsFunction
Last active August 29, 2015 14:00
JavaScript illustrates that methods are the same as functions with an implicit parameter "this"
var completeSale = function(num) {
console.log("Sale " + num + ": selling " + this.items + " to " + this.customer);
}
var foo = {
customer: "Fred",
items: ["carrot","eggs"],
complete: completeSale
};
@jessitron
jessitron / etaExpansionAndImplicits
Created April 16, 2014 22:59
scala is so weird
scala> class Banana[P] {}
defined class Banana
// We will know when this gets called, when the banana is needed
scala> implicit def myBanana[P]: Banana[P] = { println("banana time"); new Banana[P] }
myBanana: [P]=> Banana[P]
// method with implicits
scala> def addWithBanana(one: Int)(two: Int)(implicit banana: Banana[Int]) = {println(banana); one + two}
@jessitron
jessitron / stayingDead.scala
Created March 19, 2014 15:23
Akka testing: it's a good idea to tell your actor system to leave a dead top-level actor dead. See: http://blog.jessitron.com/2014/03/testing-in-akka-sneaky-automatic.html
// In real life, it's great that stuff gets restarted when it fails.
// In testing, we'd rather know that it failed.
import akka.actor._
class DyingActor extends Actor {
def receive = { case "die" => throw new Exception("poo") }
}
// Default config, everything restarts automatically
val system = ActorSystem("ordinary")
@jessitron
jessitron / gist:9644001
Created March 19, 2014 15:22
Akka testing: it's a good idea to tell your actor system to leave a dead top-level actor dead.
// In real life, it's great that stuff gets restarted when it fails.
// In testing, we'd rather know that it failed.
import akka.actor._
class DyingActor extends Actor {
def receive = { case "die" => throw new Exception("poo") }
}
// Default config, everything restarts automatically
val system = ActorSystem("ordinary")
@jessitron
jessitron / gist:9191499
Created February 24, 2014 16:24
StackOverflow in scalaz-stream. My trampoline is not bouncy enough
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 {
@jessitron
jessitron / gist:8777503
Created February 3, 2014 01:09
The magic of blocking { ... } in Scala's global ExecutionContext: it leads to the creation of more threads, so the CPUs don't get bored
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:8376139
Created January 11, 2014 20:15
scala: print all URLs on classpath
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")

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 / ExplicitErrorReturning
Created June 15, 2013 17:58
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!"
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")
@jessitron
jessitron / gem_cleaner.rb
Last active December 17, 2015 05:09 — forked from kgrz/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