Skip to content

Instantly share code, notes, and snippets.

enum DateStride {
case year(Int)
case month(Int)
case day(Int)
var component: Calendar.Component {
switch self {
case .year(_):
return .year
@joshwlewis
joshwlewis / scss_format_validator.rb
Created November 19, 2012 20:09
Rails validation for scss (or sass)
# app/validators/scss_format_validator.rb
class ScssFormatValidator < ActiveModel::EachValidator
def validate_each(object, attribute, value)
begin
# Attempt to parse SCSS
Sass::Engine.new(value, syntax: :scss).render
rescue Exception => e
# Add error if parsing fails
object.errors.add(attribute, :invalid_scss, error: e.inspect)
end
@spohlenz
spohlenz / devise.rb
Created October 13, 2012 01:14
Devise with MongoModel
# Replace relevant section in config/initializers/devise.rb
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require 'devise/orm/mongomodel'
@williammalo
williammalo / README.md
Last active October 7, 2015 01:48 — forked from 140bytes/LICENSE.txt
masonry under 140bytes

A minimalist masonry function

mason(containerElement,brickElement,brickWidth,brickHeight)

Only works with one size of brick.

The only advantage of using this over using inline-block elements is that you can use css transitions.

@philfreo
philfreo / model.js
Last active October 6, 2015 21:37
Backbone Model mutators / computed properties
var Model = Backbone.Model.extend({
/**
* Override main attribute getter to handle mutators.
* Looks for an object on the model called 'mutators', keyed by key name,
* with values of either the getter function or an object like:
* { get: function() {}, set: function() {} }
*/
get: function(attr) {
var val,
@remy
remy / $.js
Last active October 4, 2015 04:57
Tiny selector and event system
$ = function (document) {
var element = Element.prototype,
nodeList = NodeList.prototype,
foreach = [].forEach;
element.on = function () {
element.addEventListener.apply(this, arguments);
return this;
};
@ordinaryzelig
ordinaryzelig / minitest_spec_expectations.md
Last active December 10, 2022 13:34
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@tsaniel
tsaniel / LICENSE.txt
Created March 12, 2012 08:56 — forked from 140bytes/LICENSE.txt
Romanize
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@madrobby
madrobby / i18n.coffee
Created November 14, 2011 15:45
Backbone i18n with CoffeeScript
# before this file is loaded, a locale should be set:
#
# In a browser environment, you can use:
# ```<script>__locale='en';</script>```
#
# In a server environment (specifically node.js):
# ```global.__locale = 'en';```
# normalize in-app locale string to "en" or "de-AT"
parts = @__locale.split('-')
@kylefox
kylefox / liquid-mode.js
Created November 11, 2011 00:02
Liquid syntax highlighting for CodeMirror.
/*
This overlay provides a 'liquid' mode to the excellent CodeMirror editor (http://codemirror.net/).
Add something like this to your CSS:
.cm-liquid-tag {
color: #32273f;
background: #ead9ff;
}
.cm-liquid-variable {