Skip to content

Instantly share code, notes, and snippets.

View danott's full-sized avatar
📈
Chart with upward trend

Dan Ott danott

📈
Chart with upward trend
View GitHub Profile
@danott
danott / randomize_digits.rb
Created March 26, 2015 16:31
Randomize the digits, uniq for each line of each run.
#!/usr/bin/env ruby
s = gets
while s
map_old_to_new = {}
available_digits = %w(0 1 2 3 4 5 6 7 8 9)
(0..9).each do |old|
new = available_digits.sample
available_digits -= [new]
map_old_to_new["#{old}"] = new
@danott
danott / seo.scss
Created March 7, 2015 06:13
Creating a WordPress theme that nudges authors towards SEO with CSS. Good idea or bad idea?
body.admin-bar .post-content h1 {
border: 2px solid red;
&:before {
content: "Using H1 tags in post content is bad for SEO. Change to an H2 tag. (You're only seeing this because you're signed in as an admin. Your visitors won't see this warning)";
background-color: red;
color: white;
font-size: 1rem;
line-height: 1;
padding: 1em;
@danott
danott / immutable_attributes.rb
Last active August 29, 2015 14:08
Rails' attr_readonly prevents updates from being written to the database, but does not prevent them from being changed in memory. If you have derived values from what's in memory, this can be problematic. For rolling out a new feature, I want to know if any of our code paths are trying to update the field. I don't want it to fail silently and be…
# Creating a whole new concern, introducing the `attr_immutable` macro
module ImmutableAttributes
class ImmutableAttributeError < StandardError; end
extend ActiveSupport::Concern
included do
class_attribute :_attr_immutable, instance_accessor: false
self._attr_immutable = []
end
@danott
danott / fat_arrows.coffee
Created October 22, 2014 17:05
Fat arrows
class MyThing
value: "My thing's value"
skinny: ->
console.log @value
fat: =>
console.log @value
otherThing =
value: "Other's value"
@danott
danott / README.md
Last active August 29, 2015 14:07 — forked from meesterdude/README.md

Emoji Spec

results Tired of the same, dull rspec output? liven it up with some emoji!

Below are the sets presently available, and their corresponding id. if you don't set an ID, one will be randomly chosen every run. Emoji icons may not render in certain terminals.

(pass, fail, pending)

emoji

@danott
danott / env.coffee
Last active August 29, 2015 14:07
Set an environment from html meta tags.
# Set an environment from html meta tags.
#
# Usage:
#
# <meta name="ENV.station" content="swan" />
# <meta name="ENV.port" content="2342" />
#
# The above meta tags would yield the following object:
#
# ENV = {'station': 'swan', 'port': 2342}
@danott
danott / sum.rb
Last active August 29, 2015 14:04
ActiveSupport sum
# In rails console.
dumb = Struct.new(:field_with_name)
[dumb.new(1), dumb.new(2), dumb.new(3)].sum(&:field_with_name)
@danott
danott / github_labels.js
Created August 5, 2014 19:52
GitHub Labels
// ==UserScript==
// @name GitHub Labels
// @namespace http://danott.co/
// @version 0.1
// @description Automatically add and remove "+1", "+2", and "NOT READY!" labels bast on comment contents. Included on all of github because pushState.
// @include https://github.com/*
// @copyright 2014+, @danott
// ==/UserScript==
var getLabelName = function() {
@danott
danott / view.coffee
Created July 24, 2014 23:38
How to propogate events up the batman view tree, similar to EventBinding
class App.BehavesLikeEventBindingView extends Batman.View
fireOnSelfAndNearestAncestor: (event, args...) ->
@[event]?.apply(@, args)
if target = @superview?.targetForKeypath(event)
target[event].apply(target, args)
# required on jsbin
Batman.config.usePushState = false
simpleStore = new Batman.Set()
simpleStore.add new Batman.Object({name: "Red"})
simpleStore.add new Batman.Object({name: "Green"})
simpleStore.add new Batman.Object({name: "Blue"})
class App extends Batman.App
@root "colors#index"