Skip to content

Instantly share code, notes, and snippets.

View AndyObtiva's full-sized avatar

Andy Maleh AndyObtiva

View GitHub Profile
@AndyObtiva
AndyObtiva / heroku_config_parser.rb
Last active August 29, 2015 13:55
Heroku Config Parser in Ruby
# Parses configuration out from the "heroku config" command, and converts to command-line input
# for the "heroku config:add" command. It escapes $ characters.
def parse(config_text)
config_line_regex = /([^:]+):(.*)/
config_text.split("\n").map do |line|
line_match = line.match(config_line_regex)
[line_match[1], line_match[2]]
end.map do |name, value|
"#{name.strip}=\"#{value.strip.gsub("$", "\\$")}\""
end.join(" ")
@AndyObtiva
AndyObtiva / speedtest
Created February 24, 2014 05:19
Speedtest Command for Bash. Assumes you have https://pypi.python.org/pypi/speedtest-cli installed.
#!/bin/sh
echo "Usage: speedtest [city]"
echo "Default city: Montreal"
echo "Examples:"
echo "$ speedtest Chicago"
echo "$ speedtest 'New York'\n"
[[ $1 ]] && city="$1" || city='Montreal'
echo "Speedtesting $city... Please be patient as this may take a minute or more depending on the Internet connection..."
speedtest-cli --list | grep -i "$city" | sed 's/^\([^\)]*\).*$/\1/' | sed -n '1,1p' | xargs speedtest-cli --share --server | grep 'Share results:' | grep 'Share results:' | sed 's/^Share results: \(.*\)$/\1/' | xargs open
echo "Done. If no report image has been opened, then please try again with another city."
@AndyObtiva
AndyObtiva / ultra_light_wizard_0_0_6_command.md
Last active February 1, 2016 03:24
Ultra Light Wizard 0.0.6 Command Output
generate  scaffold
  invoke  active_record
  create    db/migrate/20160201025849_create_projects.rb
  create    app/models/project.rb
  invoke    test_unit
  create      test/models/project_test.rb
  create      test/fixtures/projects.yml
  invoke  resource_route
   route    resources :projects
@AndyObtiva
AndyObtiva / prefix-of.clj
Created June 20, 2017 11:58
Checks if a particular collection is a prefix of another collection (contained in it at the beginning). e.g. (prefix-of? [1 2] [1 2 3]) returns true whereas (prefix-of? [2 3] [1 2 3]) returns false.
(def prefix-of?
(fn [chunk full]
(or
(empty? chunk)
(and
(=
(take 1 chunk)
(take 1 full)
)
(prefix-of?
@AndyObtiva
AndyObtiva / hello_list_single_selection.rb
Last active July 21, 2017 22:59
HelloListSingleSelection Glimmer Example
require "glimmer"
class Person
attr_accessor :country, :country_options
def initialize
self.country_options=["", "Canada", "US", "Mexico"]
self.country = "Canada"
end
@AndyObtiva
AndyObtiva / glimmer-usage.md
Last active July 22, 2017 20:07
Glimmer Usage

Usage

Usage: glimmer [--setup] [application_ruby_file_path.rb]

Example 1: glimmer hello_combo.rb This runs the Glimmer application hello_combo.rb If the SWT Jar is missing, it downloads it and sets it up first.

Example 2: glimmer --setup hello_combo.rb This performs setup and then runs the Glimmer application hello_combo.rb It downloads and sets up the SWT jar whether missing or not.

Logging

Glimmer comes with a Ruby Logger accessible via Glimmer.logger Its level of logging defaults to Logger::WARN It may be configured to show a different level of logging as follows:

Glimmer.logger.level = Logger::DEBUG

This results in more verbose debugging log to STDOUT, which is helpful in troubleshooting Glimmer DSL syntax when needed.

Example log:

@AndyObtiva
AndyObtiva / glimmer__tree_data_binding__spec.rb
Last active July 26, 2017 20:17
Glimmer Tree Data Binding Spec
require "spec_helper"
describe "Glimmer Tree Data Binding" do
include Glimmer
include_package 'org.eclipse.swt'
include_package 'org.eclipse.swt.widgets'
include_package 'org.eclipse.swt.layout'
before do
@AndyObtiva
AndyObtiva / glimmer_tree_data_binding_example.rb
Created July 26, 2017 20:20
Glimmer Tree Data-Binding Example
shell {
tree(:virtual, :border) {
items bind(company, :owner), tree_properties(children: :people, text: :name)
}
}
@AndyObtiva
AndyObtiva / ultra_light_wizard_spec.rb
Created July 30, 2017 00:13
Ultra Light Wizard spec
describe UltraLightWizard do
let(:app_rails_ref) {File.expand_path(File.join(__FILE__, '..', '..', '..', 'fixtures', 'ref_rails_app'))}
let(:app_rails_copy) {app_rails_ref.sub('ref', 'copy')}
before do
FileUtils.rm_rf app_rails_copy
FileUtils.cp_r app_rails_ref, app_rails_copy
end
after do
FileUtils.rm_rf app_rails_copy
end