Skip to content

Instantly share code, notes, and snippets.

View farleyknight's full-sized avatar
🎯
Focusing

Farley Knight farleyknight

🎯
Focusing
View GitHub Profile
require 'mechanize'
module MathUrl
def mathurl_agent
@agent ||= WWW::Mechanize.new
end
def mathurl_img_for(latex)
page = math_url_agent.get("http://mathurl.com")
form = page.forms.first
require 'tempfile'
class Firefox
def self.debug(page)
if page.is_a? File
page = page.read
elsif page.respond_to?(:body) and page.body.is_a? String
page = page.body
end
@farleyknight
farleyknight / latex_server.rb
Created November 22, 2008 03:30
Latex server. Pass equations, get pngs
# Usage:
# ruby latex_server.rb
#
# Try: <img src="http://localhost:4567/\cos \frac{\pi}{2} = 0">
# Get: A nice looking png of: cos(pi/2) = 0
#
# Bug1: Ellipses (...) don't work. Probably the way urls are parsed
# b
#!/usr/bin/env ruby
#
# A one file test to show count
require 'rubygems'
require 'dm-core'
require 'dm-aggregates'
# setup the logger
DataMapper::Logger.new(STDOUT, :debug)
def index
@carriers = Carrier.all.sort_by(&:name)
@lines = Array.new
@carriers.each do |c|
c.sw_profiles.each do |p|
@lines.push(prepend_hash_keys("carrier", c.attributes).merge(prepend_hash_keys("sw_profile", p.attributes)))
end
end
end
@farleyknight
farleyknight / postgresql_setup.sh
Created May 30, 2011 06:12
Setup postgresql for Rails testing on Ubuntu
# TODO:
# apt-get install Postgresql
# gem install postgresql
#
# ..more stuff...
#
# Make sure that your postgres account has
# superuser privileges, so "rake postgresql:build_databases"
# works properly
@farleyknight
farleyknight / require_benchmark.rb
Created June 9, 2011 14:25
Benchmarking the Rails boot process
# Stolen from here:
# http://alexyoung.org/2009/07/03/rapid-rails-boot-up-time/
require 'benchmark'
module Kernel
alias old_require require
def require(path)
#unless caller.find { |caller_line| caller_line.match /dependencies\.rb/ }
<project name="PrimeNumberAlgos" default="dist" basedir=".">
<description>
A few prime number algorithms written in Java.
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="lib" location="lib"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
@farleyknight
farleyknight / Gemfile
Created December 2, 2012 20:08
ComfortableMexicanSofa (CMS) + Spree + Devise + OmniAuth + Heroku
source 'https://rubygems.org'
gem 'rails', '3.2.9'
# Postgres Database
gem 'pg'
# Twitter API
gem 'twitter'
(function($){
$.support.selectstart = "onselectstart" in document.createElement( "div" );
$.fn.disableSelection = function(){
return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
".disableSelection", function( event ) {
event.preventDefault();
});
};
$.fn.enableSelection = function(){