Skip to content

Instantly share code, notes, and snippets.

View estahn's full-sized avatar
👨‍💻
ʕʘ̅͜ʘ̅ʔ – ʕ•̫͡•ʕ*̫͡*ʕ•͓͡•ʔ-̫͡-ʕ•̫͡•ʔ

Enrico Stahn estahn

👨‍💻
ʕʘ̅͜ʘ̅ʔ – ʕ•̫͡•ʕ*̫͡*ʕ•͓͡•ʔ-̫͡-ʕ•̫͡•ʔ
View GitHub Profile
aws ec2 describe-instances \
--filters Name=dns-name,Values=ec2-12-345-678-90.myregion.compute.amazonaws.com \
| jq '.Reservations [] .Instances [] .InstanceId' \
| xargs -n1 aws ec2 get-console-output --instance-id \
| jq '.Output'
aws ec2 describe-instances \
--filters Name=dns-name,Values=ec2-12-345-678-90.myregion.compute.amazonaws.com \
| jq '.Reservations [] .Instances [] .InstanceId'
@estahn
estahn / postgresql_add_primary_key.sql
Created October 4, 2013 13:10
PostgreSQL - Add primary key to an existing Table
ALTER TABLE "public"."foo" ADD COLUMN "id" INTEGER;
CREATE SEQUENCE "public"."foo_id_seq";
UPDATE foo SET id = nextval('"public"."foo_id_seq"');
ALTER TABLE "public"."foo" ALTER COLUMN "id" SET DEFAULT nextval('"public"."foo_id_seq"');
ALTER TABLE "public"."foo" ALTER COLUMN "id" SET NOT NULL;
ALTER TABLE "public"."foo" ADD UNIQUE ("id");
ALTER TABLE "public"."foo" DROP CONSTRAINT "foo_id_key" RESTRICT;
ALTER TABLE "public"."foo" ADD PRIMARY KEY ("id");
@estahn
estahn / remove_old_chrome_versions.sh
Created October 3, 2013 11:59
Free up disk space by deleting older Google Chrome versions
#!/bin/bash
current=`find /Applications/Google\ Chrome.app/Contents/Versions -maxdepth 1 -type d -name "*.*.*.*" | sort | tail -1 | xargs -I% basename %`
echo Deleting old Chrome versions and keep $current
find /Applications/Google\ Chrome.app/Contents/Versions -maxdepth 1 -type d -name "*.*.*.*" -not -iname "$current" -exec rm -rf {} +
@estahn
estahn / gist:5002290
Created February 21, 2013 05:13
Our current framework is heavily using a "Factory" to instantiate classes on the fly. It used ReflectionClass::newInstanceArgs() for classes with arguments. Since Reflection is quite slow it decreased our performance. The gist shows a solution that is less beautiful but more performant.
<?php
class Factory
{
// ...
/**
* Helper to instantiate objects with dynamic constructors.
*
@estahn
estahn / svn-remove-stale-branches.sh
Created December 2, 2012 07:56
Remove branches that belong to closed tickets
#!/bin/bash
# Base Repository URL
SVN_URL=http://svn-repo-url
# Atlassian Jira URL
JIRA_URL=https://jira-url
# Jira Project Key
PROJECT=project-key
@estahn
estahn / _compass-retina-sprites.scss
Created October 5, 2012 00:32
Using Compass to generate normal and retina sprite maps at once
@mixin all-retina-sprites($map, $map2x) {
@media (min--moz-device-pixel-ratio: 1.5),
(-o-min-device-pixel-ratio: 3/2),
(-webkit-min-device-pixel-ratio: 1.5),
(min-device-pixel-ratio: 1.5),
(min-resolution: 1.5dppx) {
$base-class: sprite-map-name($map);
.#{$base-class}-all-retina-sprites {
@estahn
estahn / rack_hotfix.rb
Created July 8, 2011 09:46
"warning: regexp match /.../n against to UTF-8 string" when running Cucumber
# TODO: Can be removed after updating to rack 1.3.0
module Rack
module Utils
def escape(s)
CGI.escape(s.to_s)
end
def unescape(s)
CGI.unescape(s)
end
end
@estahn
estahn / env.rb
Created July 6, 2011 11:20
Run Cucumber with Selenium RC and a custom Firefox profile
if ENV.key?('SELENIUM_REMOTE')
Capybara.register_driver :selenium do |app|
require 'selenium-webdriver'
profile = Selenium::WebDriver::Firefox::Profile.from_name 'default'
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
Capybara::Selenium::Driver.new(app, { :browser => :remote, :desired_capabilities => capabilities })
end
end
@estahn
estahn / gist:1055981
Created June 30, 2011 10:30
Headless Testing for Continuous Integration with Ruby and Selenium
# Install and run xvfb
apt-get install xvfb
Xvfb -ac :99
# Get Firefox
wget -O firefox-5.0.tar.bz2 "http://download.mozilla.org/?product=firefox-5.0&os=linux&lang=en-US"
tar xfj firefox-5.0.tar.bz2
mv firefox firefox-5.0
# Get Selenium Server