Skip to content

Instantly share code, notes, and snippets.

View jodosha's full-sized avatar

Luca Guidi jodosha

View GitHub Profile
<html>
<head>
</head>
<body>
<div id="header">
--- Titolo e Testata ---
</div>
<div id="body">
<div id="menu">
--- Voci di Menu ---
The first implementation was too long (8 LOCs) and referenced `options[:class]` 3 times (duplication).
After the refactoring, with two invocations and a single line of code the problem is solved.
namespace :assets do
task :check => "assets:environment" do
# If the asset pipeline isn't enabled, safely exit.
if not Rails.application.config.assets.enabled
exit(0)
end
require 'sprockets/checker'
# Ensure that action view is loaded and the appropriate
# sprockets hooks get executed
jQuery(function() {
function baseUri() {
return $('meta[name="base-uri"]').attr('content');
}
jQuery.ajaxSetup({
'beforeSend': function(xhr, settings) {
settings.url = baseUri() + settings.url;
return true;
}
@jodosha
jodosha / adapter_test.rb
Last active August 11, 2019 03:12
MiniTest shared examples
require 'test_helper'
shared_examples_for 'An Adapter' do
describe '#read' do
before do
@adapter.write(@key = 'whiskey', @value = "Jameson's")
end
it 'reads a given key' do
@adapter.read(@key).must_equal(@value)
@jodosha
jodosha / instructions.md
Created January 20, 2012 10:00
How to install ruby-debug19 on 1.9.3-p0
# (c) 2012 Luca Guidi (lucaguidi.com) – Released under MIT License
#
# It prompts:
# *[master][~/Developer/epts]% rb:1.9.3-p0
#
# Meaning:
# - The asterisk is for mark uncommitted git changes
# - In the square brackets are respectively: for the current git branch
# and for the current directory
# - The percent is the prompt
# Example #1: Person
person = Node.create({
type: 'person',
uri: 'http://people.com/people/23',
attrs: { birth_date: Time.parse('June 23, 1982').to_date }
})
Node.tire.search(load: true) { filter :range, 'attrs.birth_date' => { lte: Time.zone.now } }.size # => 0
# Example #2: Country
@jodosha
jodosha / gist:2360113
Created April 11, 2012 15:41
Except of a bash script of mine to alias start commands from software I install with Homebrew
#!/bin/bash
case "$1" in
'postgres')
postgres -D /usr/local/var/postgres
;;
'elasticsearch')
elasticsearch -f -D es.config=/usr/local/Cellar/elasticsearch/0.19.1/config/elasticsearch.yml
;;
esac
@jodosha
jodosha / brew-services.rb
Created April 12, 2012 07:27 — forked from lwe/brew-services.rb
External script for homebrew to simplify starting services via launchctl, out of the box support for any formula which implements #startup_plist.
#!/usr/bin/env ruby -w
# brew-services(1) - Easily start and stop formulas via launchctl
# ===============================================================
#
# ## SYNOPSIS
#
# [<sudo>] `brew services` `list`<br>
# [<sudo>] `brew services` `restart` <formula><br>
# [<sudo>] `brew services` `start` <formula> [<plist>]<br>