Skip to content

Instantly share code, notes, and snippets.

@toolmantim
toolmantim / Makefile
Last active December 5, 2022 23:14
An example of using Make instead of Grunt for fast, simple and maintainable front-end asset compilation.
# A simple Makefile alternative to using Grunt for your static asset compilation
#
## Usage
#
# $ npm install
#
# And then you can run various commands:
#
# $ make # compile files that need compiling
# $ make clean all # remove target files and recompile from scratch
@mudge
mudge / unicorn.conf.rb
Last active February 9, 2017 21:55
Unicorn configuration for Rails 3.2 application to log to a different file per worker (to stop logs interleaving with one another).
after_fork do |server, worker|
# Override the default logger to use a separate log for each Unicorn worker.
# https://github.com/rails/rails/blob/3-2-stable/railties/lib/rails/application/bootstrap.rb#L23-L49
Rails.logger = ActiveRecord::Base.logger = ActionController::Base.logger = begin
path = Rails.configuration.paths["log"].first
f = File.open(path.sub(".log", "-#{worker.nr}.log"), "a")
f.binmode
f.sync = true
logger = ActiveSupport::TaggedLogging.new(ActiveSupport::BufferedLogger.new(f))
@niflostancu
niflostancu / wkhtmltopdf.tablesplit.js
Last active February 1, 2024 17:28
WkHtmlToPdf Table Splitting Hack
/**
* WkHtmlToPdf table splitting hack.
*
* Script to automatically split multiple-pages-spanning HTML tables for PDF
* generation using webkit.
*
* To use, you must adjust pdfPage object's contents to reflect your PDF's
* page format.
* The tables you want to be automatically splitted when the page ends must
* have a class name of "splitForPrint" (can be changed).
@Mithrandir0x
Mithrandir0x / gist:3639232
Created September 5, 2012 16:15
Difference between Service, Factory and Provider in AngularJS
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@shunchu
shunchu / convert-seconds-into-hh-mm-ss-in-ruby.rb
Created July 25, 2012 07:58
Convert seconds into HH:MM:SS in Ruby
t = 236 # seconds
Time.at(t).utc.strftime("%H:%M:%S")
=> "00:03:56"
# Reference
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time
@bbonamin
bbonamin / drag_drop.rb
Created July 17, 2012 14:18
Capybara drag and drop
shared_examples_for "driver with javascript support" do
before { @driver.visit('/with_js') }
describe '#find' do
it "should find dynamically changed nodes" do
@driver.find('//p').first.text.should == 'I changed it'
end
end
describe '#drag_to' do
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active April 25, 2024 06:23
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@natritmeyer
natritmeyer / Usage.txt
Last active January 16, 2017 01:56
JUnit formatter for RSpec
NOTE: I've created a gem based on this: https://github.com/natritmeyer/yarjuf
---------
rspec my_spec.rb -r ./junit.rb -f JUnit -o results.xml
@fred
fred / active_admin.rb
Created May 2, 2012 08:10
extend active admin to prettier boolean values
# It extends activeadmin to show pretty boolean values
#
# config/initializers/active_admin.rb
module ActiveAdmin
module Views
class TableFor
def bool_column(attribute)
column(attribute){ |model| model[attribute] ? '✔'.html_safe : '✗'.html_safe }
end
@jaryl
jaryl / chosen.rb
Created February 6, 2012 08:56 — forked from thijsc/gist:1391107
Select item from chosen js select with Capybara-Webkit
def select_from_chosen(item_text, options)
field_id = find_field(options[:from])[:id]
within "##{field_id}_chzn" do
find('a.chzn-single').click
input = find("div.chzn-search input")
item_text.each_char do |char|
input.base.invoke('keypress', false, false, false, false, char.ord, nil);
end
find('ul.chzn-results').click
input.base.invoke('keypress', false, false, false, false, 40, nil); # down arrow