Skip to content

Instantly share code, notes, and snippets.

ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
@malandrina
malandrina / map-config-0622
Last active August 29, 2015 14:23
map config 062215
{
"mapStyles": {
"destinationHighlight":{
"useClientId":true,
"ease":"Back.easeInOut.config(1.7)",
"fill":"#looool"
},
"categoryHighlight":{
"ease":"Back.easeInOut.config(1.7)",
"fills":{
@malandrina
malandrina / default-map-config
Last active August 29, 2015 14:23
default map config
{
"mapStyles": {
"destinationHighlight":{
"useClientId":true,
"ease":"Back.easeInOut.config(1.7)",
"fill":"#looool"
},
"categoryHighlight":{
"ease":"Back.easeInOut.config(1.7)",
"fills":{
@malandrina
malandrina / map-config.json
Last active August 29, 2015 14:18
map config json
{
"mapStyles": {
"destinationHighlight":{
"useClientId":true,
"ease":"Back.easeInOut.config(1.7)",
"fill":"#FFFFFF"
},
"categoryHighlight":{
"ease":"Back.easeInOut.config(1.7)",
"fills":{
@malandrina
malandrina / gist:9237572
Last active August 29, 2015 13:56
HotelTonight Rails 4 Deprecation Warnings
DEPRECATION WARNING: It looks like you are eager loading table(s) (one of: agents, hoteltonight) that are referenced in a string SQL snippet. For example:
Post.includes(:comments).where("comments.title = 'foo'")
Currently, Active Record recognizes the table in the string, and knows to JOIN the comments table to the query, rather than loading comments in a separate query. However, doing this without writing a full-blown SQL parser is inherently flawed. Since we don't want to write an SQL parser, we are removing this functionality. From now on, you must explicitly tell Active Record when you are referencing a table from a string:
Post.includes(:comments).where("comments.title = 'foo'").references(:comments)
If you don't rely on implicit join references you can disable the feature entirely by setting `config.active_record.disable_implicit_join_references = true`. (called from _app_views_agents_index_html_haml__860689087346826956_70228045189400 at /Users/training/Source/thoughtbot/hotelstonight/app/vi
module GeospatialObject
METERS_PER_MILE = 1609.34
module Callbacks
def set_geographic_point
ActiveRecord::Base.connection.execute(<<-TEXT
UPDATE addresses
SET geographic_point = ST_GeographyFromText('POINT(' || longitude || ' ' || latitude || ')')
WHERE id = #{self.id}
TEXT
class Geocoder
queryGeocodingApi: (options) ->
if options.coordinates
formattedLatlng = "#{options.coordinates.latitude},#{options.coordinates.longitude}"
@.reverseGeocode(latlng: formattedLatlng)
reverseGeocode: (options) ->
$.ajax
type: 'GET'
url: 'https://maps.googleapis.com/maps/api/geocode/json'
def filter_by_highest_ranked_user_coaches
coach_user_ids_string = coach_user_ids.to_s.gsub('[', '').gsub(']', '')
highest_ranked_coach_ids = ActiveRecord::Base.connection.execute(<<-TEXT
SELECT DISTINCT on (user_id) user_id, id
FROM coaches c
WHERE coachup_ranking_score =
(SELECT MAX(r.coachup_ranking_score)
FROM coaches r
WHERE c.user_id = r.user_id
@malandrina
malandrina / filereader.rb
Created October 27, 2012 00:00 — forked from dbc-challenges/card.rb
FlashCardinator
class FileReader
def initialize(file)
@file = file
end
def read_file
@dictionary = {}
File.open(@file, "r").each do |line|
line.gsub!(/\\/, "")
split_line = line.chomp.split("\t")
@malandrina
malandrina / gist:3752723
Created September 19, 2012 22:24
Writing a faster anagram solver for same-length anagrams, in Ruby

Writing a faster anagram solver for same-length, one-word anagrams, in Ruby

In [my first attempt] (https://gist.github.com/3745321) at writing an anagram solver, I stored my word list in a hash in which values are words and keys are characters in those words, sorted alphabetically.

I liked this approach, but my implementation was not ideal: I defined the creation of the hash as an activity that occurs when the #same_length_anagrams method is called. This, of course, made it super slow!

This time I was able to structure things so that the word list hash is created when the program is initialized. The Ruby documentation for the #shell class leaves a lot to be desired, but [this very helpful blog post] (http://devver.wordpress.com/2009/10/12/ruby-subprocesses-part_3/) on starting sub-processes in Ruby provided me with a great point of departure. My next step is to figure out how to clean up lines 1 - 12.

# Create word list hash