Skip to content

Instantly share code, notes, and snippets.

View DanielBlanco's full-sized avatar

Daniel Blanco Rojas DanielBlanco

View GitHub Profile
@DanielBlanco
DanielBlanco / server-reboot
Created November 24, 2014 19:21
Restart resque workers after server reboot
#!/bin/bash
# This is an sample file, put a copy of this file inside /shared/bin
# I'm assuming a capistrano directory structure under /var/www/my-project/
#
# Called by crontab when the server reboots
#
# To use this file execute with root privileges:
# crontab -e
#
# then add this line:
@DanielBlanco
DanielBlanco / prepare-commit-msg
Created October 16, 2015 16:44
git hook to append Jira ticket
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master)
fi
JIRA_SERVER=$(git config jira.server)
BRANCH_NAME=$(git symbolic-ref --short HEAD)
@DanielBlanco
DanielBlanco / pre-push
Created November 8, 2016 16:17
Git hook to prevent pushing to master mistakes.
#!/bin/bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
read -p "You're about to push master, is that what you intended? [y|n] " -n 1 -r < /dev/tty
echo
if echo $REPLY | grep -E '^[Yy]$' > /dev/null
@DanielBlanco
DanielBlanco / prepare-commit-msg
Created November 14, 2016 14:39
Git hook in ruby code to insert a JIRA link when commiting.
#!/usr/bin/env ruby
# This way you can customize which branches should be skipped when
# prepending commit message.
message_file = ARGV[0]
branches_to_skip = (ENV['BRANCHES_TO_SKIP'] || 'master').split(' ')
original_message = File.read(message_file)
current_branch = `git symbolic-ref --short HEAD`
# Don't do anything if the commit already has a link i.e. in the case of --amend
@DanielBlanco
DanielBlanco / CAM-11198.rb
Created January 18, 2017 19:57
Checks email content differences.
#!/usr/bin/env ruby
# See https://workflow.advisory.com/browse/CAM-11198
if __FILE__ != $0
exit 0
end
$stderr.sync = true
require "optparse"
require 'test_helper'
# Make sure to turn `self.use_transactional_fixtures` to false.
#
# Also, run this before testing:
# $ rake db:test:prepare && rake db:test:preload && rake log:clear
#
class AppointmentRaceConditionTest < ActiveSupport::TestCase
context ".build_new!" do
@DanielBlanco
DanielBlanco / spotify.scpt
Created June 7, 2017 02:22
Returns the name & artist of the current Spotify track
if application "Spotify" is running then
tell application "Spotify"
set theName to name of the current track
set theArtist to artist of the current track
set theAlbum to album of the current track
set theUrl to spotify url of the current track
try
return "♫ " & theName & " - " & theArtist
on error err
end try
@DanielBlanco
DanielBlanco / 0_reuse_code.js
Created September 8, 2017 06:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@DanielBlanco
DanielBlanco / replace-conditional-with-polymorphism.rb
Last active September 21, 2017 17:31
Replace Conditional with Polymorphism
class MountainBike
def price
case @type_code
when :rigid
(1 + @commission) * @base_price
when :front_suspension
(1 + @commission) * @base_price + @front_suspension_price
when :full_suspension
(1 + @commission) * @base_price + @front_suspension_price +
@rear_suspension_price