Skip to content

Instantly share code, notes, and snippets.

View michaelminter's full-sized avatar

Michael Minter michaelminter

View GitHub Profile
@michaelminter
michaelminter / colors.rb
Created October 19, 2012 15:03
Ruby globals for working with terminal ANSI color codes
CLEAR = "\e[0m"
BOLD = "\e[1m"
# Colors
BLACK = "\e[30m"
RED = "\e[31m"
GREEN = "\e[32m"
YELLOW = "\e[33m"
BLUE = "\e[34m"
MAGENTA = "\e[35m"
@michaelminter
michaelminter / localstorageModel.js
Last active October 26, 2023 03:57
A Javascript class object that acts like Rails' ActiveRecord with localStorage.
///////////////////////////////////////////////////////////////////////////////
//
// Simulate an activerecord-like model class
// in general JavaScript is a class-less language. Everything is an object.
// http://www.phpied.com/3-ways-to-define-a-javascript-class/
//
///////////////////////////////////////////////////////////////////////////////
// ## Data
// Objects should be indexed by id
@michaelminter
michaelminter / git-colors.md
Created October 1, 2012 00:35
Colors in git

Bored with just black and white in your git status? Add some colour!

Open up your global Git configuration file (it should be found in ~/.gitconfig) and enter this into it:

[color]
  ui = auto
[color "branch"]
  current = yellow reverse
  local = yellow

remote = green

=begin
Given 2 water jugs of different sizes and an unlimited source of water, perform different operations to end up with some goal amount of water.
Write out the operations and how much water is in the jugs at each step.
Problem 1 --- Small = 3, Big = 5, Goal = 4
- Start (0, 0)
- Fill small (3, 0)
- pour to big (0, 3)
- Fill small (3, 3)
@michaelminter
michaelminter / scp.md
Created November 8, 2013 21:11
scp examples # command line, linux, mac

#Example syntax for Secure Copy (scp)

##What is Secure Copy?

scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.

###Examples

Copy the file "foobar.txt" from a remote host to the local host

@michaelminter
michaelminter / JQuery Event Change based on select drop-down
Created May 9, 2011 00:15
JQuery Event Change based on select drop-down
var events = [];
events[0] = ["Display content notification box 1"];
events[1] = ["Display content notification box 2"];
events[2] = ["Display content notification box 3"];
function updateEventDescription(){
for(var i = 0; i < events.length; i++){
if($('#prospect_event option:selected').val() == events[i][0]){
$("#event_description").html(events[i][1]);
i = events.length;
@michaelminter
michaelminter / twitter.rb
Created October 18, 2012 15:29
How to use watir-webdriver
#!/usr/bin/ruby
require 'rubygems'
require 'watir-webdriver'
o = [('a'..'z'),('A'..'Z'),(0..9)].map{|i| i.to_a}.flatten
string = (0...8).map{ o[rand(o.length)] }.join
# settings
username = "michael@moorberry.net"
password = "password"
class BaseQuery
attribute_accessor :object, :query
def initialize
@object = Null
@query = [@object]
end
def execute
@query.map.with_index { |q, i| i == 0 ? q : merge(q) }.join(send '.') # wtf
/*
CONTEXT:
- add a brief description of why we need this query
RESULT EXPECTATION
- add a brief description of your expectations for the query result
ASSUMPTION:
- add assumption about business logic
- add assumption about data
*/
@michaelminter
michaelminter / csv_to_s3.rb
Created April 29, 2019 17:40
Upload CSV stream from Rails to S3
def query_results
ActiveRecord::Base.connection.execute('SELECT name FROM accounts;').to_a
end
# @params [Array<Hash>] records
def generate_csv(records)
attributes = records.first.keys
CSV.generate(headers: true) do |csv|
csv << attributes