Skip to content

Instantly share code, notes, and snippets.

View langalex's full-sized avatar

Alexander Lang langalex

View GitHub Profile
@langalex
langalex / rest_client_helpers.rb
Created April 16, 2021 11:12
rest-client stub bad request error with RSpec
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|
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
@langalex
langalex / html.html
Last active October 25, 2016 10:03 — forked from thilo/html.html
An example how to use the bots platform to build a custom report
<!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 October 2, 2013 16:45
A data structure to put stuff in and take it out again. NIH syndrome?
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 June 8, 2013 15:51
Turns a series of JPEG files into a video.
#!/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 February 3, 2013 17:35
Extend an object with this module to print out all method calls to it.
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 January 24, 2013 16:44
Parrallel tests with travis-ci
env:
- RUN_TESTS=cucumber
- RUN_TESTS=rspec_testunit
@langalex
langalex / backup.rb
Created August 23, 2012 14:13
Couchbase EBS RAID Backup on Scalarium
#!/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 June 15, 2012 14:37
Logging in to the hotel wifi at Nordic Ruby 2012
# 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 April 21, 2012 23:19
Ruby Script to generate the intro and credits for my Railsgirls Berlin film
# 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"