Skip to content

Instantly share code, notes, and snippets.

View will3216's full-sized avatar

Will Bryant will3216

  • Tout
  • San Francisco, CA
View GitHub Profile
@will3216
will3216 / random_useful_rails_console_commands.rb
Created October 23, 2015 01:20
Some random console commands for use in rails
# Generate random text via an online API: Useful for generating fake data
# For more options see: https://baconipsum.com/json-api/
#Generate random sentence
require 'open-uri'
def random_sentence(count=1); open("https://baconipsum.com/api/?type=meat-and-filler&sentences=#{count}&format=text&start-with-lorem=0").read; end
# < random_sentence
# => "Bacon ipsum dolor amet aute brisket cupidatat ribeye, ball tip consequat shoulder pig chuck adipisicing shankle."
# Random paragraph
def random_paragraph(count=1); open('https://baconipsum.com/api/?type=meat-and-filler&paras=#{count}&format=text&start-with-lorem=0').read; end
@will3216
will3216 / gist:a44c9ad3a18d69abaf67
Created July 1, 2015 20:22
Log information about callbacks for the Lifecycle of a Rails 3.2.19 (Wraps state-machine callbacks as well if state-machine is being used)
# This is used for debugging callbacks chains, to use this code:
# 1. Drop this into an initializer in your rails app
# 2. Set the LG_FILE_PATH to the file location you want the logging to go too
# 3. Set MODEL_TO_DEBUG to the class you want to debug, ie: MODEL_TO_DEBUG
# 4. Change the print_string method to save the relevant information. It has
# access to any instance methods on the object presently in the callback chain
# Note: Not sure how compatible this is with other versions of rails/state-machine
# VERSIONS PATCHED
# State-Machine 1.1.2
[info] Compiling 1 Scala source to /home/godzirra/code/target/scala-2.9.1/classes...
[error] /home/godzirra/code/fraud.scala:25: type mismatch;
[error] found : scala.collection.immutable.Iterable[Int]
[error] required: Seq[?]
[error] var temp = scala.collection.mutable.ArrayBuffer((array_1):_*)
[error] ^
[error] /home/godzirra/code/fraud.scala:34: value sortWith is not a member of scala.collection.immutable.Iterable[Int]
[error] val result = fraud_exclaimation_point.sortWith(_.compareTo(_) < 0).mkString(",")
[error] ^
[error] two errors found
def iterate_values(current_values: Array[Array[Double]]): Array[Array[Double]] = {
val new_values: Array[Array[Double]] = Array.fill[Double](initial_condition.size, initial_condition(0).size)(0.0)
for (i <- 0 until initial_condition.size) {
for (j <- 0 until new_values(i).size) {
new_values(i)(j) = sor_formula(current_values, i, j)
}
}
}
def earliest_start_time(task: Int, solution: Solution): Int = {
var current_earliest = 0
solution.task_list.filter(p => p.task_id == task).foreach{p =>
p.precedence_constraint.foreach{r =>
solution.task_list.filter(y => y.task_id == r).foreach{t =>
if (t.precedence_constraint.isEmpty == true) {
if (t.empty_start_time == true){
return 0
}else{