Skip to content

Instantly share code, notes, and snippets.

Jacob Burenstam buren

Block or report user

Report or block buren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@buren
buren / i18n_generator.rb
Created Jul 10, 2015
Generate translations for activerecord models and columns
View i18n_generator.rb
class I18nGenerator
attr_reader :models, :lang_code
def initialize(lang_code: :en)
ignored_tables = %w(schema_migrations)
@models = ActiveRecord::Base.connection.tables - ignored_tables
@models.map! { |model| model.singularize.camelize.constantize }
@lang_code = lang_code.to_s
end
@buren
buren / active_table_view.rb
Created Jul 11, 2015
ActiveTableView: Render "tables structure" for ActiveRecord objects
View active_table_view.rb
class ActiveTableView
def initialize(opts)
@col_names = opts.fetch(:cols)
@records = opts.fetch(:records)
@model_name = rows.table_name.singularize
end
def headers
@col_names.map { |name| t_col(name) }
end
@buren
buren / repeater.js
Created Aug 23, 2015
Dead simple JS repeater
View repeater.js
/*
* Repeater.js
*/
(function (window) {
'use strict';
function Repeater(callback, timeout) {
var self = this;
View slides-presenter.rb
DEADLINE = Time.new(2015, 9, 21, 13, 0, 0).freeze
module Audience;end
module Audience::Talk;end
String.class_eval { define_method(:last?) { false } }
NilClass.class_eval { define_method(:last?) { true } }
define_method(:wait) { puts 'Still not ready..';sleep 3 }
define_method(:any_questions?) { puts 'Any questions?' }
define_method(:feedback) { puts 'Feedback?' }
class Audience::Presenter < Struct.new(:name)
define_method(:ready?) { Time.now >= DEADLINE }
@buren
buren / minispec.js
Last active Oct 19, 2015
Minimal JS test DSL
View minispec.js
function describe(label, testFunction) {
return new test(label, testFunction);
}
function test(label, testFunction) {
var self = this;
self.testLabel = label;
self.itLabel;
var label = function() { return self.testLabel + ' ' + self.itLabel; };
var passed = function() { console.log(label(), true); };
@buren
buren / minispec.rb
Created Oct 19, 2015
rspec-like specs, using ruby procs
View minispec.rb
def describe(label)
fails = []
it = ->(it_label, &block) {
assert = ->(expected, result) {
passed = ->() { print '.' }
failed = ->() {
print 'F'
fails << "#{label} #{it_label}, expected '#{expected}', but was '#{result}'."
}
expected == result ? passed.() : failed.()
View keybase.md

Keybase proof

I hereby claim:

  • I am buren on github.
  • I am buren (https://keybase.io/buren) on keybase.
  • I have a public key whose fingerprint is A7ED 5FE6 79AA 414B 405F E637 CCC5 6E36 265C 2FB3

To claim this, I am signing this object:

@buren
buren / rails_web_console_param.rb
Last active Feb 13, 2016
Attach a rails web console to any page by adding ?web_console=
View rails_web_console_param.rb
# config/initializers/web_console.rb
WebConsoleBeforeAction = ->(controller) do
controller.console if controller.params[:web_console]
end
ApplicationController.before_action(WebConsoleBeforeAction) if defined?(WebConsole) && Rails.env.development?
# NOTE:
# For security reasons only do this in development.
@buren
buren / language_wikimedia.js
Created Mar 23, 2016
and convert languages from Wikimedia to CSV
View language_wikimedia.js
// Extract and convert languages @ below URL to CSV
// https://meta.wikimedia.org/wiki/Template:List_of_language_names_ordered_by_code
var langCode = [];
$('.wikitable tbody tr td:nth-child(1)').each(function(){
langCode.push($(this).text());
});
var enName = [];
$('.wikitable tbody tr td:nth-child(2)').each(function(){
@buren
buren / a-jsonapi-datastore.js
Last active Mar 29, 2016
Example jsonapi-datastore usage
View a-jsonapi-datastore.js
var fs = require('fs')
var JsonApiDataStore = require('jsonapi-datastore').JsonApiDataStore;
function readExampleToObject(fileName, callback) {
fs.readFile(fileName, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
return callback(JSON.parse(data));
});
You can’t perform that action at this time.