Skip to content

Instantly share code, notes, and snippets.

View aaronmcadam's full-sized avatar
🎉
Having fun!

Aaron McAdam aaronmcadam

🎉
Having fun!
View GitHub Profile
// Brightness math based on:
// http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
$red-magic-number: 241;
$green-magic-number: 691;
$blue-magic-number: 68;
$brightness-divisor: $red-magic-number + $green-magic-number + $blue-magic-number;
@function brightness($color) {
// Extract color components
@ngauthier
ngauthier / scraping.rb
Last active March 1, 2017 13:29
Scraping the Web with Ruby Code
#!/usr/bin/env ruby
# From: http://ngauthier.com/2014/06/scraping-the-web-with-ruby.html
require 'capybara'
require 'capybara/poltergeist'
require 'csv'
require 'gdbm'
class NickBot
include Capybara::DSL
@scottjehl
scottjehl / noncritcss.md
Last active August 12, 2023 16:57
Comparing two ways to load non-critical CSS

I wanted to figure out the fastest way to load non-critical CSS so that the impact on initial page drawing is minimal.

TL;DR: Here's the solution I ended up with: https://github.com/filamentgroup/loadCSS/


For async JavaScript file requests, we have the async attribute to make this easy, but CSS file requests have no similar standard mechanism (at least, none that will still apply the CSS after loading - here are some async CSS loading conditions that do apply when CSS is inapplicable to media: https://gist.github.com/igrigorik/2935269#file-notes-md ).

Seems there are a couple ways to load and apply a CSS file in a non-blocking manner:

@staltz
staltz / introrx.md
Last active May 15, 2025 10:37
The introduction to Reactive Programming you've been missing
@henrik
henrik / application_controller.rb
Last active December 19, 2017 11:39
Convenient `locals` renderer for Rails. Don't use ivars if you can help it. http://thepugautomatic.com/2013/05/locals/
class ApplicationController < ActionController::Base
# stuff
private
# These groups are equivalent:
#
# render action: :new, locals: { item: x }
# render :new, locals: { item: x }
@aaronmcadam
aaronmcadam / hover_and_active_style.scss
Last active August 29, 2015 14:03
Adding hover and active styles with pseudo-elements.
&:hover {
position: relative;
&:before {
content: " ";
height: 24px;
width: 24px;
left: 0;
top: 0;
position: absolute;
# From http://railscasts.com/episodes/287-presenters-from-scratch?view=comments
# I added spec/support/presenters.rb file and I require it from spec_helper.rb:
RSpec.configure do |config|
config.include ActionView::TestCase::Behavior, example_group: {file_path: %r{spec/presenters}}
config.include RSpec::Rails::Matchers::RenderTemplate, example_group: {file_path: %r{spec/presenters}}
end
# Example:
presenter.method.should render_template('blah/_blah')
@Killavus
Killavus / ugly_code_refactoring.coffee
Last active March 14, 2022 17:52
Example of possible refactoring of badly written code - loading photos and making it grayed after click
Photos = {}
class Photos.App
constructor: ->
@gui = new Photos.Gui($("#photos-list"))
@backend = new Photos.Backend()
start: =>
@backend.fetchPhotos()
.done(
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['backbone.marionette', 'backbone.radio', 'underscore'], factory);
} else if (typeof exports !== 'undefined') {
module.exports = factory(require('backbone.marionette'), require('backbone.radio'), require('underscore'));
} else {
factory(root.Backbone.Marionette, root.Backbone.Radio, root._);
}
}(this, function(Marionette, Radio, _) {
'use strict';
@patmaddox
patmaddox / authorized_controller.rb
Created August 13, 2014 04:20
RubySteps 012 - Rails - Mini frameworks snippet
module AuthorizedController
# ... full code in the paid lesson
def show
resource = resource_by_id
if resource.viewable_by?(current_user)
render json: resource
else
render text: 'Unauthorized', status: :unauthorized