Skip to content

Instantly share code, notes, and snippets.

View jkotchoff's full-sized avatar
💭
1's and 0's

Jason Kotchoff jkotchoff

💭
1's and 0's
View GitHub Profile
require 'net/http'
# Extend img tag to optionally embed images in-line into HTML instead of referencing as a URI
#
# This is a useful technique when sending HTML emails as it circumvents the prompt many mail clients
# present seeking permission to 'display images from this sender?' when an email of mime-type 'html'
# contains <img> tags.
#
# ie. <%= image_tag('red_dot.gif', :embed_inline => "true") %>
#
@jkotchoff
jkotchoff / interview_q1_spec.rb
Created May 23, 2012 23:43
Ruby on Rails Interview Question (1)
require 'rspec'
def format_money(amount)
'-1' #TODO
end
describe "format_money" do
context "when the amount is a simple fraction" do
subject{ 0.4 }
specify{ format_money(subject).should == "$0.40" }
@jkotchoff
jkotchoff / google_play_verification.rb
Last active July 6, 2023 17:57
Verifying an Android subscription in a Ruby on Rails app using the Google Play API
class GooglePlayVerification
require 'google/api_client'
# Refer:
# https://code.google.com/p/google-api-ruby-client/issues/detail?id=72
# and
# http://jonathanotto.com/blog/google_oauth2_api_quick_tutorial.html
# and
# http://milancermak.wordpress.com/2012/08/24/server-side-verification-of-google-play-subsc/
GOOGLE_KEY = 'xxx-xxx.apps.googleusercontent.com'
@jkotchoff
jkotchoff / images2android.sh
Last active December 22, 2015 19:09 — forked from Arood/images2android.sh
Updated the gist for @_StockLight. As per @jeffbonnes advice at @ticonf melbourne 2013, this version expects a Resources/images directory (instead of Resources/iphone/images) that contains the standard and @2x images which are served straight to iOS and also MDPI Android devices.
type mogrify >/dev/null 2>&1 || { echo >&2 "» This script requires mogrify. Please install ImageMagick first!"; exit 1; }
rm -rf Resources/android/images
mkdir Resources/android/images
mkdir Resources/android/images/res-xhdpi
mkdir Resources/android/images/res-mdpi
echo " » Copying the splash screen"
cp Resources/iphone/Default.png Resources/android/images/res-mdpi/default.png
cp Resources/iphone/Default@2x.png Resources/android/images/res-xhdpi/default.png
@jkotchoff
jkotchoff / Screen Shot 2013-09-24 at 1.15.18 PM.png
Last active December 23, 2015 19:08
on iOS7, certain strings do not render as visible on a Titanium Alert Dialog. This is a temporary workaround until a platform fix is released.
Screen Shot 2013-09-24 at 1.15.18 PM.png
@jkotchoff
jkotchoff / titanium_tablet_check.js
Created October 25, 2013 02:37
This is an edit of: http://www.libtronics.com/2013/10/determining-if-device-is-tablet-on.html that can be used to check whether an appcelerator Titanium app should be rendered with a tablet layout.
function isTablet(){
if(!Ti.Android){
return Ti.Platform.osname === 'ipad';
}
// http://www.libtronics.com/2013/10/determining-if-device-is-tablet-on.html
var height = Ti.Platform.displayCaps.platformHeight;
var width = Ti.Platform.displayCaps.platformWidth;
if (height < width){
var w_inch = height / Ti.Platform.displayCaps.xdpi;
# This class shows uses version 0.28.7 of the ruby google-api-client gem circa April 2019
# to query the Google Play subscription API.
#
# If using an older version of the google-api-client gem (ie. version 0.8.x), instead refer to:
# https://gist.github.com/jkotchoff/e60fdf048ec443272045/e3e2c867633900d9d6f53de2de13aa0a0a16bb03
#
# Sample usage:
#
# package_name = 'com.stocklight.stocklightapp'
# product_id = 'com.stocklight.stocklight.standardsubscription'
@jkotchoff
jkotchoff / urban_airship_device_token_export.rb
Created December 23, 2014 22:21
Export device tokens from Urban Airship
require 'rubygems'
require 'urbanairship'
require 'httparty'
Urbanairship.application_key = '...'
Urbanairship.application_secret = '...'
Urbanairship.master_secret = '...'
response = Urbanairship.device_tokens
@jkotchoff
jkotchoff / aws_sns_push_notification.rb
Last active February 24, 2021 00:57
Sends a push notifications to an iOS and an Android device from Amazon SNS V2
require 'rubygems'
require 'aws-sdk'
# This code snippet sends a push notification to a device using the Amazon SNS service.
#
# It is using the preview V2 amazon gem as per:
# https://aws.amazon.com/sdk-for-ruby/
#
# This was installed using:
# $ gem install aws-sdk --pre
@jkotchoff
jkotchoff / listview_pullview_ios_extend_edges.js
Last active August 29, 2015 14:13
Using the titanium Listview with a pullView example on an iOS window with extendEdges set to Ti.UI.EXTEND_EDGE_TOP
var win = Ti.UI.createWindow({title: 'listview test', backgroundColor: 'white', extendEdges: [Ti.UI.EXTEND_EDGE_TOP]});
var listView = Ti.UI.createListView({height:'90%', top:0});
var sections = [];
var TOP_OFFSET = 64;
listView.setContentInsets({top:TOP_OFFSET}, {animated:false});
var fruitSection = Ti.UI.createListSection({ headerTitle: 'Fruits'});
var fruitDataSet = [
{properties: { title: 'Apple'}},