Skip to content

Instantly share code, notes, and snippets.

View andrewle's full-sized avatar

Andrew Le andrewle

View GitHub Profile
#!/bin/sh
# Textmate command that uses AppleScript to switch to Firefox, reload
# the browser, and then switch back to Textmate
# I have this bound to Ctl-Opt-Command R
#
# Save: Nothing (or Current File is useful too)
# Input: None
# Output: Discard
#
@andrewle
andrewle / center_window.sh
Created April 19, 2010 06:37
Center the top most window using AppleScript
#!/usr/bin/env bash
# Center the top most window using AppleScript
# I call this up quickly using Quicksilver and run it as a terminal
# script because (surprise!) it's faster than running as native AppleScript
osascript -e "
tell application \"Finder\"
set screenSize to bounds of window of desktop
set screenWidth to item 3 of screenSize
end tell
@andrewle
andrewle / leader-election.md
Created April 16, 2012 02:06 — forked from ryandotsmith/process-partitioning.md
Leader Election With Ruby & PostgreSQL

Leader Election With Ruby & PostgreSQL

The Problem

I have a table with millions of rows that needs processing. The type of processing is not really important for this article. We simply need to process some data with Ruby --or any other user-space programming language.

A Solution

{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"strict": true,
"noUnusedLocals": true,
"strict": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
@andrewle
andrewle / clever-rails.rb
Created September 20, 2012 10:04
A Rails app generator tuned my common needs
#!/usr/bin/env ruby
require 'rails/generators'
require 'rails/generators/rails/app/app_generator'
require "active_support/core_ext/string/strip"
class CleverAppGenerator < Rails::Generators::AppGenerator
class_option :skip_bundle, default: true
class_option :database, default: "postgresql"
class_option :skip_test_unit, default: true, hide: true
@andrewle
andrewle / capture.rb
Created July 27, 2010 21:08
Get full screen shots of a list of webpages using webkit2png.py
#!/usr/bin/env ruby
PROJECT_NAME = ""
pages = %w{
... urls to pages go here
}
pages.each_with_index do |url, index|
system("python webkit2png.py -W 1200 -o #{PROJECT_NAME}_#{index} -F #{url}")
"use strict";
class Board {
constructor() {
this.width = 10;
this.height = 12;
this.grid = this._initializeToZeros();
this.grid[2][1] = 1;
}
@andrewle
andrewle / test.rb
Created October 17, 2016 16:25
Print deprecation notices to stderr after all tests have run
# I've always disliked the way deprecation notices would appear while the test
# suite is running: they break up the neat little rows of dots (or F's, as it
# may be) which causes noise and makes the notices hard to read and understand.
#
# Adding this snippet to `config/environments/test.rb` will buffer all your
# deprecation notices until the end of the test run and keep your test output
# nice and tidy.
#
Rails.application.config do
# ...
#!/bin/bash
function gitroot {
if [ "$(pwd)" != "$(git rev-parse --show-toplevel)" ]; then
go-to-git-root
elif [ $(cd .. && git rev-parse --is-inside-work-tree &> /dev/null; echo $?) -eq 0 ]; then
cd .. && go-to-git-root
fi
}
# MIT License:
#
# Copyright (C) 2012 Heroku, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions: