Skip to content

Instantly share code, notes, and snippets.

View suciuvlad's full-sized avatar

Vlad Suciu suciuvlad

View GitHub Profile
@test
Feature: Viewing bulletins
In order to view the content on this website
As a visitor
I want to view bulletins
Background:
Given A Refinery user exists
Scenario: Listing all bulletins
class Article < ActiveRecord::Base
has_one :publication, :as => :publicationable
accepts_nested_attributes_for :publication
end
@suciuvlad
suciuvlad / zsh
Created April 18, 2012 14:56 — forked from tonyjcamp/zsh
zsh Theme
# https://github.com/blinks zsh theme
function _prompt_char() {
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
echo "%{%F{blue}%}±%{%f%k%b%}"
else
echo ' '
fi
}
@suciuvlad
suciuvlad / deferred-img.js
Created November 9, 2012 11:04 — forked from fcalderan/deferred-img.js
Image loader / preloader achieved by deferred objects in jQuery 1.6
/**
* For a current project I need to wait to execute a code until some images have been loaded.
* Beside, I also need to execute a callback (in my specific code I want to show the image
* with a fade-in effect) every time a single image has been loaded.
*
* So basically I used two deferred objects: the nested one which is resolved for a single
* image successfull load event (or when image has been discarded) and the outside one,
* which is resolved when all deferred objects on single images have been resolved or rejected.
*
* This snippet also takes care all frequent issues when trying to load an image (excessive
@suciuvlad
suciuvlad / with_retries.rb
Created November 15, 2012 11:24 — forked from cainlevy/with_retries.rb
with_retries{} helper to easily catch and retry exceptions in Ruby
module Retriable
# This will catch any exception and retry twice (three tries total):
# with_retries { ... }
#
# This will catch any exception and retry four times (five tries total):
# with_retries(:limit => 5) { ... }
#
# This will catch a specific exception and retry once (two tries total):
# with_retries(Some::Error, :limit => 2) { ... }
#
# An abstract base class used to create simple serializers
# for ActiveRecord objects
class BaseSerializer
include Rails.application.routes.url_helpers
attr_reader :serialized_object
def initialize(serialized_object)
@serialized_object = serialized_object
end
desc 'Benchmark funds_raised methods'
ITERATIONS = 1000
task benchmark_sql: :environment do
campaign = Campaign.last
Benchmark.bm do |bm|
bm.report('sql') do
ITERATIONS.times do
@suciuvlad
suciuvlad / gist:a0fb947b430dfaa819d1
Last active August 29, 2015 14:12
upstart config nodejs
#!upstart
description "node.js server"
author "vlad suciu"
start on startup
stop on shutdown
script
export HOME="/root"
@suciuvlad
suciuvlad / gist:495231b8ae8ba8c9a572
Last active August 29, 2015 14:12
monit nginx and upstart services
check process nginx with pidfile "/var/run/nginx.pid"
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
group www-data
if failed port 80 protocol HTTP
request /ok
with timeout 5 seconds
then restart
check process nodejs with pidfile "/var/run/fyves-renderer-8001.pid"
@suciuvlad
suciuvlad / gist:8684220da04d612c38c8
Created December 27, 2014 12:45
nginx load balancing
upstream fyves_renderer {
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}
server {
listen 80;
server_name localhost;