Skip to content

Instantly share code, notes, and snippets.

View freshtonic's full-sized avatar
🎯

James Sadler freshtonic

🎯
  • Sydney, Australia
View GitHub Profile
@freshtonic
freshtonic / gist:6579025
Created September 16, 2013 10:33
DRYed up version of the CSS transformations.
# The final CSS files
$(DIST)/stylesheets/%.css: $(SASS)/%.scss
$(BIN)/node-sass $< $@
$(BIN)/autoprefixer --browsers $(AUTOPREFIXER_BROWSERS) $@
@freshtonic
freshtonic / gist:6373145
Last active December 21, 2015 22:09
Failing to install Yeoman (with a clean node installation).
npm http GET https://registry.npmjs.org/yo
npm http 200 https://registry.npmjs.org/yo
npm http GET https://registry.npmjs.org/yo/-/yo-1.0.4.tgz
npm http 200 https://registry.npmjs.org/yo/-/yo-1.0.4.tgz
npm http GET https://registry.npmjs.org/sudo-block
npm http GET https://registry.npmjs.org/open/0.0.4
npm http GET https://registry.npmjs.org/yeoman-generator
npm http GET https://registry.npmjs.org/chalk
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/lodash
@freshtonic
freshtonic / gist:5916602
Created July 3, 2013 09:23
When Pow is failing you, try making a .powrc like this:
export rvm_path=$HOME/.rvm
if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".ruby-version" ]; then
source "$rvm_path/scripts/rvm"
rvm use `cat .ruby-version`
fi
@freshtonic
freshtonic / gist:5895391
Created June 30, 2013 14:37
A list of HTTP clients we tried to use for http://lector.io's feed handing

All on Ruby 1.9.3p395 from Sidekiq workers on Heroku unless otherwise stated.

  • Feedzirra

    This uses curb to fetch feeds, which worked fine locally but under load would eventually segfault. This happened on our own roll-your-own VPS and on Heroku.

  • Net::HTTP (this was Ruby 2.0pxxx)

After a long run downloading feeds we would start to see HTTP requests taking minutes with a 30 second timeout. Eventually all of our workers in Sidekiq would be stalled. I have read conflicting information about whether timeout.rb is to be trusted in MRI 1.9+, but it seems that in our case it shouldn't have been.

def self.create_or_update_from_extraction_result(user, extraction_result, bookmarklet_params)
ActiveRecord::Base.transaction do
article = Article.for_source_url(bookmarklet_params['source_url']) || Article.new
if extraction_result.success?
article.body = extraction_result.content
else
article.body = ""
end
article.title = extraction_result.title || "[missing title]"
article.source_url = bookmarklet_params['source_url']
@freshtonic
freshtonic / description.md
Last active December 17, 2015 10:39
The Rails Asset Pipeline & Angular JS partials.

My Angular.js partials live in public/partials.

In development mode I want them served from there, in production I want to have an Angular.js module called templates which simply popuates the template cache for me.

This isn't just about performance in production: it's making sure the partials are embedded in the assets which forces the partial's lifetime to be the same as the assets with no other caching worries when we redeploy the app.

@freshtonic
freshtonic / compiles-to-this.coffee
Created May 10, 2013 05:16
Remember to use: x = if foo then bar else baz in coffeescript instead of x = foo ? bar : bar
var _ref;
if (this.searchParams.featured) {
if ((_ref = (this.searchParams.featured || '').toLowerCase() === 'yes') != null) {
_ref;
} else {
({
'yes': 'no'
});
};
@freshtonic
freshtonic / gist:5433032
Last active December 16, 2015 12:09
Bound methods as blocks in Ruby
class WhiteList
def initialize(names)
@names = names
end
def whitelisted?(name)
@names.include? name
end
end
@freshtonic
freshtonic / gist:5381678
Created April 14, 2013 06:29
iTerm2 config
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AdjustWindowForFontSizeChange</key>
<true/>
<key>AllowClipboardAccess</key>
<false/>
<key>AnimateDimming</key>
<false/>
# Set up the application
app = angular.module('ratingRampage', [])
# This is an injectable property
app.value 'Authentication', {}
# Add a directive so that if we see a csrf-token attribute, this gets set
app.directive 'csrfToken', (Authentication) ->
(scope, element, attrs) ->
Authentication.csrf_token = attrs.csrfToken