Skip to content

Instantly share code, notes, and snippets.

View christocracy's full-sized avatar

Chris Scott christocracy

View GitHub Profile
@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 / 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
object:
{
"location": {
"coords": {
"latitude": [Float],
"longitude": [Float]
"accuracy": [Float]
"speed": [Float],
"heading": [Float],
Basel.mainPage = SC.Page.design({
// The main pane is made visible on screen as soon as your app is loaded.
// Add childViews to this pane for views to display immediately on page
// load.
mainPane: SC.MainPane.design({
childViews: [SC.TabView.design({
value: 'Welcome',
items: [{
title: 'Welcome', value: 'welcome'
// ==========================================================================
// Project: Basel - mainPage
// Copyright: ©2010 My Company, Inc.
// ==========================================================================
/*globals Basel */
// This page describes the main user interface for your application.
Basel.mainPage = SC.Page.design({
// The main pane is made visible on screen as soon as your app is loaded.
desc "modulate <theme> <hue> <saturation> <lightness>", "Modulate a theme. Specify h, s, l as floats, eg: 1.5"
def modulate(theme, hue, saturation, lightness)
ExtJS::Theme.each_image {|img|
path = img.filename.split('/')
filename = path.pop
dir = path.pop
say_status("modulate", File.join(dir, filename))
ExtJS::Theme.write_image(img.modulate(lightness.to_f, saturation.to_f, hue.to_f), File.join(ExtJS::Theme["theme_dir"], theme))
}
gsub_file(File.join(ExtJS::Theme["theme_dir"], theme, "defines.sass"), /\$hue:\s?(.*)/, "$hue: #{(hue.to_f-1)*180}")
@christocracy
christocracy / foo.js
Created October 19, 2010 18:33
foo.js
/**
* @class Foo
* @singleton
*/
Foo = (function() {
return {
/**
* getFoo
*/
getFoo: function() {
@christocracy
christocracy / gist:673761
Created November 12, 2010 05:22
Ext.CompositeElement extension to intelligently cluster dom-nodes so they don't overlap. Good for un-cluttering dense markers on a map.
/**
* @class Ext.ux.PinOverlap
* An Ext.CompositeElement extension which intelligently moves dom-elements so they don't overlap each other.
* Created for clustering markers on a Map to not overlap. First picks the most efficient direction to move-off
* of overlapped element, keeping track of where it moved from. If it overlaps another, it'll back-track and attempt
* to move around the element based upon the MOVE_* CONSTANTS below. Eg.
*
* +---------------------------
* | +-------------------+
* | | |
/**
* Loads an array of {@Ext.data.Model model} instances into the store, fires the datachanged event. This should only usually
* be called internally when loading from the {@link Ext.data.Proxy Proxy}, when adding records manually use {@link #add} instead
* @param {Array} records The array of records to load
* @param {Boolean} add True to add these records to the existing records, false to remove the Store's existing records first
*/
loadRecords: function(records, add) {
if (!add) {
this.data.clear();
}
@christocracy
christocracy / ShopifyAPICallLimit.rb
Created May 14, 2011 15:24
Hacking ActiveResource::Connection for Shopify API in order to read HTTP response header 'http_x_shopify_api_call_limit'. Simply require this code after your gems have been loaded. Caveat emptor: This hack modifies a private method of AR::Connection; H
class ActiveResource::Connection
# HACK 1: Add an attr_reader for response
attr_reader :response
def request(method, path, *arguments)
result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
payload[:method] = method
payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
payload[:result] = http.send(method, path, *arguments)
end