Skip to content

Instantly share code, notes, and snippets.

View ssaunier's full-sized avatar

Sébastien Saunier ssaunier

View GitHub Profile
@ssaunier
ssaunier / embedded_video_helper.rb
Created February 26, 2014 19:04
Youtube embed video Helper
require "uri"
require "cgi"
class ApplicationHelper
def embedded_video(url, options = {})
if url
# TODO: Handle other sources than Youtube video
params = CGI::parse(URI.parse(url).query || "")
if params["v"]
embedded_url = "//www.youtube.com/embed/#{params["v"].first}"
@ssaunier
ssaunier / minitest_rake_runner.rb
Created March 22, 2014 19:43
A rake runner for minitest, capturing the outcome of the test
# app/services/minitest_rake_runner.rb
require 'open3'
class MinitestRakeRunner
attr_reader :stdout_lines
class RakefileMissingError < StandardError; end
PATTERN = /(?<tests>\d+) (tests|runs), (?<assertions>\d+) assertions, (?<failures>\d+) failures, (?<errors>\d+) errors, (?<skips>\d+) skips/
@ssaunier
ssaunier / github_pages_repo.sh
Last active August 29, 2015 14:00
Quickly create a Github Pages repo
# What is your GitHub username? & your project name? Change with your own
GITHUB_USERNAME="ssaunier"
PROJECT_NAME="minesweep"
# We can create GitHub repo from the terminal, with https://github.com/github/hub
# It's really convinient. You can download it with:
brew install hub
# Say you want to work on a minesweep, create the repo:
mkdir -p ~/code/$GITHUB_USERNAME/$PROJECT_NAME && cd $_
@ssaunier
ssaunier / premiere_classe_wufoo.css
Last active August 29, 2015 14:00
External CSS for Premiere Classe Registration form
body {
font-size: 16px;
}
.wufoo li.focused {
background: none;
}
.wufoo input.text, .wufoo textarea.textarea {
background: none !important;
@ssaunier
ssaunier / cities.rb
Created May 10, 2014 07:41
FrenchTech cities
require 'yaml'
require "octokit"
client = Octokit::Client.new :access_token => `cat ~/.gist`
results = {}
# Cities from http://fr.wikipedia.org/wiki/Liste_des_communes_de_France_les_plus_peupl%C3%A9es
cities = File.readlines("cities.txt")
@ssaunier
ssaunier / like.rb
Created June 1, 2014 23:40
User like Postcards
class Like < ActiveRecord::Base
belongs_to :user
belongs_to :postcard
end
@ssaunier
ssaunier / email_parser.rb
Created June 11, 2014 08:49
Email parser
EMAIL_PATTERN = /([^\.@]+)(\.([^@]+))?@([^@]+)/
def parse_email(email)
groups = EMAIL_PATTERN.match(email)
if groups.nil?
raise ArgumentError.new("'#{email}' is not a valid email address")
else
firstname = groups[1]
lastname = groups[3]
email_domain = groups[4]
@ssaunier
ssaunier / subl_as_git_editor.sh
Created July 9, 2014 09:13
Set sublime as the git editor
subl_path=`alias subl | grep -o '\(/[a-zA-Z0-9. ]\+\)\+'`
git config --global core.editor "'$subl_path' -n -w"
@ssaunier
ssaunier / cat.rb
Created October 17, 2014 07:32
cat.rb
class Cat
def initialize(name, color)
@name = name
@color = color
@alive = true
@color_history = [ color ]
end
attr_reader :name, :color, :color_history
@ssaunier
ssaunier / app.rb
Last active August 29, 2015 14:07
Todo Manager - 17 octobre 2014 - Promo 4 de http://www.lewagon.org
require_relative "task_repository"
require_relative "display"
require_relative "controller"
# Creer fausse base de données
task_repository = TaskRepository.new
# Creer un Display
display = Display.new