Skip to content

Instantly share code, notes, and snippets.

View RobertBrewitz's full-sized avatar

Robert Brewitz RobertBrewitz

View GitHub Profile
@RobertBrewitz
RobertBrewitz / index.js
Created June 10, 2020 17:49
Acquiring Express Router routes
const req = { method: 'POST', path: '/' };
const res = { send: jest.fn() }
const request = (req, res) => {
return jobs.stack
.find((layer) => {
return (
layer.route.path === req.path &&
layer.route.methods[req.method.toLowerCase()]
);
@RobertBrewitz
RobertBrewitz / gist:5619994
Created May 21, 2013 14:00
development conf for mongodb
# Basic database configuration
dbpath = /usr/local/var/mongodb
port = 27017
bind_ip = 127.0.0.1
logpath = /usr/local/var/log/mongodb/mongodb.log
# logappend = false
# Logging
cpu = true
verbose = true
@RobertBrewitz
RobertBrewitz / gist:5611964
Last active December 17, 2015 12:48
Bash profile
alias mdb="mongod run --rest --config /usr/local/Cellar/mongodb/2.0.2-x86_64/mongod.conf"
alias mdbclear="/bin/echo "" > /usr/local/var/log/mongodb/mongodb.log"
alias mdbquery="egrep -c '\w{5,}ms$' /usr/local/var/log/mongodb/mongodb.log"
alias mdbindex="egrep -c 'nscanned:\w{5,}ms$' /usr/local/var/log/mongodb/mongodb.log"
alias startpg="pg_ctl -D /usr/local/var/postgres -l /usr/local/var/log/postgres/postgres.log start"
alias stoppg="pg_ctl -D /usr/local/var/postgres stop -s -m fast"
alias stoppow="launchctl stop cx.pow.powd"
alias servers="ps aux | egrep 'nginx|php|mongo|mysql|postgres'"
alias mocha="./node_modules/mocha/bin/mocha test/_helper.js"
alias pgstart="pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start"
<div class="b-video-article__video">
<div id="ctl00_WebTvArticleContent_BaseVideoHolder_VideoPlaceHolder_Satellite_Satellite" class="b-satellite cf" style="height: 416px;">
<object type="application/x-shockwave-flash" data="http://www.expressen.se/Static/swf/ExpPlayer.swf?ver=2.2.10.4479" width="100%" height="416" id="ctl00_WebTvArticleContent_BaseVideoHolder_VideoPlaceHolder_Satellite_PlayerPlaceHolder"><param name="allowFullScreen" value="true"><param name="wmode" value="transparent"><param name="flashvars" value="hasPlaylist=true&amp;embedUrl=http://www.expressen.se/Static/swf/ExpPlayer.swf?ver=2.2.10.4479&amp;xmlUrl=http%3A%2F%2Fwww.expressen.se%2FHandlers%2FWebTvHandler.ashx%3Fid%3D4563932&amp;searchUrl=http%3A%2F%2Fwww.expressen.se%2FHandlers%2FWebTvHandler.ashx%3Fid%3D4563932&amp;playerType=portal&amp;auto=true&amp;hasHeader=false"></object>
<meta itemprop="embedURL" content="http://www.expressen.se/Static/swf/ExpPlayer.swf?ver=2.2.10.4479&amp;xmlUrl=http%3a%2f%2fwww.expressen.se%2f
@RobertBrewitz
RobertBrewitz / Iframe_Ad_Resizing
Created September 20, 2012 13:43
Cross site iframe resizing for adserving
<!-- HTML/JS on adhost page -->
<body style="margin:0;padding:0;">
<!-- render ad -->
<script type="text/javascript">
sendAdSize = function(e) {
if (e.origin == "http://publisher.com") {
if(e.data == 'adSize?') {
var adWidth = document.getElementsByTagName("img")[0].width;
var adHeight = document.getElementsByTagName("img")[0].height;
@RobertBrewitz
RobertBrewitz / validates_date
Created August 19, 2012 21:04
Date validation for booking system
...
field :started_at, type: Date
validates_presence_of :started_at, message: 'you have to provide a start-date'
validates_date :started_at, on_or_after: :today, on: :create
validates_date :started_at, is_at: lambda { |_self| _self.started_at_was }, on: :update, if: lambda { |_self| _self.started_at_was.to_date < Time.now.to_date }
validates_date :started_at, on_or_after: :today, on: :update, if: lambda { |_self| _self.started_at_was.to_date >= Time.now.to_date }
field :ended_at, type: Date
validates_presence_of :ended_at, message: 'you have to provide an end-date'
@RobertBrewitz
RobertBrewitz / when_I_fill_in_all_required_object_fields_step.rb
Created August 4, 2012 01:43
Fill in valid data for a model with Capybara and FactoryGirl
When /^I fill in all required "(.*?)" fields$/ do |model|
klass = model.singularize.camelcase.constantize
# Build the class with valid attributes
# Requires valid factory
valid_model = FactoryGirl.build(model.singularize.to_sym)
# Remove ID field(s)
valid_model.attributes.delete("_id") if valid_model.attributes.include?("_id")
valid_model.attributes.delete("id") if valid_model.attributes.include?("id")
@RobertBrewitz
RobertBrewitz / teaching_myself_boos_tda.rb
Created August 3, 2012 10:31
Understanding the BOOS, "Don't ask tell" from a talk at GORUCO 2012
##
# Growing Object Oriented Software
# Tell, don't ask approach
# Tested and learned the principle
class SomeProgram
def self.runit
# Printer is the main purpose
# Later I might want to Log, IM, Email or Ping something about the printing result.
@RobertBrewitz
RobertBrewitz / weekify.sh
Created October 6, 2011 14:36
Sort your download directory into weeks
#! /bin/bash
WEEK=$(/bin/date +%V)
if [ ! -d $HOME/Downloads/week-$WEEK ]; then
mkdir $HOME/Downloads/week-$WEEK
fi
downloadedFiles=($(find $HOME/Downloads -depth 1))
@RobertBrewitz
RobertBrewitz / nginx.baseline.conf
Created July 5, 2011 20:50
Nginx baseline configuration for Amazon EC2 instance after tuning session
user www-data www-data;
pid /var/run/nginx.pid;
worker_rlimit_nofile 58064;
worker_processes 1;
events {
use epoll;
worker_connections 58064;
}