Skip to content

Instantly share code, notes, and snippets.

Marc ms-tg

Block or report user

Report or block ms-tg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ms-tg
ms-tg / why-doubles.scala
Last active Aug 29, 2015
In response to Slack post "Please explain why Doubles work this way"
View why-doubles.scala
// In response to Slack post "Please explain why Doubles work this way"
//
// For doubles...
// 1.001484375 - 1 = 0.0014843749999999822
// 0.001484375 + 1 = 1.001484375
//
// To run, start the repl with `sbt console`, then paste all this in
//
import java.lang.Double.doubleToRawLongBits
import java.lang.Long.{toBinaryString, toHexString}
@ms-tg
ms-tg / sbt-tg.sh
Last active Aug 29, 2015
Workaround to launch SBT when `play` command from 2.0.8 is also used
View sbt-tg.sh
#!/bin/bash
# WORKAROUND (2014-07-16, Marc): Avoids "No scala version specified or detected"
# error when Play 2.0.x and 2.3.x projects are both built by same local user.
if [ -e "${HOME}/.sbt/boot/other" ]; then
rm -rfv ~/.sbt/boot/other
rm -v ~/.ivy2/cache/org.scala-sbt/sbt/ivy-0.13.5.xml
fi
export SBT_OPTS="-Dsbt.repository.config=/etc/sbt/repositories -Dsbt.override.build.repos=true"
@ms-tg
ms-tg / jdk8_optional_monad_laws.java
Created Nov 11, 2013
Does JDK8's Optional class satisfy the Monad laws? Yes, it does.
View jdk8_optional_monad_laws.java
/**
* ```
* Does JDK8's Optional class satisfy the Monad laws?
* =================================================
* 1. Left identity: true
* 2. Right identity: true
* 3. Associativity: true
*
* Yes, it does.
* ```
@ms-tg
ms-tg / scala_try_monad_axioms.scala
Last active Nov 25, 2019
Scala Try: monad axioms
View scala_try_monad_axioms.scala
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 / for-comp-either-right.scala
Created Aug 6, 2013
From Ratan: desugar a for-comprehension to see why assignment won't work with Either RightProjections
View for-comp-either-right.scala
////
// 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 / test-dpkg-version-naming.bash
Last active Dec 20, 2015
Test our package naming proposal for debian
View test-dpkg-version-naming.bash
#!/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 / StringWithToIntOpt.scala
Created Mar 18, 2013
Example of Scala enrich-my-library pattern: adding String#toIntOpt
View StringWithToIntOpt.scala
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)
View mysql_in_list_vs_temp_tbl.sql
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,
View ruby_mutable_hash_demo.rb
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
@ms-tg
ms-tg / gist-1.rb
Created Oct 18, 2012 — forked from rondale-sc/gist-1.rb
try_and_try_again
View gist-1.rb
class Project
attr_reader :supervisor
# assume supervisor looks like:
# ["Harry", "Henderson", "hhendersonfake@me.com"]
def initialize(supervisor)
@supervisor = supervisor
end
You can’t perform that action at this time.