Skip to content

Instantly share code, notes, and snippets.

Avatar

Myles Eftos madpilot

View GitHub Profile
@madpilot
madpilot / icons.rake
Created Apr 17, 2015
Rake task to generate font icons from a folder full of SVGs
View icons.rake
require 'fileutils'
RANGE = (0xe000...0xf8ff);
def map_fonts(src, map_file)
map = {
'meta' => {
'author' => "Redbubble"
},
'font' => {
View xio.io
#!/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 Feb 22, 2010
Some sample test setup files
View blueprints.rb
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:
View gist:333732
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
View gist:480932
// 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...
View gist:519205
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')
View how_to_teach_method_missing.rb
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 Dec 1, 2010
Base Record - allows you to use validations without active model in rails 2.3.x
View base_record.rb
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 Sep 16, 2011
Client side i18n tranlation demo
View index.html
<!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 Nov 30, 2011
Replay an AJAX request if the first one failed due to an authentication error
View gist:1407763
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;