This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Let's say you got a Job model and you want to track index_count, show_count, etc. | |
| Why not use Hstore? | |
| Add a migration: | |
| class AddHstoreCountsOnJobs < ActiveRecord::Migration | |
| def change | |
| add_column :jobs, :index_count, :hstore, default: {} | |
| add_column :jobs, :show_count, :hstore, default: {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| validate_form = -> | |
| $('form').submit (event) -> | |
| $.each $(this).find('input'), (i,el) -> | |
| validate_field(el); | |
| $(el).on 'blur', -> validate_field(el) ; | |
| window.validate_form = validate_form | |
| validate_field = (el) -> | |
| if ($(el)[0].checkValidity()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE FUNCTION time_ago_in_words(timestamp with time zone) | |
| RETURNS text | |
| LANGUAGE SQL | |
| AS $$ | |
| SELECT CASE | |
| WHEN date_part('year', age(current_timestamp, $1)) = 1 THEN concat(date_part('year', age(current_timestamp, $1)), ' year ago') | |
| WHEN date_part('year', age(current_timestamp, $1)) > 1 THEN concat(date_part('year', age(current_timestamp, $1)), ' years ago') | |
| WHEN date_part('month', age(current_timestamp, $1)) = 1 THEN concat(date_part('month', age(current_timestamp, $1)), ' month ago') | |
| WHEN date_part('month', age(current_timestamp, $1)) > 1 THEN concat(date_part('month', age(current_timestamp, $1)), ' months ago') | |
| WHEN date_part('day', age(current_timestamp, $1)) = 1 THEN concat(date_part('day', age(current_timestamp, $1)), ' day ago') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # config/initializer/notification_center.rb | |
| NotificationCenter.queue | |
| NotificationCenter.thread | |
| ActiveSupport::Notifications.subscribe /(.)+\.notification/i do |*args| | |
| NotificationCenter.queue << args | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| activesupport (3.2.12) lib/active_support/core_ext/string/output_safety.rb:24:in `html_escape' | |
| actionpack (3.2.12) lib/action_view/helpers/tag_helper.rb:151:in `block in tag_options' | |
| actionpack (3.2.12) lib/action_view/helpers/tag_helper.rb:138:in `each_pair' | |
| actionpack (3.2.12) lib/action_view/helpers/tag_helper.rb:138:in `tag_options' | |
| actionpack (3.2.12) lib/action_view/helpers/tag_helper.rb:66:in `tag' | |
| actionpack (3.2.12) lib/action_view/helpers/active_model_helper.rb:24:in `tag' | |
| actionpack (3.2.12) lib/action_view/helpers/form_helper.rb:1046:in `to_input_field_tag' | |
| s3_file_field (1.0.4) lib/s3_file_field/form_helper.rb:24:in `s3_file_field' | |
| s3_file_field (1.0.4) lib/s3_file_field/form_helper.rb:7:in `s3_file_field' | |
| app/views/assets/partials/_avatar_form.html.erb:4:in `_app_views_assets_partials__avatar_form_html_erb__818076104424137440_70152587222680' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### ruby riak.rb number_of_nodes | |
| require "rubygems" | |
| # `killall epmd` ## to kill running riaks | |
| @riak_url = "http://s3.amazonaws.com/downloads.basho.com/riak/CURRENT/osx/10.4/" | |
| @riak_filename = "riak-1.2.0-osx-x86_64.tar.gz" | |
| @port = 8098 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var latlng; | |
| var address; | |
| geocoder = new google.maps.Geocoder(); | |
| function success(position) { | |
| var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); | |
| geocoder.geocode({'latLng': latlng}, function(results, status) { | |
| if (status == google.maps.GeocoderStatus.OK) { | |
| if (results[1]) { | |
| address = results[1].formatted_address; | |
| console.log(results[1]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <title>Crossfilter</title> | |
| <style> | |
| /** CrossFilter LineChart example | |
| The current CrossFilter demo, available here: http://square.github.com/crossfilter/ | |
| ... Only renders data as bar charts using d3.js. D3.js is an awesome visualization library that provides the ability to generate many different styles of visualization. This GIST is an attempt to document rendering cross filter data as a line chart instead of a bar chart. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function submitForm(){ | |
| $.ajax({ | |
| type: 'POST', | |
| url: "admin", | |
| data: { | |
| utf8: "✓", | |
| authenticity_token: $("meta[name='csrf-token']").attr('content'), | |
| search: { | |
| q: $('#search_q').val() | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Census2010 | |
| require 'csv' | |
| include Ripple::Document | |
| property :id, Integer, :presence => true | |
| property :sumlevel, Integer, :presence => true | |
| property :state_id, Integer | |
| property :stusab, String | |
| property :logrecno, Integer |