Skip to content

Instantly share code, notes, and snippets.

View madpilot's full-sized avatar

Myles Eftos madpilot

View GitHub Profile
@madpilot
madpilot / icons.rake
Created April 17, 2015 01:53
Rake task to generate font icons from a folder full of SVGs
require 'fileutils'
RANGE = (0xe000...0xf8ff);
def map_fonts(src, map_file)
map = {
'meta' => {
'author' => "Redbubble"
},
'font' => {
@madpilot
madpilot / xio.io
Last active August 29, 2015 14:22
#!/bin/bash
getMyIP() {
local _ip _myip _line _nl=$'\n'
while IFS=$': \t' read -a _line ;do
[ -z "${_line%inet}" ] &&
_ip=${_line[${#_line[1]}>4?1:2]} &&
[ "${_ip#127.0.0.1}" ] && _myip=$_ip
done< <(LANG=C /sbin/ifconfig)
printf ${1+-v} $1 "%s${_nl:0:$[${#1}>0?0:1]}" $_myip
@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;