Skip to content

Instantly share code, notes, and snippets.

View leepfrog's full-sized avatar

Andy Tran leepfrog

View GitHub Profile
@leepfrog
leepfrog / gist:3214669
Created July 31, 2012 07:51
NSDateFormatter
-(BOOL)shouldShowAMorPM {
NSDateFormatter *referenceFormatter = [[NSDateFormatter alloc] init];
[referenceFormatter setDateFormat:@"HH:m zzz"];
NSDate *refDate = [referenceFormatter dateFromString:[NSString stringWithFormat:@"18:00 %@",[[self timeZone] abbreviation]]];
NSString *testFormatStr = [self stringFromDate:refDate];
NSCharacterSet *hourMinDividers = [NSCharacterSet characterSetWithCharactersInString:@"-:."];
NSString *hour = [[testFormatStr componentsSeparatedByCharactersInSet:hourMinDividers] objectAtIndex:0];
if ([hour intValue] > 12) {
<!doctype html>
<html>
<head>
<title></title>
<script src='./jquery.js' type='text/javascript'></script>
<script src='./handlebars.js' type='text/javascript'></script>
<script src='./ember.js' type='text/javascript'></script>
<script type="text/javascript">
App = Ember.Application.create();
@leepfrog
leepfrog / gist:3534691
Created August 30, 2012 17:37
Simple mail enqueuer
#!/usr/local/bin/ruby
require 'mail'
require 'tempfile'
require 'beanstalk-client'
require "#{File.dirname(__FILE__)}/mail_env"
File.umask(0111)
# Parse the incoming message
emailfile=Tempfile.new("email")
// In this sorting function, we have three indices in our array
// a[0] - the name of the injection
// a[1] - the name of an injection that THIS injection should be before
// a[2] - the name of an injection that THIS injection should be after
// When given an array:
// [['b', 'c', null], ['a','b', null], ['d', null, 'c'], ['c', null, null], ['e', null, 'd']];
// Then the output from this array should look like:
// [['a','b', null], ['b', 'c', null], ['c', null, null], ['d', null, 'c'], ['e', null, 'd']];
#!/usr/bin/perl
while (<>) {
/(.+)\s(.+)\s(.+)\s(.+)\s(.+)$/;
$addr = $5;
$name = $1;
$1 =~ /(.+)\.(.+)\.(.+)\.(.+)\.in-addr.+/;
print $addr," 10800 IN A ", $4, ".", $3, ".", $2, ".", $1, "\n";
}
@leepfrog
leepfrog / gist:4284160
Created December 14, 2012 09:48
#EmberJS - Adding support for CSRF from Rails to your Adapter
App.Adapter = DS.RESTAdapter.extend
# Add CSRF Token from Rails to non-get requests
ajax: (url, type, hash) ->
if hash.data and type isnt "GET"
hash.data['authenticity_token'] = jQuery("meta[name='csrf-token']").attr("content")
@_super(url,type,hash)
addImages: (files) ->
formData = new FormData()
# Attach block id
formData.append "attachments[book_id]", @get('content.id')
# Loop through the FileList and render image files as thumbnails.
for file in files
# Only process image files.
if file.type.match("image.*")
@leepfrog
leepfrog / WebSocket.js.coffee
Created December 30, 2012 07:26
Android WebSockets plugin for Cordova 2.2
class WebSocket
constructor: (url) ->
cordova.exec (-> return true), (-> return false), "WebSocketPlugin", "createSocket", [url]
cordova.exec @_onerror, (->), "WebSocketPlugin", "registerCallback", ["onerror"]
cordova.exec @_onopen, (->), "WebSocketPlugin", "registerCallback", ["onopen"]
cordova.exec @_onclose, (->), "WebSocketPlugin", "registerCallback", ["onclose"]
cordova.exec @_onmessage, (->), "WebSocketPlugin", "registerCallback", ["onmessage"]
send: (message) ->
cordova.exec (-> return true), (-> return false), "WebSocketPlugin", "send", [message]
@leepfrog
leepfrog / gist:4464513
Last active December 10, 2015 16:58
Class extension to convert hamlbars to handlebars.
class File
def to_str
path
end
end
class Hamlbars::Converter
def self.process_directory(directory)
dir = Dir.open(directory)
@leepfrog
leepfrog / gist:4498789
Created January 10, 2013 02:11
A 1st draft for building Ember.ArrayPipeline / Ember.ArrayPipelinePlugin.
Ember.ArrayPipelinePlugin = Ember.Object.extend
#
# Public
#
# Define a set of properties you would like to observe on the array for
# reprocessing.
#
# If another plugin earlier in the pipeline observes the same property,
# then this plugin will wait to process until the other plugin in the pipeline