Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexander Lang langalex

View GitHub Profile
@langalex
langalex / rest_client_helpers.rb
Created Apr 16, 2021
rest-client stub bad request error with RSpec
View rest_client_helpers.rb
module RestClientHelpers
def bad_request_error(json_body)
request = double(:request, redirection_history: nil)
net_http_res = double(:response, to_hash: {}, code: 400)
response = RestClient::Response.create(json_body.to_json, net_http_res, request)
RestClient::BadRequest.new response, 400
end
end
RSpec.configure do |c|
View controllers.application\.js
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
@langalex
langalex / html.html
Last active Oct 25, 2016 — forked from thilo/html.html
An example how to use the bots platform to build a custom report
View html.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scaleable=no">
<title>Example Report</title>
</head>
<body>
<div class="page-header">
<h1>Example Report</h1>
@langalex
langalex / bag.rb
Created Oct 2, 2013
A data structure to put stuff in and take it out again. NIH syndrome?
View bag.rb
class Bag
def initialize
@contents = Hash.new(0)
end
def put_in(names, amount)
@contents[[names].flatten] += amount
end
def take_out(name, amount)
@langalex
langalex / make_timelapse.bash
Created Jun 8, 2013
Turns a series of JPEG files into a video.
View make_timelapse.bash
#!/bin/bash
# usage: cd <directory full of JPGs> && make_timelapse
mkdir ./captures
COUNTER=0;
for i in `find . -name '*.JPG'` ;
do
#Write the filename to be friendly with ffmpeg's odd filename input
FILENAME=`printf '%04d.jpg' $COUNTER`
cp $i ./captures/$FILENAME
@langalex
langalex / log_calls.rb
Created Feb 3, 2013
Extend an object with this module to print out all method calls to it.
View log_calls.rb
module LogCalls
def self.extended(b)
b.class_eval do
(b.methods - Object.methods).each do |m|
define_method "#{m.to_s.gsub(/[\?\!=]/, '')}_with_logging#{m.to_s[/[\?\!=]/]}" do |*args|
puts m
send "#{m.to_s.gsub(/[\?\!=]/, '')}_without_logging#{m.to_s[/[\?\!=]/]}", *args
end
alias_method_chain m.to_sym, :logging
end
@langalex
langalex / .travis.yml
Created Jan 24, 2013
Parrallel tests with travis-ci
View .travis.yml
env:
- RUN_TESTS=cucumber
- RUN_TESTS=rspec_testunit
@langalex
langalex / backup.rb
Created Aug 23, 2012
Couchbase EBS RAID Backup on Scalarium
View backup.rb
#!/usr/bin/env ruby
# Backs up the mounted EBS RAID storage used by Couchbase of an EC2 instance using the Scalarium API.
#
# Before running the snapshot it stops Couchbase disk writes and then freezes the file system.
# File system must be XFS.
#
# Usage: Backup.new(<scalarium api token>, <mount point for ebs raid>, <name of couchbase bucket to back up>).start (must be run on the EC2 instance).
require 'rest_client'
@langalex
langalex / login.sh
Created Jun 15, 2012
Logging in to the hotel wifi at Nordic Ruby 2012
View login.sh
# take one of the wifi cards from the bar and fill in the blanks
# this wil log you into the hotel wifi without having to type in the username/password every time
curl -XPOST -d "username=<username>&password=<password>&operator=homerun.telia.com" https://login.homerun.telia.com/sd/login
@langalex
langalex / credits.rb
Created Apr 21, 2012
Ruby Script to generate the intro and credits for my Railsgirls Berlin film
View credits.rb
# encoding: utf-8
require_relative 'type'
require 'yaml'
30.times {puts}
sleep 2
command '"That was: #{event.name} #{Location.current} #{Date.today.year}"', "=> That was: Railsgirls Berlin 2012"