Skip to content

Instantly share code, notes, and snippets.

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;
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 / name.asm
Created October 23, 2014 06:39
My first shot at 6502 assembler, circa 2002
; INES header
.inesprg 1 ; how many program banks
.ineschr 1 ; how many picture banks
.inesmap 0 ; mapper 0
.inesmir 1 ; mirror to 1
.bank 1 ; bank 1
.org $FFFA ; start address
.dw 0 ; dw = define word!
.dw Start ; give address of start of our code for rest of NES
package services.config
import scala.concurrent.Future
import scala.reflect.runtime.universe._
trait ReflectedAttributes {
protected val instanceMirror = runtimeMirror(this.getClass.getClassLoader).reflect(this)
protected val members = instanceMirror.symbol.typeSignature.members
trait Person
class Manager extends Person
class Engineer extends Person
val people = Seq(new Engineer, new Manager)
people.map(_.toJson)
// PROBLEM: Implicit lookup is for a Writes[Person], not a Writes[Engineer] and Writes[Manager]
// long-hand boilerplate:
case class ExampleParams(foo: String, bar: String, baz: String) extends Params {
def withFoo(value: String) = this.copy(foo = value)
def withBar(value: String) = this.copy(bar = value)
def withBaz(value: String) = this.copy(baz = value)
}