Skip to content

Instantly share code, notes, and snippets.

View ghiculescu's full-sized avatar

Alex Ghiculescu ghiculescu

View GitHub Profile
require 'English'
namespace :db do # rubocop:disable Metrics/BlockLength
task :prevent_disparate_pg_dump_versions => :environment do
allowed_pg_dump_version = '9.6.10'.freeze
`pg_dump --version`
pg_dump_exit_status = $CHILD_STATUS.exitstatus
locally_installed_version = `pg_dump --version`.chomp[/(\d.*)/,1] rescue nil
@ghiculescu
ghiculescu / translatable.rb
Created March 23, 2018 04:03
moment.js locale whitelist
def moment_js_locale
# to generate this list, go to https://cdnjs.com/libraries/moment.js
# and run this in the console:
# $('.library-url').map((index, cell) => "'" + $(cell).text().replace("https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.21.0/locale/", "").replace(".js", "") + "'").get().join(", ")
valid_moment_js_locales = Set.new(['af', 'ar-dz', 'ar-kw', 'ar-ly', 'ar-ma', 'ar-sa', 'ar-tn', 'ar', 'az', 'be', 'bg', 'bm', 'bn', 'bo', 'br', 'bs', 'ca', 'cs', 'cv', 'cy', 'da', 'de-at', 'de-ch', 'de', 'dv', 'el', 'en-au', 'en-ca', 'en-gb', 'en-ie', 'en-il', 'en-nz', 'eo', 'es-do', 'es-us', 'es', 'et', 'eu', 'fa', 'fi', 'fo', 'fr-ca', 'fr-ch', 'fr', 'fy', 'gd', 'gl', 'gom-latn', 'gu', 'he', 'hi', 'hr', 'hu', 'hy-am', 'id', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'km', 'kn', 'ko', 'ky', 'lb', 'lo', 'lt', 'lv', 'me', 'mi', 'mk', 'ml', 'mr', 'ms-my', 'ms', 'mt', 'my', 'nb', 'ne', 'nl-be', 'nl', 'nn', 'pa-in', 'pl', 'pt-br', 'pt', 'ro', 'ru', 'sd', 'se', 'si', 'sk', 'sl', 'sq', 'sr-cyrl', 'sr', 'ss'
@ghiculescu
ghiculescu / Gemfile
Last active November 1, 2017 23:32
SMS you a reminder to shave when you clock in to work
source 'https://rubygems.org'
gem 'sinatra'
gem 'aws-sdk', '~> 3'
gem 'httparty'
gem 'twilio-ruby'
@ghiculescu
ghiculescu / tooltipable.rb
Created June 3, 2017 03:55
If you say `placeholder: true` on a form element, Rails gets it from i18n. Do the same for `tooltip: true`
# based on https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/tags/placeholderable.rb
# config/initializers/tooltipable.rb
module ActionView
module Helpers
module Tags # :nodoc:
module Tooltipable # :nodoc:
def initialize(*)
super
translations:
- file: "app/assets/javascripts/i18nautogen/i18n-%{locale}.js"
only: ['*.js']
@ghiculescu
ghiculescu / translation_helper.rb
Created June 3, 2017 03:49
Monkey patch ActionView's TranslationHelper to add a custom prefix for keys accessed via lazy lookup (http://guides.rubyonrails.org/i18n.html#looking-up-translations). Use this if you don't want a top level i18n key for each controller in your app - instead all keys sit under a "views" parent (and presumably you'd have other top level keys for o…
# config/initializers/translation_helper.rb
module ActionView
# = Action View Translation Helpers
module Helpers
module TranslationHelper
private
def scope_key_by_partial_with_views_prefix(key)
if key.is_a?(String) && key.first == "."
key = scope_key_by_partial_without_views_prefix(key)
"views.#{key}"
# i wish i did this in JS
require 'sinatra'
require 'fileutils'
require 'json'
require 'date'
require 'time'
require 'byebug'
get "/devices" do
Calculator = {}
function Calculator:new (o, input) -- the "account" example at http://www.lua.org/cgi-bin/demo made me think that you could just make classes, didn't realise the importance of all this boilerplate
o = o or {name=name}
setmetatable(o, self)
self.__index = self
self.input = input
self.calculation = "(%d+) ?([+-/*]) ?(%d+)" -- not sure if i'm a fan of lua not supporting all regex features - http://lua-users.org/wiki/PatternsTutorial - but i suspect the benefits will be obvious after more digging
++[[]][+[]]+[]+[]+!+[]+"luv"
my_set = JillSet.new
my_set.insert("alex") # returns true
my_set.insert("jill") # returns true
my_set.has?("jill") # returns true
my_set.has?("Jill") # returns false
my_set.items # returns ["alex", "jill"]