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
@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 / 1-oauth2_tweet_from_ruby.md
Last active July 3, 2023 10:54
Twitter v2 Oauth2 send tweet from Ruby on Rails
@jkotchoff
jkotchoff / generate_twitter_bearer_token.rb
Last active April 27, 2023 23:10
Send Tweets to the Twitter API with an OAuth1 token
# Generate and use an oauth2 bearer token for the Twitter API in Ruby
#
# For Application-Only authentication to the twitter API, a 'bearer token'
# is required to authenticate agains their endpoints for rate limiting
# purposes.
#
# This script generates a bearer token by posting to twitter and then it
# uses that token to poll their API.
#
# Note, the base 64 encoded consumer credentials for the bearer token needs
@jkotchoff
jkotchoff / emailed_zip_file_extractor.rb
Created November 29, 2016 00:23
Rails example of how to connect to the Gmail API using Ruby and download a Zip File attachment and then unzip contents from the zip archive
class EmailedZipFileExtractor
# This class downloads an email from gmail and extracts a file out of a .zip attachment
require 'google/apis/gmail_v1'
require 'googleauth'
require 'zip'
# These credentials come from creating an OAuth Web Application client ID
# in the Google developer console
#
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") %>
#
# 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 / 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 / bitrise.yml
Created April 12, 2020 04:45
Bitrise CI slack workflow
...
workflows:
primary:
steps:
- activate-ssh-key@4.0.3:
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
- git-clone@4.0.17: {}
- script@1.1.5:
inputs:
- content: |-
@jkotchoff
jkotchoff / appc.js
Last active November 12, 2017 01:29
This Titanium code can be used in an appcelerator project (with Hyperloop enabled) to determine if an iOS advertisement was the cause of the current installation
module.exports = {
hyperloop: {
ios: {
xcodebuild: {
frameworks: [
'iAd'
]
}
}
}
@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;