Skip to content

Instantly share code, notes, and snippets.

@TrevorS
TrevorS / whiteboard_cleaner.sh
Created January 20, 2015 19:32
whiteboard cleaner
#!/bin/bash
convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2
class ActiveRecord::Base
def self.import!(record_list)
raise ArgumentError 'record_list not an Array of Hashes' unless record_list.is_a?(Array) && record_list.all? {|rec| rec.is_a? Hash }
return if record_list.empty?
record_list.in_groups_of(1000, false).each do |record_group|
key_list, value_list = convert_record_list(record_group)
sql = "INSERT INTO #{self.table_name} (#{key_list.join(', ')}) VALUES #{value_list.map {|rec| "(#{rec.join(', ')})" }.join(' ,')}"
self.connection.insert_sql(sql)
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
Bulbasaur
Ivysaur
Venusaur
Charmander
Charmeleon
Charizard
Squirtle
Wartortle
Blastoise
Caterpie
#!/usr/bin/env ruby
# encoding: utf-8
Dir['*.csv'].each { |f| File.rename(f, "#{f.to_i}.csv") }
@TrevorS
TrevorS / TestChar.java
Last active August 29, 2015 14:08
"" + (char) b vs. Character.toString((char) b)
public class TestChar {
public static void main(String[] args) {
long tests = 1000000000;
byte b = (byte) 'b';
long start = System.nanoTime();
for (int i = 0; i < tests; i++) {
String a = "" + (char) b;
}
System.out.println("Done: " + (System.nanoTime() - start) / 1000000000.0);
@TrevorS
TrevorS / TestChar.java
Last active August 29, 2015 14:08
"" + c vs. Character.toString(c)
public class TestChar {
public static void main(String[] args) {
long tests = 1000000000;
char c = 'c';
long start = System.nanoTime();
for (int i = 0; i < tests; i++) {
String a = "" + c;
}
System.out.println("Done: " + (System.nanoTime() - start) / 1000000000.0);
require 'csv'
namespace :customers do
desc 'Load customers and their addresses'
task :load, [:path] => :environment do |t, args|
headers = [:telephone, :name, :lot_no, :street_direction, :street_name, :street_subtitle,
:city, :service_type, :lcp_name, :nap_name, :nap_count, :nap_size]
modem_models = %w{ZNID-GPON-2424 ZNID-GPON-2425 ZNID-GPON-2426}.map { |m| { name: m } }
models = ModemModel.create!(modem_models)
@TrevorS
TrevorS / find_modems_from_fiber_strand.rb
Created October 2, 2014 13:11
Find all modems from a distribution strand (joining nested associations).
Modem.joins(
network_access_point_port:
{ distribution_strand:
{ splitter_port: :splitter } } ).where('splitters.fiber_strand_id' => 121)
[1, 2, 3, 7, 8, 11, 12, 13].enum_for(:chunk).with_index { |x, index| x - index }.map { |diff, group| [group.first, group.last] }