Skip to content

Instantly share code, notes, and snippets.

@tstone
tstone / val-vs-lazy-val.scala
Last active November 11, 2022 10:29
val vs. lazy val for implicit class's in Scala
implicit class StringOps(s: String) {
val one = { println("one"); "one" }
val two = { println("two"); "two" }
lazy val three = { println("three"); "value" }
}
scala> "asdf".three
one

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

pry-nav

@tstone
tstone / Timer.java
Created July 27, 2021 23:37
Timer for VM
package com.collidermodular.util;
public class Timer {
private final double samplesPerMs;
private final Runnable runnable;
private double duration;
private double sampleCounter;
private double targetSampleCount;
private boolean active;
package com.collidermodular.core;
public interface Host {
public double getSampleRate();
public double getSamplesPerMs();
public double getMsPerSample();
public double getTempo();
}
public interface ValueSource {
// Based on the "3.3 Naive lowpass filter" 1-pole filter from:
// https://www.native-instruments.com/fileadmin/ni_media/downloads/pdf/VAFilterDesign_2.1.2.pdf
// https://www.youtube.com/watch?v=zPzCLqkQnr0
class OnePoleLowPass {
private double cutOff; // unit: rads per sample
private double z = 0.0;
final double samplesPerSec = Values.SamplesPerMs * 1000;
final double twoPi = 2 * Math.PI;
#
# A python module to implement recursive search/copy of files
#
import datetime
import shutil
import os
import re
class DirSearch(object):
@tstone
tstone / fizzbuzz-python.py
Created October 29, 2009 07:25
Recursive Python FizzBuzz solution
def fizzbuzz (start, end):
if start % 15 == 0:
print 'fizzbuzz'
elif start % 3 == 0:
print 'fizz'
elif start % 5 == 0:
print 'buzz'
else:
print start
class A
@value = "a"
def self.print
puts @value
end
end
class B < A
@value = "b"
module.exports = {
A: {
hello: function() {
return 'hello';
}
}
}
@tstone
tstone / gist:8449893
Last active January 3, 2016 10:29
Scala Futures + For Comprehension/Seq's
// DEMO CODE
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
def time[A](label: String, block: => Future[A]) = {
val t0 = System.nanoTime()
block.onComplete {
case _ => {
val t1 = System.nanoTime()