Skip to content

Instantly share code, notes, and snippets.

float InvSqrt (float x)
{
float xhalf = 0.5f*x;
int i = *(int*)&x;
i = 0x5f3759df - (i>>1);
x = *(float*)&i;
return x*(1.5f - xhalf*x*x);
}
@ianlevesque
ianlevesque / application.js
Created December 20, 2009 01:38
Automatically set the TimeZone in Rails >= 2.1
// detect time zone
Event.observe(window, 'load', function() {
var date = new Date();
date.setTime(date.getTime() + (1000*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
var offset = -(new Date().getTimezoneOffset() / 60);
document.cookie = "timezone=" + offset + expires + "; path=/";
});
@ianlevesque
ianlevesque / ButtonStyling.h
Created March 30, 2010 01:33
Take images created in Dashcode and prepare them for iPhone or iPad SDK UIButtons
//
// ButtonStyling.h
//
// Created by Ian Levesque on 3/29/10.
//
#import <UIKit/UIKit.h>
@interface UIImage(ButtonStyling)
# upstart script for nginx
description "nginx"
start on (net-device-up and local-filesystems)
stop on runlevel [016]
expect fork
respawn
exec /opt/nginx/sbin/nginx
@implementation UIImage(Utilities)
-(UIImage *)scaledToSize:(CGSize)size {
// if we're already that size, just return us
if(fabs([self size].width - size.width) < 0.001 && fabs([self size].height - size.height) < 0.001) {
return [[self retain] autorelease]; // we need to do this so that we could release the "original" before retaining the resized "copy"
}
int pixelsWide = size.width + 0.5;
int pixelsHigh = size.height + 0.5;
convert bufferpopoverbackground.png -fill none -draw "matte 0,0 reset" -tile bufferpopoverbackground.png -draw "rectangle -1,-1 306,180" \( +clone -background black -shadow 255x5+0+0 \) +swap -background none -layers merge +repage output.png
private static final Class[] mStartForegroundSignature = new Class[] {
int.class, Notification.class};
private static final Class[] mStopForegroundSignature = new Class[] {
boolean.class};
private NotificationManager mNM;
private Method mStartForeground;
private Method mStopForeground;
private Object[] mStartForegroundArgs = new Object[2];
private Object[] mStopForegroundArgs = new Object[1];
require 'rubygems'
require 'rack'
require 'addons'
require 'exceptional'
require 'json'
configure :production do
set :raise_errors, false
Exceptional.configure ENV['EXCEPTIONAL_API_KEY']
Exceptional::Remote.startup_announce(::Exceptional::ApplicationEnvironment.to_hash('sinatra'))
{
basic: ['android_low', 'android', 'android_high'],
premium: ['android_premium_low', 'android_premium_medium', 'android_premium', 'android_premium_high'],
defaults: {
basic_wwan: 'android',
basic_wifi: 'android_high',
premium_wwan: 'android_premium_medium',
premium_wifi: 'android_premium'
}
@ianlevesque
ianlevesque / capmon.rb
Created August 31, 2011 21:17 — forked from amscotti/capmon.rb
Ruby script to retrieve and display Comcast data usage. See http://www.128bitstudios.com/2011/08/27/comcast-data-usage-put-a-fork-in-it/
#!/usr/bin/env ruby
require 'rubygems'
require 'mechanize'
URL_PRELOADER = 'https://customer.comcast.com/Secure/Preload.aspx?backTo=%2fSecure%2fUsers.aspx&preload=true'
URL_USERS = 'https://customer.comcast.com/Secure/Users.aspx'
URL_ACCOUNT = 'https://customer.comcast.com/Secure/Account.aspx'
abort "Usage: #{$0} <username> <password>" unless ARGV.length == 2