Skip to content

Instantly share code, notes, and snippets.

View earlonrails's full-sized avatar

Kevin Krauss earlonrails

  • Disney Streaming
  • San Francisco
View GitHub Profile
@earlonrails
earlonrails / application.xml
Created November 3, 2011 22:10
Simple adobe air browser.
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<application xmlns="http://ns.adobe.com/air/application/2.6">
<!-- Adobe AIR Application Descriptor File Template.
Specifies parameters for identifying, installing, and launching AIR applications.
xmlns - The Adobe AIR namespace: http://ns.adobe.com/air/application/2.0
The last segment of the namespace specifies the version
of the AIR runtime required for this application to run.
@earlonrails
earlonrails / fizzbuzz.sh
Last active November 25, 2022 11:15
Fizz Buzz in bash! Hooray!
#!/bin/bash
x=1
while [ $x -le 100 ]
do
if [[ 0 -eq "($x%3) + ($x%5)" ]]
then
# Check if divide by 3 & 5 #
echo "fizz buzz"
elif [[ 0 -eq "($x%5)" ]]
then
@earlonrails
earlonrails / input_changer.js
Created November 26, 2011 23:25
Clear Field on Focus and restore if nothing entered javascript and html input.
function autoUnput(thefield, orig){
if(orig){
if(thefield.value == ''){
thefield.value = orig;
}
} else if (thefield.defaultValue==thefield.value){
thefield.value = "";
}
}
@earlonrails
earlonrails / untarzip_grep.rb
Created December 6, 2011 20:44
Untar and unzip and then grep and output results.
#!/usr/local/bin/ruby
pattern = ARGV[0]
files = ARGV[1..-1]
unless pattern || files
puts "Usage: ./untarzip_grep.rb pattern tar-gz-file ... \n"
exit
else
files.each do |f|
system("tar -O -xzf #{f} | grep #{pattern}")
@earlonrails
earlonrails / time_it.rb
Created December 11, 2011 23:31
Just time some block of code in ruby. Benchmark is better but this was just for fun.
def time_it(&block)
start_time = Time.now
if block_given?
yield
end_time = Time.now
elapsed = end_time - start_time
out = "Took "
out += "#{(elapsed/3600).to_i} (h) " if (elapsed/3600).to_i > 0
out += "#{((elapsed/60) > 60 ? (elapsed/60) % 60 : (elapsed/60)).to_i} (m) " if (elapsed/60).to_i > 0
out += "#{'%.4f' % (elapsed > 60 ? elapsed % 60 : elapsed)} (s)" if (elapsed)
@earlonrails
earlonrails / mock_curl_multi.rb
Created December 13, 2011 01:56
Mock curl multi for ruby spec testing!!!
require 'curl-multi'
require 'mocks'
CURL_NEW = Curl::Multi.method(:new) unless defined? CURL_NEW
#
# Example:
# mock_curl_next_request { |req|
# req.add_chunk("<xml>junk</xml>")
# req.do_success
@earlonrails
earlonrails / mock_tcp_socket.rb
Created December 13, 2011 01:57
Mock tcp socket for spec tests with ruby!!!
require 'socket'
require 'mocks'
TCP_NEW = TCPSocket.method(:new) unless defined? TCP_NEW
#
# Example:
# mock_tcp_next_request("<xml>junk</xml>")
#
class FakeTCPSocket
@earlonrails
earlonrails / secret_santa.rb
Created December 22, 2011 19:09
Secret Santa solver.
#!/usr/bin/ruby
# Secret Santa Solver
=begin
ruby secret_santa.rb
Luke Skywalker <luke@theforce.net>
Leia Skywalker <leia@therebellion.org>
Toula Portokalos <toula@manhunter.org>
Gus Portokalos <gus@weareallfruit.net>
Bruce Wayne <bruce@imbatman.com>
Jill Wayne <jilly@imbatmanswoman.com>
@earlonrails
earlonrails / defined.js
Created February 7, 2012 18:43
check if a variable is defined
function defined(obj){
return (typeof obj != 'undefined');
}
// function defined(obj){
// return (typeof obj != 'undefined' || obj != null);
// }
// function defined(obj){
// try{
@earlonrails
earlonrails / mock_io.rb
Created February 28, 2012 23:19
Mock IO in ruby
require 'curl-multi'
require 'spec/mocks'
=begin
# Example:
require 'spec/mock_io'
mock_next_io(lambda{["We Mocked!"]}, lambda{"another block"})
io = IO.new
io.write("log")
io.flush