Skip to content

Instantly share code, notes, and snippets.

View inorganik's full-sized avatar
🛠️
building

Jamie Perkins inorganik

🛠️
building
View GitHub Profile
@inorganik
inorganik / extendNavigator.js
Created January 6, 2014 15:57
Develop/use a phoneGap app in a web browser by extending the navigator object to mimic the Cordova navigator object
// check if we are running as a webapp or phonegap app
if (typeof cordova == 'undefined') {
// if webapp, extend navigator object to replace cordova's.
navigator.notification = {
alert : function(text, a, b, c) {
alert(text);
},
confirm : function(text, success) {
var response = confirm(text);
success(response);
@inorganik
inorganik / removeConsoleLogs
Last active August 29, 2015 13:55
The easiest way to remove console.logs from a file
Use a code editor with Regex find and replace. Then search:
console.log\(.*\)\;?
And replace with an empty string. ('').
@inorganik
inorganik / iOSmodelConverter.js
Last active August 29, 2015 14:02
Convert device.name to meaningfull model name
/*
With PhoneGap's device plugin, using device.name yields
something like "iPhone6,1" which is an identifier, not a
name. This function converts it to a meaningfull model name.
Example:
var model = getiOSModelName(device.name);
model = "iPhone 5s"
*/
@inorganik
inorganik / gist:fc59c72db9c691ced8e3
Created September 19, 2014 22:33
Prepare / Build / Run / Inspect
tell application "Terminal"
do script ("cordova prepare ios") in window 1
end tell
delay 3
tell application "Xcode"
activate
end tell
tell application "System Events"
@inorganik
inorganik / translateFrame
Last active August 29, 2015 14:07
Changes a frame for a rect with a default anchorPoint of (.5, .5) to remain in the same place with a different anchorPoint, because you can't change an anchorPoint in interface builder
// changes frame for a rect with a default anchorPoint of (.5, .5) to remain
// in the same place with a different anchorPoint, because you can't change
// an anchorPoint in interface builder
-(CGRect) translateFrame:(CGRect)frame forAnchorPoint:(CGPoint)anchorPoint {
NSLog(@"translate frame starting frame: %@ for anchorPoint: %@", NSStringFromCGRect(frame), NSStringFromCGPoint(anchorPoint));
CGRect newFrame = frame;
float xAdjustment = anchorPoint.x - .5;
float yAdjustment = anchorPoint.y - .5;
newFrame.origin.x = frame.origin.x + frame.size.width * xAdjustment;
@inorganik
inorganik / gist:cd6da5a79106d17b7c1b
Created September 21, 2015 16:00
Angular scroll spy
(function (angular) {
'use strict';
// Scroll Spy Directive
// ===============================
//
// * **Author:** Jamie Perkins
//
// $broadcast an event when an element comes into or goes out of view:
@inorganik
inorganik / extract-testflight.js
Last active April 6, 2016 12:50 — forked from creaoy/extract-testflight.js
Extract TestFlight user email addresses from iTunes Connect
// Make sure you scroll down to get all data loaded
var text = 'First, Last, Email\n';
angular.forEach($scope.filteredTesters, function(val) {
text += val.firstName.value + ',';
text += val.lastName.value + ',';
text += val.emailAddress.value + '\n';
});
var a = document.createElement("a");
var file = new Blob([text], {type: 'text/csv'});
a.href = URL.createObjectURL(file);
@inorganik
inorganik / gist:f9971e65f71e037650b39b5f182e157e
Created May 20, 2016 22:16
iOS Keychain status to string
+ (NSString *)keychainStatusToString:(OSStatus)status {
switch (status) {
case 0:
return @"Success";
case -4:
return @"Function or operation not implemented.";
case -50:
return @"One or more parameters passed to the function were not valid.";
case -108:
@inorganik
inorganik / firstpaint.js
Last active May 23, 2017 23:19 — forked from ebidel/firstpaint.js
Helper to print first paint time in Chrome
if (window.chrome && window.chrome.loadTimes) {
let load = chrome.loadTimes();
const getFP = function() {
let fp = (load.firstPaintTime - load.startLoadTime) * 1000;
return Math.round(fp);
};
let fp = getFP();
console.log(`first paint: ${fp} ms`);
@inorganik
inorganik / randomLocations.swift
Created June 22, 2017 14:37
Return a cluster of random locations around a given location
import Foundation
import CoreLocation
struct randomLocations {
// create random locations (lat and long coordinates) around user's location
func getMockLocationsFor(location: CLLocation, itemCount: Int) -> [CLLocation] {
func getBase(number: Double) -> Double {
return round(number * 1000)/1000