Skip to content

Instantly share code, notes, and snippets.

View robhurring's full-sized avatar
🍻
cheers

Rob Hurring robhurring

🍻
cheers
View GitHub Profile
@robhurring
robhurring / datepicker.js
Last active August 29, 2015 14:14
angular pikaday
/* global angular, Ladda */
(function(module, $) {
'use strict';
module.directive('datepicker', function() {
return {
link: function postLink(scope, element, attrs) {
var today = new Date();
var minYear = 1900;
var maxYear = today.getFullYear();
@robhurring
robhurring / noidea.js
Last active August 29, 2015 14:16
forMatt
var UserSelect = React.createClass({
_changed: function(event) {
var value = this.refs.box.getDOMNode().value;
this.props.onSelect(value);
},
render: function() {
var items = this.props.items.map(function(item) {
return (
<option value={item}>{item}</option>
@robhurring
robhurring / save_tracker.rb
Created April 14, 2015 21:32
RSpec ActiveRecord model save and creation reporting
# ./spec/support/save_tracker.rb
module SaveTracker
extend ActiveSupport::Concern
included do
class_attribute :_save_tracker_
self.reset_save_tracker!
end
module ClassMethods
@robhurring
robhurring / Timer.jsx
Last active August 29, 2015 14:21
Timer
class Timer extends React.Component {
constructor(props) {
super(props)
this._interval = null;
this.state = {
ticks: 0
}
}
@robhurring
robhurring / .eslintrc
Last active August 29, 2015 14:21 — forked from cletusw/.eslintrc
ESLint starter RC file (updated ECMA6 rules)
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"arrowFunctions": false, // enable arrow functions
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"classes": false, // enable classes
"defaultParams": false, // enable default function parameters
"destructuring": false, // enable destructuring
@robhurring
robhurring / update_content.js
Created July 7, 2015 13:59
AJAX content replace
(function($) {
// scan our ajax response for replaceable content blocks then update the HTML
var updateContent = function(content) {
var $contentKeyElements = $(content).filter('[data-content-key]');
$contentKeyElements.each(function() {
var node = $(this);
var key = node.attr('data-content-key');
$('[data-content-key=' + key + ']').replaceWith(node);
});
@robhurring
robhurring / any.js
Created February 18, 2009 19:31
Allow strings to number_to_currency style comma seperate in javascript
// Allow strings to number_to_currency style comma seperate
String.prototype.commafy = function () {
return this.replace(/(^|[^\w.])(\d{4,})/g, function($0, $1, $2) {
return $1 + $2.replace(/\d(?=(?:\d\d\d)+(?!\d))/g, "$&,");
});
}
// Convenience method for numbers
Number.prototype.commafy = function () {
return String(this).commafy();
@robhurring
robhurring / application.html.erb
Created March 16, 2009 13:21
Rails Metal theme switcher
# your applications main layout file (app/views/layouts/application.html.erb?)
# I put this after the normal stylesheet call, so our theme can override what we want instead of the entire stylesheet
<% if theme = request.env['rails.theme'] %>
<%= stylesheet_link_tag "themes/#{theme}", :media => :all %>
<% end %>
@robhurring
robhurring / config.ru
Created March 24, 2010 19:00
Sinatra using ActiveRecord's Query Caching ability across multiple Databases : http://proccli.com/active-record-query-caching-sinatra-multiple-databases
require 'sinatra_query_caching_demo'
run Demo
@robhurring
robhurring / diff.rb
Created March 26, 2010 20:20
Ruby Diff -- Ghetto style!
require 'tempfile'
# TODO: do some pre-comparison on a and b so we can skip creating temp files and all that jazz.
# NOTE: this is so ghetto ;)
module Diffable
def diff(b, options = {})
Diff.new(self, b, options).diff
end
end