Skip to content

Instantly share code, notes, and snippets.

@ms-tg
ms-tg / gist-1.rb
Created October 18, 2012 18:13 — forked from rondale-sc/gist-1.rb
try_and_try_again
class Project
attr_reader :supervisor
# assume supervisor looks like:
# ["Harry", "Henderson", "hhendersonfake@me.com"]
def initialize(supervisor)
@supervisor = supervisor
end
require 'hamster'
require 'hamster/experimental/mutable_hash'
# a bunch of threads with a read/write ratio of 10:1
num_threads = 100
num_reads_per_write = 10
num_loops = 500
hsh = Hamster.mutable_hash
puts RUBY_DESCRIPTION
CREATE TABLE filler (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT
) ENGINE=Memory;
CREATE TABLE t_param (
param INT NOT NULL PRIMARY KEY
) ENGINE=Memory;
CREATE TABLE t_source (
id INT NOT NULL PRIMARY KEY,
@ms-tg
ms-tg / StringWithToIntOpt.scala
Created March 18, 2013 14:38
Example of Scala enrich-my-library pattern: adding String#toIntOpt
package enriching_example
import scala.util.control.Exception.allCatch
case class StringWithToInt(s: String) {
def toIntOpt: Option[Int] = allCatch opt { s.toInt }
}
implicit def string2stringWithToInt(s: String) = StringWithToInt(s)
@ms-tg
ms-tg / test-dpkg-version-naming.bash
Last active December 20, 2015 10:30
Test our package naming proposal for debian
#!/bin/bash
##
# A script to test our debian package naming policy.
#
# This script uses `dpkg --compare-versions` to test that provided
# sequences of package names are considered to be in ascending order
# by Debian's tools.
#
# Author: Marc Siegel <marc.siegel@timgroup.com>
# Modified: 2013-07-30
@ms-tg
ms-tg / for-comp-either-right.scala
Created August 6, 2013 17:07
From Ratan: desugar a for-comprehension to see why assignment won't work with Either RightProjections
////
// Output of running:
// $ scala -Xprint:parser -e "val e: Either[String, Int] = Right(1); for {i <- e.right; j = i + 1} yield j"
////
//
// Picked up _JAVA_OPTIONS: -Xss3m -XX:MaxPermSize=256M
// /tmp/scalacmd2064075741948415763.scala:1: error: value map is not a member
// of Product with Either[String,(Int, Int)] with Serializable
// val e: Either[String, Int] = Right(1); for {i <- e.right; j = i + 1} yield j
// ^
@ms-tg
ms-tg / scala_try_monad_axioms.scala
Last active May 28, 2022 03:48
Scala Try: monad axioms
import scala.util.{Try, Success, Failure}
def f(s: String): Try[Int] = Try { s.toInt }
def g(i: Int): Try[Int] = Try { i * 2 }
def unit[T](v: T): Try[T] = Success(v)
//val v = "1"
val v = "bad"
val m = Success(v)
@ms-tg
ms-tg / jdk8_optional_monad_laws.java
Created November 11, 2013 21:14
Does JDK8's Optional class satisfy the Monad laws? Yes, it does.
/**
* ```
* Does JDK8's Optional class satisfy the Monad laws?
* =================================================
* 1. Left identity: true
* 2. Right identity: true
* 3. Associativity: true
*
* Yes, it does.
* ```