Skip to content

Instantly share code, notes, and snippets.

View AddEvent & RemoveEvent cross-browser implementation
// These are cross-browser implementations of addEvent and removeEvent that account for differences
// in how addEventListener and attachEvent are supported across W3C standards browsers, and IE < IE9 standards mode.
// (IE9 compatibility mode uses attachEvent, standards mode uses addEventListener).
// The approach here attempts to solve several problems:
// 1. IE's attachEvent obliterates 'this' and the 'this' in the callback becomes 'window'
// 2. The fix, which is to call the function as a method on the object, requires that
// each instance of the function be tagged individually (the guid) so that multiple listeners can be applied
// to the same object
// 3. Avoid the memory leaks associated with adding a property to the object that it did not already have
View Creating an organization site
# Creating a Github Pages Organization Website
This was not exactly straightforward. No GitHub documentation directly walks you through this process - so I am documenting it here.
# Scenario
Let's say your organization is called 'AcmeWidgets' and you want to have your website at the root URL of your Github Pages website: https://acmewidges.github.io/
You also want to do the following, which doesn't seem SO weird, right?
- You are using something like Yeoman or Jekyll to manage your organization site
- You want your DISTRIBUTION files to exist on a branch on your repository
- You want your SOURCE files to exist in another branch.
View YouTube API — getting video thumbnail
Each YouTube video has 4 generated images. They are predictably formatted as follows:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
@codinronan
codinronan / braintree.d.ts
Created Dec 15, 2017 — forked from stwiname/braintree.d.ts
Typescript definition file for Braintree node module
View braintree.d.ts
//TODO update objects to show optional parameters
//TODO expand on Function parameters
//TODO add enum types
//TODO add error types
declare module Braintree {
/**********************
* Errors *
@codinronan
codinronan / us-states.js
Last active Jan 24, 2018
JSON apping of US states and abbreviations
View us-states.js
var usStates = [
{ name: 'ALABAMA', abbreviation: 'AL'},
{ name: 'ALASKA', abbreviation: 'AK'},
{ name: 'AMERICAN SAMOA', abbreviation: 'AS'},
{ name: 'ARIZONA', abbreviation: 'AZ'},
{ name: 'ARKANSAS', abbreviation: 'AR'},
{ name: 'CALIFORNIA', abbreviation: 'CA'},
{ name: 'COLORADO', abbreviation: 'CO'},
{ name: 'CONNECTICUT', abbreviation: 'CT'},
{ name: 'DELAWARE', abbreviation: 'DE'},
@codinronan
codinronan / countries.json
Created Feb 2, 2018 — forked from keeguon/countries.json
A list of countries in JSON
View countries.json
[
{name: 'Afghanistan', code: 'AF'},
{name: 'Åland Islands', code: 'AX'},
{name: 'Albania', code: 'AL'},
{name: 'Algeria', code: 'DZ'},
{name: 'American Samoa', code: 'AS'},
{name: 'AndorrA', code: 'AD'},
{name: 'Angola', code: 'AO'},
{name: 'Anguilla', code: 'AI'},
{name: 'Antarctica', code: 'AQ'},
@codinronan
codinronan / timestamp_version_bump.js
Created Feb 18, 2018
Apache Cordova build hook to auto bump iOS CFBundleVersion and Android versionCode
View timestamp_version_bump.js
#!/usr/bin/env node
var fs = require("fs"),
path = require("path");
var rootdir = process.argv[2];
if (rootdir) {
module.exports = function(context) {
@codinronan
codinronan / gist:24e93bb7a8717e13279a43882ab5c4f2
Last active Feb 19, 2018
cordova-plugin-braintree-gradle-fix.js
View gist:24e93bb7a8717e13279a43882ab5c4f2
#!/usr/bin/env node
// Define hook in your config.xml inside the android platform node:
// <platform name="android">
// <hook src="scripts/gradle-fix.js" type="before_prepare" />
// <hook src="scripts/gradle-fix.js" type="after_prepare" />
// </platform>
// The purpose of this script is to resolve the android.support version conflicts in cordova plugins
View keybase.md

Keybase proof

I hereby claim:

  • I am codinronan on github.
  • I am eapat (https://keybase.io/eapat) on keybase.
  • I have a public key ASDMyOAjW_-tZQviT7t5--AA8N_z8NcWc-Bk1a4-GiOE4Ao

To claim this, I am signing this object:

@codinronan
codinronan / events.service.ts
Last active Jun 9, 2018
Decorator for Ionic Storage
View events.service.ts
import { Injectable, NgZone } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { ReplaySubject } from 'rxjs/ReplaySubject';
// We use a ReplaySubject instead of a Subject or BehaviorSubject because we want to ensure 2 things:
// 1. That new subscribers receive any current values
// 2. That if the subject has never been invoked, no value is passed when a subscriber is wired up.
// Subject does not provide replay behavior (providing the current value), and BehaviorSubject
// requires an initial value, which may not be appropriate to the event.
// Therefore ReplaySubject, with a 1-element window, is the correct choice.