Skip to content

Instantly share code, notes, and snippets.

View sgruhier's full-sized avatar

Sébastien Gruhier sgruhier

  • https://xilinus.com
  • Saint-Paul en Forêt
  • X @sgruhier
View GitHub Profile
@netzpirat
netzpirat / 0_README.md
Created November 12, 2010 10:42
Continuous CoffeeScript testing with Guard and Jasmine

Continuous CoffeeScript testing with Guard and Jasmine

This Gist shows how to set up a Rails project to practice BDD with CoffeeScript, Guard and Jasmine. You can see this setup in action on Vimeo

  • Install Gems with Bundler with bundle install
  • Define your guards with mate Guardfile
  • Initialize Jasmine with bundle exec jasmine init
  • Configure Jasmine with mate spec/support/yasmine.ym
  • Start Guard with bundle exec guard
@coldnebo
coldnebo / rails_trace.rb
Last active December 1, 2018 08:10
This Rack middleware for Rails3 lets you see a call-trace of the lines of ruby code in your application invoked during a single request. Only code within your app is considered (i.e. in the /app folder). This expands on my previous attempt (https://gist.github.com/3077744). Example of output in comments below.
require 'singleton'
# outputs a colored call-trace graph to the Rails logger of the lines of ruby code
# invoked during a single request.
#
# Example:
#
# 1) Make sure this file is loaded in an initializer
#
# 2) Add the following to your application.rb in Rails3:
@nz
nz / gist:6322673
Created August 23, 2013 18:46
Basic sketch for renaming an index in Elasticsearch
# create an index with some state (in this case, a mapping)
curl -X POST localhost:9200/test-original -d '{"mappings":{"wine":{"properties":{"designation":{"type":"string"},"full_name":{"type":"string"},"winery":{"type":"string"},"style":{"index":"no","type":"string"},"vintage":{"index":"no","type":"string"},"restaurant_ids":{"index":"no","type":"string"},"appellation":{"type":"string"},"vineyard_name":{"type":"string"},"variety_id":{"index":"no","type":"string"},"country":{"type":"string"}}}}}'
# => {"ok":true,"acknowledged":true}
# verify the mapping
curl localhost:9200/test-original/_mapping
# => {"test-original":{"wine":{"properties":{"appellation":{"type":"string"},"country":{"type":"string"},"designation":{"type":"string"},"full_name":{"type":"string"},"restaurant_ids":{"type":"string","index":"no"},"style":{"type":"string","index":"no"},"variety_id":{"type":"string","index":"no"},"vineyard_name":{"type":"string"},"vintage":{"type":"string","index":"no"},"winery":{"type":"string"}}}}}
# copy the inde
anonymous
anonymous / oshi.rb
Created July 8, 2010 08:18
require 'rubygems'
require 'eventmachine'
require 'em-websocket'
require 'json'
class Connection
attr_accessor :socket, :user_id
def initialize(socket, user_id)
@socket = socket
@maccman
maccman / juggernaut_channels.rb
Created June 26, 2012 04:56
Sinatra Server Side Event streaming with private channels.
# Usage: redis-cli publish message.achannel hello
require 'sinatra'
require 'redis'
conns = Hash.new {|h, k| h[k] = [] }
Thread.abort_on_exception = true
get '/' do
@mislav
mislav / geoip_service.rb
Created September 3, 2012 11:48
Simple GeoIP service class using freegeoip.net and Faraday
require 'faraday_middleware'
require 'hashie/mash'
# Public: GeoIP service using freegeoip.net
#
# See https://github.com/fiorix/freegeoip#readme
#
# Examples
#
# res = GeoipService.new.call '173.194.64.19'
@lancejpollard
lancejpollard / index.md
Created May 22, 2012 06:32
Notes on Ember.js overcomplicating...

Some random notes on the pangs of ember. Will be expanding as they are uncovered.

Building a form

Say you have a form that maps to a model, something like:

<form>
  <fieldset>
    <legend>Who are you?</legend>
@carlzulauf
carlzulauf / geodist.rb
Created February 2, 2012 16:57
Ruby haversine distance method, in miles
def geodist(a, b)
rads = Math::PI/180
# 7926.3352 is diameter of earth in miles
7926.3352 * Math.asin(
Math.sqrt(
Math.sin( (b[1] - a[1])*rads / 2 )**2 *
Math.cos( a[0] * rads ) *
Math.cos( b[0] * rads ) +
Math.sin( (b[0] - a[0])*rads / 2 )**2
)
# Extend jQuery objects with Underscore collection methods.
#
# Each collection method comes in two flavors: one prefixed
# with _, which yields a bare DOM element, and one prefixed
# with $, which yields a jQuery-wrapped element.
#
# So if `this` is a jQuery object, instead of:
#
# _.max @, (el) -> $(el).height()
#
@abtris
abtris / zend-mail-example
Created April 12, 2011 17:41
Mock Smtp example
<?php
require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';
$config = array();
$config['host'] = "localhost";
$config['port'] = 1025;
$config['username'] = "";
$config['password'] = "";