Skip to content

Instantly share code, notes, and snippets.

View madpilot's full-sized avatar

Myles Eftos madpilot

View GitHub Profile
@madpilot
madpilot / blueprints.rb
Created February 22, 2010 08:34
Some sample test setup files
require 'machinist/active_record'
require 'sham'
require 'faker'
Sham.define do
title { Faker::Lorem.words(2).join(' ') }
permalink { Faker::Lorem.words(2).join('-') }
status(:unique => false) do
case(rand(3))
when 0:
if Rails.env == 'production' && File.exists?(File.join(Rails.root, 'REVISION'))
revision = File.read(File.join(Rails.root, 'REVISION')).strip
ActionController::Base.asset_host = "yourcdn.s3.amazon.com/#{revision}"
end
module Sass::Script::Functions
def url(string)
if Rails.env == 'production' && File.exists?(File.join(Rails.root, 'REVISION'))
revision = File.read(File.join(Rails.root, 'REVISION')).strip
path = string.value
// Create a file on your desktop, enter the code, and then open it LOCALLY in your browser
// This works...
var http = new XMLHttpRequest();
var url = "http://www.need-a-real-url.com";
var params = "<data></data>";
http.open("POST", url, true);
http.send(params);
// This doesn't...
require 'test_helper'
class SyncTest < Test::Unit::TestCase
include TestHelper
context 'SyncTest' do
setup do
setup_context
Titanium.include('lib/88miles.js')
Titanium.include('lib/sync.js')
class SmokeyTheBear
def method_missing(symbol, *args)
responses = [ :me, :you ]
if responses.include?(symbol)
what_was_said = symbol.to_s
what_was_meant = responses.dup.delete_if { |r| r == symbol }.first.to_s
return "You chose '#{what_was_said}' referring to '#{what_was_meant}'. That is incorrect. The correct answer is '#{what_was_meant}'."
else
super
@madpilot
madpilot / base_record.rb
Created December 1, 2010 07:01
Base Record - allows you to use validations without active model in rails 2.3.x
class BaseRecord
attr_accessor :values
def self.fields(fields)
BaseRecord.field_list = fields
end
def self.field_list=(field_list)
@field_list = field_list
end
@madpilot
madpilot / index.html
Created September 16, 2011 00:47
Client side i18n tranlation demo
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>i18n Demo</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/madpilot/jquery-i18n/master/jquery.i18n.js"></script>
<script type="text/javascript">
var languages = {
en: {
@madpilot
madpilot / gist:1407763
Created November 30, 2011 02:49
Replay an AJAX request if the first one failed due to an authentication error
jQuery.ajaxSetup(
statusCode: {
403: function() {
// This calls a backbone view that renders a login window, then
// calls the success function one the user has been authenticated
// The call back simply re-runs $.ajax using the current context object,
// which conveniently is a hash of the original AJAX request params.
var sessionLogin = new SessionsLoginView();
var context = this;
@madpilot
madpilot / checkboxslider.css
Created December 6, 2011 06:46
CSS to create a CSS3 only slider.
input[type=checkbox] {
border: 1px solid #686868;
height: 27px;
width: 79px;
-webkit-appearance: none;
-webkit-border-radius: 13px;
background-image: url(/blog/wp-content/uploads/2011/12/checkbox-background.png);
background-position: -52px 0;
background-repeat: no-repeat;
-webkit-animation-timing-function: ease-in-out;
GeoIP.new(File.join(Rails.root, 'db', 'localization', 'GeoLiteCity.dat')).city(request.remote_ip)
=> ["203.59.95.220", "203.59.95.220", "AU", "AUS", "Australia", "OC", "08", "Perth", "", -31.9333, 115.8333]