Skip to content

Instantly share code, notes, and snippets.

@Bodacious
Bodacious / app_delegate.rb
Created October 22, 2012 17:11
Simple Rubymotion app with UIAlertView
class MyController < UIViewController
def viewDidLoad
self.view.backgroundColor = UIColor.whiteColor
alert.show
end
# ==============
# = Properties =
# ==============
@Bodacious
Bodacious / Katana Code's Git Strategy.md
Created April 14, 2013 18:38
Here's KatanaCode's Git Strategy which each of us use across all of the projects we're involved with

Katana Code's Git Strategy

Introduction

The purpose of this document is to define the strategy which all Katana Code employees and subcontractors must adhere to when working on Katana Code projects.

The aim is to develop a uniform, coherent and effective solution. This document is not written in stone and can be updated as and when better approaches are discovered.

Topic Branches

@Bodacious
Bodacious / pesapal.rb
Last active October 25, 2016 17:49
PesaPal OpenAuth integration (not working yet)
require 'oauth'
require 'uri'
key = # my Consumer Key (sandbox)
sec = # my Consumer Secret (sandbox)
SITE_URL = 'https://demo.pesapal.com'
# An XML string of param data to include with our request
RAW_XML = <<-XML
@Bodacious
Bodacious / pesapal.rb
Last active December 17, 2015 14:39
pesa-pal integration in Rails [incomplete]
module PesaPal
include ActiveSupport::Configurable
self.configure do |config|
config.test_mode = !Rails.env.production?
config.consumer_key = Rails.env.production? ? "" : ""
config.consumer_secret = Rails.env.production? ? "" : ""
config.merchant_email = Rails.env.production? ? "" : "[email protected]"
@Bodacious
Bodacious / pesapal.rb
Created May 22, 2013 09:52
PesaPal Implementation in Ruby (test)
module PesaPal
require 'active_support'
include ActiveSupport::Configurable
self.configure do |config|
config.test_mode = true
config.consumer_key = "<your key>"
config.consumer_secret = "<your secret>"
end
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@Bodacious
Bodacious / application_helper.rb
Created November 8, 2013 18:18
Rails helpers for paypal payment acceptance methods
def paypal_acceptance_badge
path = "https://www.paypal.com/webapps/mpp/paypal-popup"
im_path = "https://www.paypalobjects.com/webstatic/mktg/logo/AM_SbyPP_mc_vs_dc_ae.jpg"
link_to(path, title: "How PayPal Works", id: "paypal_acceptance_badge") do
image_tag(im_path, border: "0", alt: "PayPal Acceptance Mark")
end
end
# app/helpers/forms_helper.rb
module FormsHelper
# A custom FormBuilder class for Rails forms with Twitter Bootstrap 3
class CustomFormBuilder < ActionView::Helpers::FormBuilder
# ActionView::Helpers::FormHelper and ActionView::Helpers::FormBuilder
# methods each have different args. This hash stores the names of the args
# and the methods that have those args in order to DRY up the method aliases
# defined below.
@Bodacious
Bodacious / musical_note_frequencies.rb
Last active January 2, 2016 14:59
List of musical notes and their frequencies calculated in Ruby
# The freqencies of A are easiest as most are integers
# Remember - each octave means double frequency
A_FREQS = %w[ 27.5 55 110 220 440 880 1760 3520 7040 14080 ].map(&:to_f)
# The names of the 12 semitones
NOTES = %W[ A\s A# B\s C\s C# D\s D# E\s F\s F# G\s G# ]
A_FREQS.each_with_index do |freq, octave|
NOTES.each_with_index do |note, i|
octave += 1 if note == "C\s"
@Bodacious
Bodacious / app_delegate.rb
Created April 1, 2014 20:00
Rubymotion developers often seem to shy away from using getter methods for instance variables. Instead, they're defined all over the place - as you'd see more in Objective-C.
# This is the approach I see most commonly in Rubymotion code examples.
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@mainViewController = MainViewController.alloc.init
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
@window.rootViewController = mainViewController
@window.makeKeyAndVisible
true
end