Skip to content

Instantly share code, notes, and snippets.

View michaelminter's full-sized avatar

Michael Minter michaelminter

View GitHub Profile
@michaelminter
michaelminter / timestamp.js
Last active December 14, 2015 23:09
Create a millisecond timestamp in Javascript
// create timestamp with milliseconds for unique id
var date = new Date();
var components = [
date.getYear(),
date.getMonth(),
date.getDate(),
date.getHours(),
date.getMinutes(),
date.getSeconds(),
date.getMilliseconds()
@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 / md5.js
Created January 17, 2013 01:38
md5 generator
/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*/
/*
@michaelminter
michaelminter / notes.md
Created November 14, 2012 18:05
FIXME, TODO, and OPTIMIZE code comments

You can add some special notes to your source code comments in Rails to remind you later of stuff you need to do:

class Article < ActiveRecord::Base
  # TODO add named_scopes
  # FIXME method A is broken
  # OPTIMIZE improve the code 

  has_many :comments
  ....

end

@michaelminter
michaelminter / git_rename.sh
Created October 22, 2012 17:50
Rename Git Branch
git branch -m old_branch new_branch
@michaelminter
michaelminter / colors.sh
Created October 19, 2012 15:04
Git terminal colors
#define GIT_COLOR_NORMAL ""
#define GIT_COLOR_RESET "\033[m"
#define GIT_COLOR_BOLD "\033[1m"
#define GIT_COLOR_RED "\033[31m"
#define GIT_COLOR_GREEN "\033[32m"
#define GIT_COLOR_YELLOW "\033[33m"
#define GIT_COLOR_BLUE "\033[34m"
#define GIT_COLOR_MAGENTA "\033[35m"
#define GIT_COLOR_CYAN "\033[36m"
#define GIT_COLOR_BOLD_RED "\033[1;31m"
@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 / 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"
@michaelminter
michaelminter / not_in.rb
Created October 18, 2012 02:35
Find an array of objects by whats NOT available
scope :not_in_user_locations, lambda { |user| { :conditions => ['locations.id NOT IN (SELECT locations.id FROM locations JOIN user_locations ON user_locations.location_id = locations.id WHERE user_locations.user_id = ?)', user.id] }}
@michaelminter
michaelminter / index.js
Created October 17, 2012 19:52
Clears a form with jQuery
$('form').clearForm()