Skip to content

Instantly share code, notes, and snippets.

View BFalkner's full-sized avatar

Brennan Falkner BFalkner

View GitHub Profile
def integer?
ActivePattern::Pattern.build do |value, pass|
if value.is_a? Integer
value
elsif value.is_a? String
/\A[-+]?\d+\z/ === value ? value.to_i : pass
else
pass
end
end
@BFalkner
BFalkner / example.emblem
Last active December 31, 2015 00:39
Ember and Bootstrap Popup
popup-link value="Click Me" placement="bottom"
| Hey there.
a click="hide target='popover'" href="#" Close
var // Static reference to slice
sliceDeferred = [].slice;
/* $.when that waits for everything to return before failing */
function whenAll( firstParam ) {
var args = sliceDeferred.call( arguments, 0 ),
i = 0,
length = args.length,
pValues = new Array( length ),
count = length,
> _.split([1, 2, 3, 4], function(item) { return [item, item*2]; })
[1, 2, 2, 4, 3, 6, 4, 8]
@BFalkner
BFalkner / Salesforce.js
Created February 24, 2012 19:14
JavaScript has bad functional/monadic syntax.
{
_ajax: function(path, method, data, retry) {
var self = this;
var response = self._session.pipe(function(session) {
return $.ajax({
type: method || "GET",
url: SalesForceSettings.proxyUrl,
cache: false,
processData: false,
<!DOCTYPE html>
<html>
<head>
<title>Template Test</title>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0.beta2/handlebars.min.js"></script>
<script type="text/javascript">
$(function() {
$("script[type='text/x-handlebars-template']").each(function(i, el) {
var source = $(el).data("source");
@BFalkner
BFalkner / baton.cs
Created January 17, 2012 04:00
An awful bug. Connect throws if no Wiimote is present.
class Baton : IBaton {
private static Wiimote wiimote;
public Baton() {
if (wiimote == null) {
wiimote = new Wiimote();
wiimote.Connect();
wiimote.SetReportType(InputReport.IRAccel, true);
wiimote.SetLEDs(false, false, false, false);
}
private static string EnumOptions<T>()
{
if (!typeof(T).IsEnum)
return string.Empty;
return Enum.GetNames(typeof (T))
.Select(s => string.Format("\'{0}\'", s))
.Aggregate((lhs, rhs) => string.Format("{0}, {1}", lhs, rhs));
}
private static readonly MediaTypeCollection mediaTypes = ((MediaTypesConfigSection)ConfigurationManager.GetSection("typeSection")).MediaTypes;
public static ActionResult With(this Controller controller, params Func<object, ActionResult>[] responses)
{
string format = controller.ControllerContext.RouteData.Values["format"] as string ?? "html";
var match = responses.First(
r => Lookup(r.Method.GetParameters()[0].Name, format));
MediaType type = mediaTypes[match.Method.GetParameters()[0].Name];
if (type != null)
controller.Response.ContentType = type.Name;