Skip to content

Instantly share code, notes, and snippets.

View jamesmccann-zz's full-sized avatar

James McCann jamesmccann-zz

View GitHub Profile
@jamesmccann-zz
jamesmccann-zz / activerecord.rake
Created April 27, 2017 23:37
Hanami ActiveRecord rake tasks
require 'active_record'
require 'require_all'
require 'yaml'
namespace :db do
env = ENV['HANAMI_ENV'] || ENV['RACK_ENV'] || 'development'
db_config = YAML::load(File.open('config/database.yml'))[env] \
|| ActiveRecord::Base.configurations[env]
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
@jamesmccann-zz
jamesmccann-zz / gist:a8c34d7e0496c5259c082a92938ca710
Last active April 20, 2017 02:32
All Modernizr JS Properties/CSS Classes
ambientlight
applicationcache
audio
batteryapi
blobconstructor
canvas
canvastext
contenteditable
contextmenu
cookies

Bachman compared the Ptolemaic-to-Copernican change in astronomy to the change in computer programming in the early 1970s. When Bachman made the comparison in 1973, data processing was changing from a computer-centered view of information systems to a database-centered view. Bachman pointed out that the ancients of data processing wanted to view all data as a sequential stream of cards flowing through a computer (the computer-centered view). The change was to focus on a pool of data on which the computer happened to act (a database-oriented view).

Today it's difficult to imagine anyone thinking that the sun revolves around the Earth. Similarly, it's difficuly to imagine a programmer thinking that all data could be viewed as a sequential stream of cards.

Steve McConnell, Code Complete 2, 2004

@jamesmccann-zz
jamesmccann-zz / ios-resize.sh
Created July 7, 2015 03:08
iOS asset resize
#!/bin/bash -e
dir=$1
if [[ -d $dir ]]; then
cd $dir
else
echo "ios-ar expects a directory as the first argument"
exit 1
fi
@jamesmccann-zz
jamesmccann-zz / gist:2e16cd33d1eeea105a2f
Created November 7, 2014 03:46
Covert repeating day flags to an integer
public static int booleanArrayToInt(boolean[] dayFlags) {
int result = 0;
for (int i = 0; i < dayFlags.length; i++) {
result += (dayFlags[i]? 1 : 0) * Math.pow(2, i);
}
return result;
}
public static boolean[] intToBooleanArray(int days) {
boolean[] result = new boolean[7];
@jamesmccann-zz
jamesmccann-zz / resize.sh
Created October 6, 2014 21:39
Android asset resize script (run inside a folder of 3x images).
#!/bin/bash -e
# Ensure we're running in location of script.
cd "`dirname $0`"
mkdir ./drawable-mdpi
mkdir ./drawable-hdpi
mkdir ./drawable-xhdpi
mkdir ./drawable-xxhdpi
@jamesmccann-zz
jamesmccann-zz / view_migrations.md
Last active August 29, 2015 14:05
ActiveRecord View Migrations

Rake task to perform "view migrations" for using SQL Views with Rails. Avoids the need to copy or re-run multiple migrations when changes are made to queries providing view data.

Usage: rake db:views:load

Place SQL create statement for each view in a file as db/views/<view_name>.sql. Optionally include a numeric prefix such as 01_first_view.sql to order views that may have dependencies.

namespace :db do
  namespace :views do
    desc "Execute all stored View statements on DB connection"
@jamesmccann-zz
jamesmccann-zz / gist:81b7756f47bf565493df
Created May 21, 2014 00:00
Using a clip-path for circular avatar images in D3
# Add a clippath to defs for circular profile images
defs.append('clipPath')
.attr('id', 'clip-circle')
.append('circle')
.attr('r', PROFILE_IMAGE_RADIUS)
.attr('cx', 0)
.attr('cy', 0)
# Usage
nodeGroup.append('g')
@jamesmccann-zz
jamesmccann-zz / variable_parser.rb
Last active December 28, 2015 22:28
Find all unique instance variable declarations in a Ruby Module
seen_variables = []
File.open(ARGV[0], 'r').each do |line|
line = line.strip!
/^@\w+/.match(line) do |v|
puts v unless seen_variables.include?(v.to_s)
seen_variables << v.to_s
end
end