Skip to content

Instantly share code, notes, and snippets.

View christocracy's full-sized avatar

Chris Scott christocracy

View GitHub Profile
object:
{
"location": {
"coords": {
"latitude": [Float],
"longitude": [Float]
"accuracy": [Float]
"speed": [Float],
"heading": [Float],
@christocracy
christocracy / geofence.js
Created May 20, 2015 04:31
BackgroundGeolocation Geofence API
// Add custom longpress event for adding GeoFence with hard-coded radius 200m.
google.maps.event.addListener(app.map, 'longpress', function(e) {
if (app.geofence) {
app.geofence.setMap(null);
}
// Add the geofence with BackgroundGeolocation plugin
bgGeo.addGeofence({
identifier: 'MyGeofence',
radius: 200,
latitude: e.latLng.lat(),
@christocracy
christocracy / grid_clusterer.rb
Created August 7, 2014 07:20
grid_clusterer.rb
module GeoKit
#It is half of the earth circumference in pixels at zoom level 21.
#You can visualize it by thinking of full map. Full map size is 536870912 × 536870912 pixels.
#Center of the map in pixel coordinates is 268435456,268435456 which in latitude and longitude would be 0,0.
PIXEL_OFFSET = 268435456
PIXEL_RADIUS = PIXEL_OFFSET / Math::PI
module Mappable
module ClassMethods
@christocracy
christocracy / LanguageTranslation.rb
Created June 20, 2014 06:48
Language translation management with phrase-dependencies
LanguageTranslation
has_many :dependencies, :after_remove => :on_remove_dependency
private
def on_remove_dependency(dep)
if dependencies.count == 0
# if this phrase is no longer pointed-to, destroy self
self.destroy
end
end
@christocracy
christocracy / gist:8481702
Created January 17, 2014 21:14
Fix the iOS, Phonegap NIB error, dammit. Add this to your `.cordova/hooks/after_platform_add/patch_plist.sh` `$ chmod +x patch_plist.sh`
#!/bin/bash
if pushd platforms/ios 2>/dev/null ; then # iOS-specific actions...
# Patch *-Info.plist
PROJNAME=$(echo *.xcodeproj|sed -e 's/\..*//')
sed -i '' '/<key>NSMainNibFile<\/key>/,/<\/string>/d' $PROJNAME/*-Info.plist
sed -i '' '/<key>NSMainNibFile~ipad<\/key>/,/<\/string>/d' $PROJNAME/*-Info.plist
popd
fi
@christocracy
christocracy / new_bashrc.sh
Created August 11, 2012 08:03 — forked from josephwecker/new_bashrc.sh
Replace .bashrc, .bash_profile, .profile, etc. with something much more clean, consistent, and meaningful.
#!/bin/bash
# License: Public Domain.
# Author: Joseph Wecker, 2012
#
# Are you tired of trying to remember what .bashrc does vs .bash_profile vs .profile?
# Are you tired of trying to remember how darwin/mac-osx treat them differently from linux?
# Are you tired of not having your ~/.bash* stuff work the way you expect?
#
# Symlink all of the following to this file:
# * ~/.bashrc
@christocracy
christocracy / plugins.js
Created June 23, 2011 13:55
Adding plugins from within a plugin
Ext.define('GridScaffold', {
extend: 'Ext.AbstractPlugin',
alias: 'plugin.grid.Scaffold',
enableDD: false,
constructor: function(config) {
var grid = config.cmp;
grid.items = grid.items || [];
if (config.enableDD) {
// construct a sub-plugin within another but have call #constructPlugin at this point.
@christocracy
christocracy / AbstractComponent.js
Created June 23, 2011 12:13
Plugin lifecycle
// @_jdg Ok, I think I see where you're going, you're saying you can't do this:
//
Ext.define('MyClass', {
extend: 'Ext.panel.Panel',
initComponent: function() {
Ext.apply(this, {
plugins: ['my-plugin'],
.
.
@christocracy
christocracy / Ext.data.AjaxProxy.js
Created June 22, 2011 16:03
Fix for duplicate records being created after store.sync()
/**
* AjaxProxy is totally borked when it comes to synchronizing records of an UPDATE or CRDATE action
* NB: This hack assumes that server will return result recordset in the same order received.
*/
Ext.override(Ext.data.AjaxProxy, {
createRequestCallback: function(request, operation, callback, scope) {
var me = this;
return function(options, success, response) {
if (success === true) {
var reader = me.getReader(),
@christocracy
christocracy / categories.js
Created June 19, 2011 18:55
JSON Response for categories
// Your response uses XML-like nesting which is incompatible with Sencha's JsonReader.
[
{ // <----- no
"category": {
.
.
.
"tracks": [
{ // <------ no