Skip to content

Instantly share code, notes, and snippets.

View mmower's full-sized avatar
💭
Writing code

Matt Mower mmower

💭
Writing code
View GitHub Profile
@mmower
mmower / tryErb.erb
Created May 12, 2011 15:14 — forked from mattstifanelli/tryErb.erb
ERB File with Ruby code embedded into HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>try erb</title>
</head>
<body>
<p>
<% 99.downto(96) do |number| %>
<%= number %> bottles of beer…<br>
# Math Quiz by Jonathan J. Becker
# rewritten in an instructive Ruby style by Matt Mower <self@mattmower.com>
class Problem
attr_reader :arg1, :arg2
def initialize( arg1, arg2 )
if arg1 > arg2
@arg1, @arg2 = arg1, arg2
ENV['RAILS_ENV'] = ENV['RACK_ENV']
require "config/environment"
use Rails::Rack::LogTailer
use Rails::Rack::Static
run ActionController::Dispatcher.new
# config.ru
require 'config/environment'
use Rails::Rack::LogTailer
use ActionDispatch::Static
run ActionController::Dispatcher.new
- (float *)generateSineWaveWithFrequency:(float)frequency amplitude:(float)amplitude atSampleRate:(int)sampleRate {
float *wave = malloc( sampleRate * sizeof( float ) );
for( int n = 0; n < sampleRate; n++ ) {
wave[n] = sin( 2 * M_PI * ( (float)n / sampleRate ) * frequency ) * amplitude;
}
return wave;
}
@mmower
mmower / gist:850857
Created March 2, 2011 12:31
URI#domain method to extract the domain from a hostname
# Add a #domain method to URI to return the domain part of the hostname based on
# looking for valid IANA TLD names.
#
require 'open-uri'
module URI
def self.iana_tlds
@@iana_tlds ||= open( "http://data.iana.org/TLD/tlds-alpha-by-domain.txt" ).read.split(/\n/).reject { |s| s =~ /^#/ }.map { |d| d.upcase }
@mmower
mmower / loadbeep
Created January 24, 2011 12:59
A script that monitors the 5-minute load average taking regular samples of top and iostat. When the 5m load goes above a threshold it sets off an alarm that gives regular terminal beeps. It also writes out the accumulated data from top & iostat to a file.
#!/usr/bin/ruby -w
# by Matt Mower <self@mattmower.com>
#
# A script that monitors the 5-minute load average taking regular samples of top and iostat.
# When the 5m load goes above a threshold it sets off an alarm that gives regular terminal
# beeps. It also writes out the accumulated data from top & iostat to a log file.
#
class LoadAverageMonitor
02/12/2010 21:53:42 [0x0-0x546546].com.apple.Xcode[10430] osascript: couldn't save changes to script /Developer/Library/Xcode/Plug-ins/Xmod.pbplugin/Contents/Resources/Scripts/Xmod.scpt: Permission denied
-- EVENTS I AM GENERATING --
[Event no. 2] Triggered by WILL POST EVENT delegate method:
<PFEvent: 0x102f13860>
type: 11 (kCGEventKeyUp)
timestamp: 10904738161000
position: {857, 661}
target PID: 1498 (name: Reaktor 5)
target PSN: 254014 (name: Reaktor 5)
source PID: 2597 (Freeman)
Shaddam:Freeman matt$ rake --trace dmg
(in /Volumes/Corrino/matt/Projects/LucidMac/Freeman)
** Invoke dmg (first_time)
** Invoke build (first_time)
** Invoke build/Release/Freeman.app/Contents/Info.plist (first_time)
** Execute build/Release/Freeman.app/Contents/Info.plist
xcodebuild -configuration Release -target Freeman
=== BUILD NATIVE TARGET Freeman OF PROJECT Freeman WITH CONFIGURATION Release ===
Check dependencies