Skip to content

Instantly share code, notes, and snippets.

View crguezl's full-sized avatar
🌋

Casiano Rodriguez-Leon crguezl

🌋
View GitHub Profile
[09:34][~/rubytesting/rake]$ cat -n GetReady.rake
1 task :turn_off_alarm do
2 puts "Turned off alarm. Would have liked 5 more minutes, though."
3 end
4
5 task :groom_myself do
6 puts "Brushed teeth."
7 puts "Showered."
8 puts "Shaved."
9 end
task :turn_off_alarm do
puts "Turned off alarm. Would have liked 5 more minutes, though."
end
task :groom_myself do
puts "Brushed teeth."
puts "Showered."
puts "Shaved."
end
@crguezl
crguezl / Output of rake -T for this Rakefile
Created February 15, 2012 17:40
Example of Rakefile (used to produce pdf files from LaTeX source)
LPPbook_git (master)$ rake -T
rake clean # Remove any temporary products.
rake clobber # Remove any generated file.
rake dist # Builds a zip file
rake html # Build the HTML from the latex sources
rake images # Copy images into perlexamples/
rake perlexamples.pdf # Build perlexamples.pdf with index and biblio
rake perlexamples.tex # Builds perlexamples.tt2 (Using Perl Template) to LaTeX
rake perlexamples/index.html # Build the HTML from the latex sources
rake publichtml # Publish the HTML files into the remote server
@crguezl
crguezl / simple.rb
Created March 29, 2012 06:31
Recursive Predictive parser for a simple grammar: s -> A s B | c ; c -> C c | C
# svn+ssh://orion/var/svn/casiano/LPP/rubytesting/simplerecdescent
# s -> A s B
# | c
# c -> C c
# | C
class Lexer
attr_accessor :input, :tokens, :pos
def initialize(input)
@crguezl
crguezl / git-export
Created July 5, 2012 09:44
"git export URL" emulates "svn export URL"
#!/usr/bin/env perl
use warnings;
use strict;
use File::Basename;
use File::Path qw{remove_tree};
my $url = shift or die "Usage:\n $0 repository\n";
my $basename = basename($url, '.git');
die "Directory $basename already exists. Remove it first" if -d $basename;
my $out = `git clone --depth 1 $url 2>&1`;
@crguezl
crguezl / gempath.rb
Created July 6, 2012 07:48
Returns the path where the gem being used is installed. '$ gempath.rb sinatra'
#!/usr/bin/env ruby
spec = Gem::Specification.find_by_name(ARGV.shift)
puts spec.gem_dir
class Array
def iterator!
self.each_with_index do |n,i|
self[i] = yield n
end
end
end
array = [1,2,5,6,7]
array.iterator! {|n| n**2}
puts array.inspect # [1, 4, 25, 36, 49 ]
module Kernel
A=B=C=D=E=F="defined in Kernel"
end
#Top level or global constant defined in Object
A=B=C=D=E="defined at top-level"
class Super
A=B=C=D="defined in superclass"
end
module Included
A=B=C="defined in included module"
@crguezl
crguezl / app.rb
Last active December 26, 2015 07:09
require 'rack'
require 'rack/showexceptions'
require './lib/rps'
builder = Rack::Builder.new do
use(Rack::Session::Cookie, {:key => 'rack session',
#:domain => 'localhost',
#:path => '/', #:expire_after => 2592000,
:secret => 'change_me'})
@crguezl
crguezl / multiline.ini
Last active August 29, 2015 13:56
PL grado ETSII: how to manage multiline assignments in INI files. Node repl session
[section_one]
one = 1
two = 2
[section_two]
three = 3
multi = multiline \
support
; comments should be ignored