Skip to content

Instantly share code, notes, and snippets.

View dperrymorrow's full-sized avatar
💭
🍕

David Morrow dperrymorrow

💭
🍕
View GitHub Profile
@belsrc
belsrc / gist:672b75d1f89a9a5c192c
Last active April 15, 2023 15:13
Simple Vue.js filters that I usually need
/**
* Changes value to past tense.
* Simple filter does not support irregular verbs such as eat-ate, fly-flew, etc.
* http://jsfiddle.net/bryan_k/0xczme2r/
*
* @param {String} value The value string.
*/
Vue.filter('past-tense', function(value) {
// Slightly follows http://www.oxforddictionaries.com/us/words/verb-tenses-adding-ed-and-ing
var vowels = ['a', 'e', 'i', 'o', 'u'];
@dperrymorrow
dperrymorrow / inheritance.js
Last active December 20, 2015 17:09
javascript inheritance
function Animal (name) {
console.log("Animal constructor is called " + name);
}
Animal.prototype.sleep = function () {
console.log(this.name + ' is sleeping');
};
// extending the parent classe
@mperham
mperham / yolo.rb
Created July 12, 2013 17:15
Have 100s of models and thousands of tests? Prefer simplicity over security when upgrading to Rails4? YOLO!
class ActiveRecord::Base
class << self
def inherited_yolo(klass)
old_inherited(klass)
klass.attr_accessible(*klass.column_names.map(&:to_sym)) unless klass.abstract_class?
end
alias_method :old_inherited, :inherited
alias_method :inherited, :inherited_yolo
end
end
@madrobby
madrobby / date.rb
Created February 15, 2013 17:37
`Date.parse` with some extra leeway to handle user input errors. Handles things like `2013-02-31` (parses it as `2013-02-29`) and handles things in general like users would expect.
module Freckle
module Date
class << self
def parse(string)
raw = string.to_s.strip
return nil if raw.empty?
begin
# reverse order if we encounter "European" formatting
@jayj
jayj / flexbox.less
Last active June 23, 2024 01:14
CSS3 Flexbox - LESS Mixins
// --------------------------------------------------
// Flexbox LESS mixins
// The spec: http://www.w3.org/TR/css3-flexbox
// --------------------------------------------------
// Flexbox display
// flex or inline-flex
.flex-display(@display: flex) {
display: ~"-webkit-@{display}";
display: ~"-ms-@{display}box"; // IE10 uses -ms-flexbox
window.NR = window.NR || {};
window.NR.myModule = (function () {
"use strict";
function initialize() {
// your initialization code here
}
function anotherMethod() {
// its function body here
@karlhorky
karlhorky / grayscale-disable.css
Created August 26, 2012 12:17
Cross-Browser CSS Grayscale
img.grayscale.disabled {
filter: url("data:image/svg+xml;utf8,&lt;svg xmlns=\'http://www.w3.org/2000/svg\'&gt;&lt;filter id=\'grayscale\'&gt;&lt;feColorMatrix type=\'matrix\' values=\'1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 1 0\'/&gt;&lt;/filter&gt;&lt;/svg&gt;#grayscale");
-webkit-filter: grayscale(0%);
}
@andflett
andflett / bookmarks.rake
Created May 8, 2012 22:26
Rake task to import bookmarks and tags (parent folders) from Netscape Bookmark formatted files.
require 'nokogiri'
require 'open-uri'
namespace :bookmarks do
desc '-- Import bookmarks in Netscape Bookmark format'
task :import => :environment do
doc = Nokogiri::HTML(open(File.join(Rails.root, "lib/dump/bookmarks_5_8_12.html")))
# Ensure we're dealing with the correct format
@janogarcia
janogarcia / haml_partials.haml
Created May 3, 2012 11:28
HAML Partials wihout Rails (useful for LiveReload)
/ A simplistic way of loading and rendering HAML partials (header.haml, footer.haml, nav.haml... you name it) without Rails
/ Useful when using tools like LiveReload http://livereload.com/
/ but don't want to configure a web server just to use PHP include/require constructs (discussion http://help.livereload.com/discussions/questions/22-haml-partials)
/ It could be improved/simplified using a helper http://stackoverflow.com/questions/5436769/partial-haml-templating-in-ruby-without-rails/5436973#5436973
/ Check out the Jade version https://gist.github.com/2593727
%html
%body
%header
= Haml::Engine.new(File.read('/path/to/your/partial.haml')).render
@foca
foca / singleton.coffee
Created January 18, 2012 22:39
Small implementation of Singletons for Backbone
# Public: generates a mixable singleton implementation dependent on a model key.
# Once you mix it into a model, your model gains an .instance method that will
# generate an object and cache it. Further calls to the .instance methods will
# return the same object.
#
# key - The name of the attribute we use to index instances. Defaults to "id".
#
# Example
#
# # Called without arguments uses the "id" as key.