Skip to content

Instantly share code, notes, and snippets.

View olivierlacan's full-sized avatar

Olivier Lacan olivierlacan

View GitHub Profile
@gruber
gruber / Liberal Regex Pattern for All URLs
Last active May 6, 2024 21:38
Liberal, Accurate Regex Pattern for Matching All URLs
The regex patterns in this gist are intended to match any URLs,
including "mailto:foo@example.com", "x-whatever://foo", etc. For a
pattern that attempts only to match web URLs (http, https), see:
https://gist.github.com/gruber/8891611
# Single-line version of pattern:
(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
#!/bin/bash
if [ -z "$1" ]; then
wdir="."
else
wdir=$1
fi
for f in $( find . -name '*.erb' ); do
out="${f%.erb}.haml"
if [ -e $out ]; then
@joshed-io
joshed-io / example_group.rb
Created July 14, 2011 01:16
Easiest possible RSpec Performance Test w/ Scenarios
# here's a quick recipe to run a performance test
# with this method, you can:
#-> easily choose the examples you want included from your existing specs
#-> define the target number of total iterations you'd like, no limit
#-> tune the transaction mix by specifying frequency metadata for each example
#-> be happy that the transaction mix is fairly homogeneous over the test interval
# (ideally you'd run this with acceptance (webrat/capybara) specs, but you
# could employ this technique for any rspec test)
@olivierlacan
olivierlacan / sublime-text-2-settings.json
Last active January 11, 2024 15:38
Basic Sublime Text 2 settings for Rails development
{
"use_simple_full_screen": false,
// calculates indentation automatically when pressing enter
"auto_indent": true,
// sets the colors used within the text area (default)
// see https://github.com/olivierlacan/monokaim to download
// the customized Monokai I use.
"color_scheme": "Packages/Color Scheme - Default/Monokaim.tmTheme",
@clintel
clintel / gist:1155906
Created August 19, 2011 02:40
Fenced code in bullet lists with GitHub-flavoured MarkDown??

Fenced code blocks inside ordered and unordered lists

  1. This is a numbered list.

  2. I'm going to include a fenced code block as part of this bullet:

    Code
    More Code
    
@olivierlacan
olivierlacan / syntax_highlighting.py
Created August 31, 2011 14:47 — forked from JeanMertz/syntax_highlighting.py
Ruby on Rails syntax highlight switcher for Sublime Text 2
# ======================================================================================= #
# NOTE: This is relatively outdated, you should use the DetectSyntax package
# from Package Control instead: http://wbond.net/sublime_packages/community#sort-installs
# ======================================================================================= #
# Instructions: put this inside of the following folder on a Mac:
# /Users/<yourusername>/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/
# ======================================================================================= #
import sublime, sublime_plugin
import os
@olivierlacan
olivierlacan / launch_sublime_from_terminal.markdown
Created September 5, 2011 15:50
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

require "rack/contrib/try_static"
use Rack::TryStatic, :root => "build", :urls => %w[/], :try => ['index.html', '/index.html']
require "rack/contrib/static_cache"
use Rack::StaticCache, :urls => ['/'], :root => 'build'
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else

Fibur

Fibur is a library that allows concurrency during Ruby I/O operations without needing to make use of callback systems. Traditionally in Ruby, to achieve concurrency during blocking I/O operations, programmers would make use of Fibers and callbacks. Fibur eliminates the need for wrapping your I/O calls with Fibers and a callback. It allows you to write your blocking I/O calls the way you normally would, and still have concurrent execution during those I/O calls.

Example

Say you have a method that fetches data from a network resource: