Skip to content

Instantly share code, notes, and snippets.

View namit's full-sized avatar

Namit Yadav namit

  • Brownie Points, Inc.
View GitHub Profile
@namit
namit / sns_apns_endpoints.rb
Last active August 29, 2015 13:59
Creating and Editing Endpoints in Amazon Simple Notification Servicce (SNS) + Apple Apple Push Notification service (APNS) + Ruby
sns = AWS::SNS.new(:access_key_id => AWSPUB,:secret_access_key => AWSPRI)
app_arn = server.is_sandbox? ? SNS_SANDBOX_APP_ARN : SNS_PRODUCTION_APP_ARN
timestamp = Time.new.strftime("%Y-%m-%d %H:%M:%S")
custom_user_data = "{\"user_id\":#{user.id},\"type\":\"#{token_type}\",\"update_ts\":\"#{timestamp}\"}"
if edit_endpoint # Edit existing endpoint
apn_token = AppleToken.find(:id => token_id) # AppleToken is the DB object in Sequel
if apn_token.nil? || apn_token.user_id != user.id
# Token ID not found for this user
@namit
namit / sns_apns_publish.rb
Last active August 29, 2015 14:00
Publishing messages in Amazon Simple Notification Servicce (SNS) + Apple Apple Push Notification service (APNS) + Ruby
def self.sendapns(apnsdata)
type = apnsdata['type']
uid = apnsdata['userid'].to_i
endpoint_arn = get_endpoint_arn(uid)
notification = APNS_NOTIFICATIONS[type] # Get the notification fields from wherever you store them
if notification.nil?
@log.error("notification type '#{type}' not found")
return
end
@namit
namit / pre-commit
Last active August 29, 2015 14:18
Git pre-commit hook to deny commits in production branches and for files larger than a specified size
#!/usr/bin/env ruby
# (1) Prevent any commit to production branches
PRODUCTION_BRANCHES = ["production"]
branch = `git rev-parse --abbrev-ref=strict HEAD`.chomp
if (PRODUCTION_BRANCHES.include?(branch))
puts "\nDo you really want to commit on '#{branch}' branch?\nIf yes, add --no-verify to the commit command to force it."