Skip to content

Instantly share code, notes, and snippets.

View vjt's full-sized avatar
💭
looking at the stars

Marcello Barnaba vjt

💭
looking at the stars
View GitHub Profile
@vjt
vjt / camelize.js
Created February 15, 2011 15:50
String.camelize
// I thought I needed it, but I didn't need it anymore,
// but I already implemented it. So, here we go, if you
// ever would need a Javascript camelize implementation
// you can freely use this :-).
// - [email protected] Tue Feb 15 16:49:52 CET 2011
jQuery.extend (String.prototype, {
camelize: function () {
return this.replace (/(?:^|[-_])(\w)/g, function (_, c) {
@vjt
vjt / bench.rb
Created March 9, 2011 10:11
Benchmark made easy
# Benchmark made easy
#
# bench { stuff } # runs stuff 1000 times and returns the real time spent doing it
# bench(100) { stuff } # as above, but 100 times.
#
# - [email protected] - public domain
module Kernel
def bench(n = 1000, &block)
raise ArgumentError, 'What should I benchmark?' unless block
@vjt
vjt / service.rb
Created March 10, 2011 13:14
The simplest foreground Rails service framework you'll ever see
# vim: ft=ruby
#
# Usage:
#
# Save as ./script/service
#
# Create your ./script/job containing:
#
# load './script/service'
# Service.new do
@vjt
vjt / less-to-css-with-braces-on-their-own-line.diff
Created March 20, 2011 10:46
Applies to sass-3.1.0.alpha.221. Make the closing curly braces stand on their own line. - [email protected]
--- lib/sass/tree/visitors/convert.rb.orig 2011-03-20 05:32:23.000000000 +0100
+++ lib/sass/tree/visitors/convert.rb 2011-03-14 14:57:45.000000000 +0100
@@ -21,7 +21,7 @@
def visit_children(parent)
@tabs += 1
return @format == :sass ? "\n" : " {}\n" if parent.children.empty?
- (@format == :sass ? "\n" : " {\n") + super.join.rstrip + (@format == :sass ? "\n" : " }\n")
+ (@format == :sass ? "\n" : " {\n") + super.join.rstrip + (@format == :sass ? "\n" : "\n#{' '*((@tabs-1)*2)}}\n")
ensure
@tabs -= 1
@vjt
vjt / post-checkout
Created March 23, 2011 11:07
post-checkout hook to recursively checkout Git gem dependencies in Gemfile.lock
#!/usr/bin/env ruby
exit 0 if ARGV[0] == ARGV[1] # Not switching branches
require 'rubygems'
require 'bundler'
require 'pathname'
root = Pathname(Dir.getwd)
@vjt
vjt / named-journal.sh
Created May 18, 2011 22:36
flush bind journal files
#!/bin/sh
# Freeze and thaw dyndns zones in order to flush
# BIND journal files.
#
# - vjt Thu May 19 00:34:13 CEST 2011
#
ZONES="example.com example.net 3.2.1.in-addr.arpa"
for zone in $ZONES; do
@vjt
vjt / highlight-dom-id.js
Created May 25, 2011 12:48
Highlight HTML elements whose ID is equal to the anchor part of the URL
// Highlight HTML elements whose ID is equal to the anchor part of the URL
// Tags: dom_id, jQuery, Rails, Javascript
//
$(function ()
if (/^#(\w+_)+\d+$/.test (document.location.hash)) {
var element = $(RegExp.lastMatch);
element.css ({backgroundColor: '#ffffd7'}).highlight ();
}
});
@vjt
vjt / parse-word-structure.rb
Created November 19, 2011 12:21
Parse a Word OpenXML document file with a predefined structure
#!/usr/bin/env ruby
require 'nokogiri'
require 'zip/zipfilesystem'
file = ARGV[0] or abort("Usage: #$PROGRAM_NAME <file.docx>")
Zip::ZipFile.open(file) do |zip|
doc = Nokogiri::XML(zip.file.read('word/document.xml'))
@vjt
vjt / conf.apache
Created February 22, 2012 15:32
GRC (Generic Colouriser/Colorizer) configuration for Apache / nginx access logs
# Configuration suitable to display Apache/nginx access logs
# Based on conf.proftpd by Pavol Domin
# Crafted by Marcello Barnaba <[email protected]>
# Get GRC at http://kassiopeia.juls.savba.sk/~garabik/software/grc.html
#
# ip number
regexp=^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
colours=bold magenta
@vjt
vjt / 1-session.sh
Last active June 5, 2018 12:31
vjt's tmux RVM + ViM IDE setup
#!/bin/sh
#
# IDE Session starter - you should save this script as ~/bin/session, make it
# executable with chmod +x ~/bin/session, and then make a symlink to it for
# every application you want to start.
# E.g. ln -s session ~/bin/members creates a "members" symlink, and when you'll issue
# "members" on the command line this script will:
# Check if a tmux session named "members" exists