Skip to content

Instantly share code, notes, and snippets.

View GBH's full-sized avatar
🦀
🦀🦀🦀🦀🦀🦀🦀🦀🦀

Oleg GBH

🦀
🦀🦀🦀🦀🦀🦀🦀🦀🦀
View GitHub Profile
@GBH
GBH / wiki
Created January 10, 2018 21:09
{{Infobox software
| name = ComfortableMexicanSofa
| developer = Oleg Khabarov
| released = {{release date|2010|10|13}}
| latest_release_version = <!-- If you update this, remember to also update [[List of content management systems]]--> 2.0.7<ref name="comfortable_mexican_sofa_release">https://rubygems.org/gems/comfortable_mexican_sofa/versions/2.0.7</ref>
| latest_release_date = {{release date|2017|12|24}}
| status = Active
| operating_system = [[Cross-platform]]
| platform = [[Ruby on Rails]]
| genre = [[Content management system]]
# frozen_string_literal: true
gem "bundler", "< 1.16"
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
require 'yaml'
en_hash = YAML::load_file(File.expand_path('../config/locales/en.yml', File.dirname(__FILE__)))
locales = %w(en de es fr nl pt-BR zh-CN zh-TW)
def fix_locale(locale_hash, en_hash)
result_hash = locale_hash
@GBH
GBH / merger.rb
Last active March 25, 2016 14:42
#!/usr/bin/env ruby
# Small script to join and clean-up ACA gpx files.
# Setup:
# - make sure you got nokogiri installed (gem install nokogiri)
# - throw this merger.rb in some directory
# - inside that directory create input/ folder
# - copy ACA .gpx files into that folder. Generally {direction}Main files plus Services files
# Usage:
# - from terminal run ./merger.rb
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
brew update && brew upgrade postgresql
initdb /usr/local/var/postgres9.5.1 -E utf8
pg_upgrade -d /usr/local/var/postgres -D /usr/local/var/postgres9.5.1 -b /usr/local/Cellar/postgresql/9.4.2/bin/ -B /usr/local/Cellar/postgresql/9.5.1/bin/ -v
rm -rf postgres
@GBH
GBH / each_with_alpha_index.rb
Last active August 29, 2015 14:20
each_with_alpha_index
module Enumerable
# Iterate through enumerable with alpha index instead of integers
def each_with_alpha_index(index = 'a')
each do |element|
yield element, index
index.next!
end
end
end
@GBH
GBH / gist:d601b212e1e473c62e90
Created April 1, 2015 18:35
Testing for translation consistency
require_relative '../test_helper'
class I18nIntegrationTest < ActionDispatch::IntegrationTest
def collect_combined_keys(hash, ns = nil)
hash.collect do |k, v|
keys = [ ]
keys << collect_combined_keys(v, "#{ns}.#{k}") if v.is_a?(Hash)
keys << "#{ns}.#{k}"
end.flatten
vagrant@jun-group:~/player$ rails s torquebox
=> Booting TorqueBox
=> Rails 3.2.18 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
NameError: missing class or uppercase package name (`com.jungroup.player.geocoding.ZipcodeTranslator')
get_proxy_or_package_under_package at org/jruby/javasupport/JavaUtilities.java:54
method_missing at file:/home/vagrant/.rvm/rubies/jruby-1.7.8/lib/jruby.jar!/jruby/java/java_package_module_template.rb:14
(root) at /home/vagrant/player/lib/geo_code.rb:7
@GBH
GBH / gist:a0c6e7ec555881242f61
Created November 17, 2014 14:20
Ruby ancestor chain fun
module Foo
def hello
puts 'foo'
end
end
module Bar
def hello
puts 'bar'
end
@GBH
GBH / gist:9218575
Created February 25, 2014 21:47
Hash#deep_slice
class Hash
def deep_slice(*allowed_keys)
sliced = { }
allowed_keys.each do |allowed_key|
if allowed_key.is_a?(Hash)
key = allowed_key.keys.first
sliced[key] = self[key].deep_slice(*[allowed_key.values].flatten) if self[key]
else
sliced[allowed_key] = self[allowed_key] if self[allowed_key]