Skip to content

Instantly share code, notes, and snippets.

View elrikdante's full-sized avatar

Dante Haskell Elrik elrikdante

View GitHub Profile
@elrikdante
elrikdante / CakePHP Comet Lib
Created August 23, 2013 16:23
A Comet implementation in Php. The first callback should be some function that's waiting for an external result, which it will return (otherwise, it should not return anything), the second callback is the function to invoke with the result of the first callback. Thats it.
<?php
define('MESSAGE_POLL_MICROSECONDS', 500000);
define('MESSAGE_TIMEOUT_SECONDS', 60);
define('MESSAGE_TIMEOUT_SECONDS_BUFFER', 5);
class Comet {
public $work;
public $callback;
public static function &init($work, $callback) {
==> Downloading http://www.haskell.org/ghc/dist/7.8.1-rc2/ghc-7.8.0.20140228-src.tar.bz2
######################################################################## 100.0%
==> Downloading https://www.haskell.org/ghc/dist/7.8.1-rc2/ghc-7.8.0.20140228-x86_64-apple-darwin-lion.tar.bz2
######################################################################## 100.0%
==> ./configure --prefix=/private/tmp/ghc-khpP/ghc-7.8.0.20140228/subfo --with-gcc=clang
==> make -j1 install
==> ./configure --prefix=/usr/local/Cellar/ghc/7.8.0.20140228 --build=x86_64-apple-darwin --with-gcc=clang
==> make
libraries/Cabal/Cabal/Distribution/Version.hs:700:19:
Parse error in pattern: Parse.skipSpaces
@elrikdante
elrikdante / gist:46c0ebf615f72d76d4b2
Last active August 29, 2015 14:18
NGINX log scraper for time/route based data aggregation
#!/usr/bin/env ruby
require 'json'
require 'time'
data = []
counts = Hash.new(0)
uniq_paths = []
time_series = Hash.new do |h,k|
h[k] = Hash.new(0)
-- |
module Main where
import Control.Monad.State
data Closure i o = R (i -> (o, Closure i o))
data Mark = X | O deriving (Show, Read, Ord)
instance Eq Mark where
X == X = True
O == O = True
@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)}"