Skip to content

Instantly share code, notes, and snippets.

View justingreerbbi's full-sized avatar

Justin Greer justingreerbbi

View GitHub Profile
@marcoarment
marcoarment / apns_jwt_token.php
Last active April 14, 2024 06:49
Generate ES256 JWT tokens for Apple Push Notification Service (APNS) in PHP
<?php
function base64url_encode($binary_data) { return strtr(rtrim(base64_encode($binary_data), '='), '+/', '-_'); }
function apns_jwt_token($team_id, $key_id, $private_key_pem_str)
{
if (! function_exists('openssl_get_md_methods') || ! in_array('sha256', openssl_get_md_methods())) throw new Exception('Requires openssl with sha256 support');
$private_key = openssl_pkey_get_private($private_key_pem_str);
if (! $private_key) throw new Exception('Cannot decode private key');
@njncalub
njncalub / centerImageView.js
Last active November 16, 2018 00:52
Center a Titanium.UI.ImageView inside a parent Titanium.UI.View similar to a `background-size: cover;` in CSS.
/**
* Center a Titanium.UI.ImageView inside a parent Titanium.UI.View
* similar to a `background-size: cover;` in CSS.
*
* Takes 3 parameters: imageRatio, parentView, and imageView
*
* imageRatio:
* an object with the ratio or actual dimension of the image to be placed in the ImageView.
* e.g. {width: 3, height: 2}
*