Skip to content

Instantly share code, notes, and snippets.

View elrikdante's full-sized avatar

Dante Haskell Elrik elrikdante

View GitHub Profile
@elrikdante
elrikdante / AlaCarte.hs
Created December 13, 2015 04:14 — forked from puffnfresh/AlaCarte.hs
Coproduct to combine algebras for a free monad interpreter.
module AlaCarte where
-- Control.Monad.Free
data Free f a = Free (f (Free f a)) | Pure a
instance Functor f => Monad (Free f) where
Pure a >>= f = f a
Free r >>= f = Free (fmap (>>= f) r)
return = Pure
@elrikdante
elrikdante / geo_world_map_migration
Created December 30, 2015 05:31 — forked from scicco/geo_world_map_migration
Rails migration for GeoWorldMap db into postgresql db
class CreatePlaces < ActiveRecord::Migration
# Rails migration for GeoWorldMap db into postgresql db
#(inspired by http://blog.inspired.no/populate-your-database-with-free-world-cities-countries-regions-in-2-minutes-using-a-rails-migration-273/ post)
#extract files from GeoWorldMap.zip archive from here
# http://www.geobytes.com/GeoWorldMap.zip
#
#and place them into #{Rails.root}/db/migrate/
##the archive has 'cities.txt' file, rename it 'Cities.txt'
#mv cities.txt Cities.txt
@elrikdante
elrikdante / iso6801-duration.hs
Created March 7, 2016 05:02 — forked from nh2/iso6801-duration.hs
Haskell module for parsing ISO8601 durations
{-# LANGUAGE ScopedTypeVariables #-}
module Data.Time.ISO8601.Duration where
import Control.Applicative
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as BS8
import Data.Attoparsec.ByteString.Char8
import Test.QuickCheck
@elrikdante
elrikdante / hspec-before-all.hs
Created March 7, 2016 05:06 — forked from nh2/hspec-before-all.hs
Example of ignoring hspec's beforeAll hook context
import Control.Concurrent (threadDelay)
import Test.Hspec
import qualified Test.Hspec.Core.Hooks as Hooks
main :: IO ()
main = hspec spec
-- | When a hook is set up with `beforeAll`, that changes the type
@elrikdante
elrikdante / get_messages_off_rabbitmq.rb
Created March 30, 2016 13:46 — forked from natritmeyer/get_messages_off_rabbitmq.rb
Get messages off a RabbitMQ... Queue!
require 'httparty'
require 'json'
class QueueInspector
include HTTParty
basic_auth "guest", "guest"
base_uri "http://192.168.0.1:55672"
def messages
body = {'count' => 5,'requeue' => true, 'encoding' => 'auto', 'truncate' => 50000}.to_json
@elrikdante
elrikdante / Accommodation.rb
Created April 12, 2016 04:47 — forked from jeroenr/Accommodation.rb
Use ActiveResource with non-Rails REST API
class Accommodation < ActiveResource::Base
class << self
def element_path(id, prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
"#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
end
def collection_path(prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
"#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
@elrikdante
elrikdante / shallow_nested_routes.rb
Created April 12, 2016 04:48 — forked from slamotte/shallow_nested_routes.rb
Allows ActiveResource to be used with shallow nested routes.
module ShallowNestedRoutes
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
# Pass in the name of the parent class
def set_shallow_nested_route_parent(parent)
parent = parent.to_s
# Override these methods so they set the prefix path before a call and reset it afterward.
@elrikdante
elrikdante / ShopifyAPICallLimit.rb
Created April 12, 2016 04:51 — forked from resistorsoftware/ShopifyAPICallLimit.rb
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.
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
@elrikdante
elrikdante / geocode_coordinates.rb
Created May 1, 2016 02:09 — forked from ole/geocode_coordinates.rb
Geocodes addresses on the command line and print the geo coordinates (latitude and longitude). See http://oleb.net/blog/2014/01/geocoding-automator-service/ for more info on how I am using this script.
#!/usr/bin/env ruby
# Determines the coordinates (latitude and longitude) of the places or
# addresses passed as arguments (either on the command line or via stdin)
# and prints the results.
# This script requires the Ruby Geocoder gem by Alex Reisner
# (http://www.rubygeocoder.com).
# To install the gem, run this command from a Terminal session:
#
@elrikdante
elrikdante / index.html
Created May 25, 2016 06:17 — forked from RickWong/react.html
Write React apps in 1 HTML file.
<html>
<body>
<div id="react-root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react-with-addons.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react-dom.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.5.2/redux.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.7.7/babel.min.js"></script>
<script id="App" type="text/template">
const App = ({name}) => {