Skip to content

Instantly share code, notes, and snippets.

View mcls's full-sized avatar
🏠
Working from home

Maarten Claes mcls

🏠
Working from home
View GitHub Profile
@mcls
mcls / routes.rb
Created January 4, 2021 18:10
Rails Routes class
# Make it easier to call rails routes from anywhere
class Routes
include Rails.application.routes.url_helpers
delegate :asset_path, :image_path, to: :controller_helpers
protected
def controller_helpers
ActionController::Base.helpers
@mcls
mcls / cors_headers.sh
Created June 11, 2018 11:22
CORS headers checking script
#!/usr/bin/env bash
#
# Minimimal example:
#
# cors_headers https://www.google.com
#
# Example with origin (-o):
#
# cors_headers -o localhost https://www.google.com
#
@mcls
mcls / database_cleaner.rb
Last active December 16, 2016 11:29
DatabaseCleaner gem setup for RSpec
# file: spec/support/database_cleaner.rb
require 'database_cleaner'
# More info: https://github.com/DatabaseCleaner/database_cleaner
RSpec.configure do |config|
config.before(:suite) do
# Ensure a clean slate
DatabaseCleaner.clean_with(:truncation)
end
# Allows you to run rspec with SCREENSHOT=1 to take screenshots.
# The images are stored under tmp/screenshots/
#
module ScreenshotHelpers
SCREENSHOT_KEY = 'SCREENSHOT'
DIR_PATH = Rails.root.join('tmp', 'screenshots')
# @example
# screenshot("dashboard_clean_slate")
# screenshot("shopping_cart_multiple_items")
@mcls
mcls / vcr_rspec.rb
Last active November 24, 2016 15:20
VCR helpers and config for use with RSpec
# file: spec/support/vcr.rb
require 'vcr'
# More info:
# - https://github.com/vcr/vcr
# - https://relishapp.com/vcr/vcr/docs
VCR.configure do |config|
config.cassette_library_dir = File.expand_path(File.join(__dir__, "..", "support", "vcr_cassettes"))
@mcls
mcls / name_generator.rb
Created August 4, 2016 14:17
NameGenerator
# usage: NameGenerator.generate
#
module NameGenerator
def self.generate
[ADVERBS.sample, ADJECTIVES.sample, NAMES.sample].join("_")
end
NAMES = [
"ai",
"analytics",

Keybase proof

I hereby claim:

  • I am mcls on github.
  • I am mcls (https://keybase.io/mcls) on keybase.
  • I have a public key whose fingerprint is D608 CAAE 524B 038A 4BB5 BD72 035B 4046 E70B 8644

To claim this, I am signing this object:

@mcls
mcls / .gitconfig
Created February 17, 2014 15:34
Git aliases
[alias]
st = status -bs
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
b = branch -v
co = checkout
undo = reset --soft HEAD^
cm = commit -v
today = log --since=midnight --author='Maarten Claes' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
@mcls
mcls / syn.go
Created January 8, 2014 20:49
Searches for synonyms online
package main
import (
"os"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/codegangsta/cli"
)
func findSynonyms(query string) string {
@mcls
mcls / rtmp_meta.rb
Created May 14, 2013 14:10
Quick hack to fetch duration of RTMP stream using rtmpdump v2.4.
require 'forwardable'
module RtmpMeta
class Parser
PATTERN = /duration\s+(?<duration>\d+\.?\d+)$/
attr_reader :raw_data
def initialize raw_data
@raw_data = raw_data
end