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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / boot-up-god.sh
Last active September 24, 2015 20:57
God init script for {Open,}SuSE systems
#!/bin/sh
# System startup script for the almighty God - http://god.rubyforge.org/
#
# Install: save as /etc/init.d/god and run insserv /etc/init.d/god
#
# Author: Marcello Barnaba <[email protected]>
#
# - vjt Wed Feb 2 17:56:03 CET 2011
#
@vjt
vjt / imap.class.php
Created January 31, 2011 21:32
Awesome IMAP authentication backend for Dokuwiki
<?php
/**
* Awesome IMAP authentication backend
*
* Set in conf/dokuwiki.php:
*
* $conf['authtype'] = 'imap';
* $conf['authdomain'] = 'example.com'; // The default domain for IMAP-created users
* $conf['authserver'] = '{127.0.0.1:143/imap/novalidate-cert}'; // The IMAP server to which authenticate to
*