Skip to content

Instantly share code, notes, and snippets.

View lukes's full-sized avatar

Luke Duncalfe lukes

View GitHub Profile
{
"name":"Afghanistan", // english name
"country-code":"004", // unique numeric code
"alpha-2":"AF", // unique 2-character code
"alpha-3":"AFG", // unique 3-character code
"sub-region-code":"034", // geographical sub-region code
"region-code":"142", // macro geographical (continental) region code
"iso 3166-2":"ISO 3166-2:AF" // ISO 3166-2 code for principle subdivision
}
@lukes
lukes / find_invalid_records_in_rails.rake
Last active July 18, 2022 23:43
Find invalid records in Rails.
namespace :db do
desc "Outputs any invalid data records"
task :invalid_records => :environment do
puts "\n** Testing record validating in #{Rails.env.capitalize} environment**\n"
ActiveRecord::Base.send(:subclasses).each do |model|
puts "#{model} records (#{model.count})"
next if model.count == 0
invalid = model.all.reject(&:valid?)
if invalid.size.zero?

I'm trying to run the rails test suite but I keep getting this error:

$ bundle exec rake postgresql:build_databases
createdb: database creation failed: ERROR:  encoding UTF8 does not match locale en_US
DETAIL:  The chosen LC_CTYPE setting requires encoding LATIN1.
createdb: database creation failed: ERROR:  encoding UTF8 does not match locale en_US
DETAIL:  The chosen LC_CTYPE setting requires encoding LATIN1.
@lukes
lukes / application-controller.js.coffee
Created August 6, 2014 23:13
Simplest Ember 5 Star Rating component
App.ApplicationController = Ember.ObjectController.extent
starRatingValue: Ember.computed(->
"3"
)
@lukes
lukes / initializers-current-user.js
Last active August 29, 2015 14:07
Using Ember.ObjectProxy for currentUser
// (Rename to current-user.js and place in /initializers)
// Ember now complains that you can't type inject a controller into a controller
// so use an Ember.ObjectProxy for currentUser instead.
//
// Ember.ObjectProxy allows you to set a content value, and will delegate
// all getters and setters to its content.
import DS from "ember-data";
import CurrentUser from "../models/current-user";
@lukes
lukes / controllers-application.js
Created October 6, 2014 22:17
Making currentPath available to all controllers
import Ember from 'ember';
export default Ember.ObjectController.extend({
currentPathDidChange: function() {
this.set('path.content', this.get('currentPath'));
}.observes('currentPath')
});
@lukes
lukes / adapters-open-weather-map.js
Last active August 29, 2015 14:07
Ember OpenWeatherMapAdapter
import Ember from 'ember';
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
headers: {
"x-api-key": "[Your OpenWeatherMap API Key]"
},
findQuery: function(store, type, query) {
@lukes
lukes / initializers-connection-status.js
Last active March 10, 2017 08:43
Ember online/offline connection status service
// (Rename to connection-status and add to /initializers)
export default {
name: 'connectionStatus',
initialize: function(container, app) {
app.inject('route', 'connectionStatus', 'service:connectionStatus');
app.inject('controller', 'connectionStatus', 'service:connectionStatus');
}
};
@lukes
lukes / Brocfile.js
Created December 7, 2014 20:38
Enable fingerprinting for all environments except development
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var app = new EmberApp({
// Custom settings for broccoli-assets-rev
// See http://www.ember-cli.com/#asset-compilation
fingerprint: {
enabled: true
}
});
@lukes
lukes / rant.js
Created December 18, 2014 21:38
<rant> to actual rant
// <rant> to actual rant
// (requires modern browsers)
var rants = document.getElementsByTagName('rant');
for (i=0;i<rants.length;i++) {
var rant = new SpeechSynthesisUtterance(rants[i].innerHTML);
window.speechSynthesis.speak(rant);
}