Skip to content

Instantly share code, notes, and snippets.

@joost
joost / google_places_client.rb
Last active August 29, 2015 14:02
Super Simple Google Places API Ruby Client
# This gist is turned into a gem: https://github.com/joost/google_places_api
require 'hashie'
require 'faraday'
require 'faraday_middleware'
# Created our own very simple Google Places API client since the google_places gem
# is returning incorrect results.
# Usage:
# client = GooglePlacesClient.new(key: API_KEY)
# response = client.get('textsearch', query: 'something')
# ref = response.body.results.first.reference
@joost
joost / your_model.rb
Created March 27, 2015 11:01
Sunspot reindex without removing the index
class YourModel
# Overwrite sunspot version to not remove from index.
# See: https://github.com/sunspot/sunspot/blob/16e5f620814fd4bdf43e3df158e7fdcbbd92713b/sunspot_rails/lib/sunspot/rails/searchable.rb#L206
def self.solr_reindex(options = {})
solr_index(options)
solr_clean_index_orphans
end
end

Keybase proof

I hereby claim:

  • I am joost on github.
  • I am joosth (https://keybase.io/joosth) on keybase.
  • I have a public key whose fingerprint is 3546 2624 A98A C4A1 2E7C 414D ABA4 5856 9272 EE8A

To claim this, I am signing this object:

@joost
joost / docker_compose.rb
Last active August 29, 2015 14:22
Homebrew Docker Compose v1.3.0rc2 Formula
# Usage:
# https://gist.githubusercontent.com/joost/20934650f68dd561fc35/raw/44629ade560e0e546ac7d2f94537a594546c5e1f/docker_compose.rb
class DockerCompose < Formula
desc "Isolated development environments using Docker"
homepage "https://docs.docker.com/compose/"
url "https://github.com/docker/compose/archive/1.3.0rc2.tar.gz"
sha256 "4e0a6c82e283e44eb551a8e57bb40c1c2768f8acaf36eb7e858c99ca4fb3d0dc"
# bottle do
# sha256 "bf8a80a39a59185add39a12e6da2b53e19e08bb09d823b1cbaf2ffdcf797c3d7" => :yosemite
@joost
joost / solr.rb
Created November 27, 2012 12:38
Solr 4.0 brew recipe
require 'formula'
class Solr < Formula
url 'http://www.apache.org/dyn/closer.cgi?path=lucene/solr/4.0.0/apache-solr-4.0.0.tgz'
homepage 'http://lucene.apache.org/solr/'
sha1 '0cb61d9572516fc627785201b79b3a85e95f877d'
def script; <<-EOS.undent
#!/bin/sh
if [ -z "$1" ]; then
@joost
joost / search_hash.rb
Created November 28, 2012 12:27
Convert a params Hash to a Sunspot search.
# SearchHash converts a Hash with search options to a Sunspot search.
# Example:
# s = SearchHash.new(Model, :q => 'some string to match in all text fields')
# s.search # The Sunspot search
# s.search.results # The actual results
#
# s = SearchHash.new(Model, :some_field__gt => 12, :text_field_name => 'some query')
#
# Pagination:
# s = SearchHash.new(Model, {:some_field__gt => 12, :text_field_name => 'some query', :page => 2, :per_page => 100}, {:per_page_max => 200, :per_page_default => 25})
@joost
joost / compare_yaml.rb
Created November 9, 2015 14:25
Compare two YAML files
def compare_yaml_hash(cf1, cf2, context = [])
cf1.each do |key, value|
unless cf2.key?(key)
puts "Missing key : #{key} in path #{context.join(".")}"
next
end
value2 = cf2[key]
if (value.class != value2.class)
@joost
joost / gist:5354717
Created April 10, 2013 13:40
Languages per TLD
Source: http://www.distilled.net/blog/uncategorized/google-cctlds-and-associated-languages-codes-reference-sheet/
Top level domain Extension Country Name Language Language b
http://www.google.com.af .af Afghanistan fa – Persian ps – Pashto, Pushto
http://www.google.dz .dz Algeria fr – French ar – Arabic
http://www.google.as .as American Samoa en – English
http://www.google.ad .ad Andorra ca – Catalan; Valencian
http://www.google.co.ao .ao Angola pt-PT – Portuguese kg – Kongo
http://www.google.com.ai .ai Anguilla en – English
http://www.google.com.ag .ag Antigua and Barbuda en – English
@joost
joost / pixabay_client.rb
Created July 22, 2014 10:37
Supersimple http://pixabay.com/api/docs/ Ruby API client.
require 'hashie'
require 'faraday'
require 'faraday_middleware'
# Supersimple http://pixabay.com/api/docs/ client.
# Usage:
# result = PixabayClient.new(username: 'someone', key: 'your_key').get(search_term: 'beach')
# result.body # Mashified results
# See: https://gist.github.com/joost/e32daf904ed8bd171974
class PixabayClient
@joost
joost / icons8_client.rb
Created June 25, 2014 14:36
Super simple Ruby Icons8 API (http://api.icons8.com/) client
require 'hashie'
require 'faraday'
require 'faraday_middleware'
# Supersimple http://api.icons8.com/ client.
# Usage:
# Icons8Client.new.search('icon')
# See: https://gist.github.com/joost/e149404f645f33ba1939
class Icons8Client
def initialize(options = {})