Skip to content

Instantly share code, notes, and snippets.

View gerad's full-sized avatar

Gerad Suyderhoud gerad

View GitHub Profile
@gerad
gerad / gist:3881072
Created October 12, 2012 19:38
get 50 random words from the dictionary (on mac os x)
awk 'BEGIN {srand()} {print rand() " " $0}' /usr/share/dict/words | sort | head -50
@gerad
gerad / gist:3824482
Created October 3, 2012 01:54
example mongodb query for documents containing arrays with null values
db.collection.find({ arrayWithNulls: { $elemMatch: { $type: 10 }}});
@gerad
gerad / authors-over-time.rb
Created April 27, 2012 02:20
git authors over time
require 'set'
require 'date'
author = nil
authors = {}
`git log`.split("\n").reverse.each do |line|
if line.match(/^Author:\s+(.*)$/)
author = $1
end
@gerad
gerad / hack.sh
Created April 12, 2012 22:58 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2371651/hack.sh | sh
#
@gerad
gerad / xcode-git-version.sh
Created April 5, 2012 01:03 — forked from jpwatts/xcode-git-version.sh
This Xcode 4 build phase script automatically sets the version and short version string of an application bundle based on information from the containing Git repository.
#!/bin/bash
# This script automatically sets the version and short version string of
# an Xcode project from the Git repository containing the project.
#
# To use this script in Xcode 4, add the contents to a "Run Script" build
# phase for your application target.
set -o errexit
set -o nounset
@gerad
gerad / jquery.snapengage.js
Created March 8, 2012 18:58
snapengage async jquery plugin
;// http://www.snapengage.com/docs/asyncload.jsp
// usage: $.snapengage()
// loads snapengage asynchronously. A click on any link with class 'snapengage'
// will cause the chat to open.
!function($, window, undefined) {
var widgetid = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX';
$.snapengage = function() {
@gerad
gerad / console-stub.js
Created February 29, 2012 18:55
stub out the javascript console for IE
!function(w) {
debugger
if (!w.console) {
var c = w.console = {};
c.log = c.error = c.info = c.debug = c.warn = c.trace = c.dir = c.dirxml = c.group = c.groupEnd = c.time = c.timeEnd = c.assert = c.profile = c.profileEnd = function() {};
}
}(window);
@gerad
gerad / top-domains.js
Created January 26, 2012 19:07
query time spent by domain using tractor
var map = function() {
var domain = this.info.url.match(/^https?:\/\/([^\/]*)/)[1];
emit(domain, { duration: this.duration });
};
var reduce = function(key, values) {
var result = { duration: 0 };
values.forEach(function(value) {
result.duration += value.duration
});
@gerad
gerad / axInfoForProcessIdentifier.m
Created January 20, 2012 04:45
get the name and path of the frontmost window using the carbon mac os accessibility api
// http://stackoverflow.com/questions/2107657/mac-cocoa-getting-a-list-of-windows-using-accessibility-api
// http://stackoverflow.com/questions/853833/how-can-my-app-detect-a-change-to-another-apps-window
// http://cocoatutorial.grapewave.com/tag/axuielementcopyattributevalue/
- (NSDictionary *)axInfoForProcessIdentifier:(NSNumber *)processIdentifier
{
NSMutableDictionary *ret = [NSMutableDictionary dictionaryWithCapacity:2];
pid_t pid = (pid_t) [processIdentifier integerValue];
AXUIElementRef app = AXUIElementCreateApplication(pid);
AXUIElementRef frontWindow = nil;
NSString *title = nil;
@gerad
gerad / trackmac.rb
Created May 8, 2011 19:36
get information on the currently active mac window in ruby / applescript
require 'rubygems'
require 'bundler/setup'
require 'appscript'
# http://stackoverflow.com/questions/480866/get-the-title-of-the-current-active-window-document-in-mac-os-x
while true
frontmost = Appscript.app('System Events').application_processes.get.select{ |a| a.frontmost.get }.first
if frontmost
puts frontmost.name.get
if frontmost.windows.count > 0