Skip to content

Instantly share code, notes, and snippets.

@electronicbites
electronicbites / unicorn
Last active March 23, 2016 18:47
initd unicorn script fauna
#!/bin/bash
# /etc/init.d/unicorn
# ### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $network $remote_fs $local_fs
# Required-Stop: $network $remote_fs $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Stop/start unicorn
Manager::BookingsController#data 0.044 5,509 5062 SQL, SQL, ...
statement/Postgres/ActiveRecord::SessionStore::Session/find 0.045 1 1 SQL
statement/Postgres/Restaurant/find 0.048 1 1 SQL
statement/Postgres/Restaurant/find 0.051 1 1 SQL
statement/Postgres/Table/find 0.054 1 1 SQL
statement/Postgres/Reservation/find 0.062 2 2 SQL
statement/Postgres/Opening/find 0.066 1 1 SQL
statement/Postgres/Reservation/find 0.070 2 2 SQL
statement/Postgres/Opening/find 0.074 1 1 SQL
statement/Postgres/Offering/find 0.082 1 1 SQL
@electronicbites
electronicbites / console
Created October 14, 2015 10:15
codeclimate analyze output
➜ finedining-server git:(develop) docker run \
> --interactive --tty --rm \
> --env CODE_PATH="$PWD" \
> --volume "$PWD":/code \
> --volume /var/run/docker.sock:/var/run/docker.sock \
> --volume /tmp/cc:/tmp/cc \
> codeclimate/codeclimate analyze
fatal: bad config file line 1481 in .git/config
fatal: bad config file line 1481 in .git/config
#create mango pay user (dummy)
user_id = begin
mango_user = MangoPay::NaturalUser.create({'FirstName' => 'DummyFirstName', 'LastName' => 'DummyLastName',
'Email' => '[email protected]', 'Birthday' => 1300186358,
'Nationality' => FFaker::Address.country_code,
'CountryOfResidence' => FFaker::Address.country_code,
'Tag' => "Guest of #{@restaurant.name}"})
mango_user['Id']
rescue SocketError => e
module Bookings
class BookingsController < ApplicationController
include GuestBookingSteps
layout 'bookings/application'
rescue_from Wicked::Wizard::InvalidStepError, with: :foo
DEFAULT_GUEST_COUNT = "2"
......
end
@electronicbites
electronicbites / gist:c0f0f3e799bce10e1e82
Last active August 29, 2015 14:02
Bcrypt Encryption, Decrpytion copied from devise
# constant-time comparison algorithm to prevent timing attacks
def secure_compare(a, b)
return false if a.blank? || b.blank? || a.bytesize != b.bytesize
l = a.unpack "C#{a.bytesize}"
res = 0
b.each_byte { |byte| res |= byte ^ l.shift }
res == 0
end
@electronicbites
electronicbites / install-notes.txt
Last active August 29, 2015 13:57
ffmpeg installation on ubuntu 12
sudo apt-get update
sudo apt-get -y install libtag1-dev autoconf automake build-essential libass-dev libgpac-dev \
libsdl1.2-dev libtheora-dev libtool libvorbis-dev pkg-config texi2html zlib1g-dev -y
mkdir ~/ffmpeg_sources
#ysam
cd ~/ffmpeg_sources
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
% ------- Define procedures----
/inch {72 mul} def
/box % stack: x y => ---
{ newpath moveto
1 inch 0 rlineto 0 1 inch
rlineto −1 inch 0
rlineto closepath } def
/fillbox % stack: grayvalue => ---
{ setgray fill } def
@electronicbites
electronicbites / gist:6831978
Last active December 24, 2015 16:59
display seconds as hh:mm:ss
def to_dot_time(seconds)
hours = seconds / 3600
seconds -= hours * 3600
minutes = seconds / 60
seconds -= minutes * 60
(hours > 0 ? [hours, minutes, seconds] : [minutes, seconds]).join(":")
end
@electronicbites
electronicbites / resque
Last active January 17, 2017 09:48
init.d script for resque / ubuntu 8
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: resque
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: resque - a Redis-backed Ruby library for creating background jobs