Skip to content

Instantly share code, notes, and snippets.

@codingfoo
codingfoo / load_secrets.rb
Last active October 7, 2015 00:07
Load a secrets file
require 'ostruct'
require 'yaml'
::Secrets = OpenStruct.new(YAML.load_file(File.expand_path('../secrets.yml', __FILE__))[Rails.env])
@codingfoo
codingfoo / url_exists.rb
Created July 14, 2012 22:54
Check if remote url exists
def remote_url_exists?(url)
begin
url = URI.parse(url)
Net::HTTP.start(url.host, url.port) do |http|
return http.head(url.request_uri).code == "200"
end
rescue
false
end
end
@codingfoo
codingfoo / javascript_parse_benchmark.rb
Last active December 11, 2015 20:59
Javascript parsing benchmark
script = open(ARGV[0]).read
require "benchmark"
include Benchmark
require 'rkelly'
require 'parsejs'
require 'violet'
require 'content_urls'
@codingfoo
codingfoo / sax_vs_dom.rb
Last active December 11, 2015 20:59
Benchmark sax vs dom parsing for nokogiri
require 'nokogiri'
class MyDoc < Nokogiri::XML::SAX::Document
attr_reader :result
def initialize
@result = ""
end
def xmldecl version, encoding, standalone
@codingfoo
codingfoo / Readme.md
Last active February 12, 2016 03:44
Sensu Widget for Dashing

Description

Simple Dashing job to send sensu client history checks to dashing widgets.

##Dependencies

##Usage

Put the sensu.rb file in your /jobs folder.

@codingfoo
codingfoo / README
Last active December 17, 2015 16:39
Basic iptables config
https://help.ubuntu.com/community/IptablesHowTo
Place the scripts in
/etc/network/if-pre-up.d and /etc/network/if-post-down.d
@codingfoo
codingfoo / rocket_launcher.rb
Last active December 29, 2016 01:07
Foam Missile Launcher Control in Ruby
#!/usr/bin/env ruby
Version = '0.1'
abort("Usage: #{__FILE__} idVendor:idProduct") if ARGV.empty?
require 'curses'
require 'libusb'
# Add your own idVendor, idProduct, and movement codes here!
@codingfoo
codingfoo / number.cpp
Created December 30, 2013 15:41
Example of strtol function
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int val;
char str[20];
strcpy(str, "0x00010");
@codingfoo
codingfoo / boot.rb
Created January 20, 2014 23:12
Modify default rails server port
#config/boot.rb
require 'rails/commands/server'
module Rails
class Server
alias :default_options_alias :default_options
def default_options
default_options_alias.merge!(:Port => 3014)
end
end

Learn a variety of programming paradigms:

  • Write a program in assembly language
  • Write an application in a functional language
  • Write an application in an object-oriented language
  • Write an application in a prototype-based language
  • Write an application in a logic programming language
  • Write an application using the Actor model
  • Write an application in Forth