sakuric 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +13 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +60 -0
- data/HISTORY.yml +13 -0
- data/INSTALL +5 -0
- data/LICENSE +1 -0
- data/Makefile +19 -0
- data/Manifest +405 -0
- data/README.md +72 -0
- data/Rakefile +4 -0
- data/TODO +3 -0
- data/VERSION +1 -0
- data/bashrc +30 -0
- data/bashrc.d/00-functions.include +7 -0
- data/bashrc.d/01-sakura_checks.include +15 -0
- data/bashrc.d/02-uname.include +11 -0
- data/bashrc.d/80-ruby.include +4 -0
- data/bashrc.d/99-dirs.include +11 -0
- data/bashrc.d/aliases.include +20 -0
- data/bashrc.d/common.include +7 -0
- data/bashrc.d/local.d/README +1 -0
- data/bashrc.d/local.d/nothing.include +0 -0
- data/bashrc.d/uname.d/Darwin +6 -0
- data/bashrc.d/uname.d/Linux +0 -0
- data/bashrc.local.sample +11 -0
- data/bin/10 +7 -0
- data/bin/10times +7 -0
- data/bin/1every +22 -0
- data/bin/1everyN +22 -0
- data/bin/1suN +22 -0
- data/bin/2 +5 -0
- data/bin/act +24 -0
- data/bin/amarelo +2 -0
- data/bin/arancio +4 -0
- data/bin/arcobaleno +10 -0
- data/bin/bianco +3 -0
- data/bin/black +2 -0
- data/bin/brew-install +3 -0
- data/bin/cache +50 -0
- data/bin/cache3 +50 -0
- data/bin/cheorae +4 -0
- data/bin/colorastdouterr +37 -0
- data/bin/cp2desktop +3 -0
- data/bin/create-git-repo.sh +24 -0
- data/bin/csoe +37 -0
- data/bin/data +3 -0
- data/bin/derive +90 -0
- data/bin/dimmi +31 -0
- data/bin/dimmiora +4 -0
- data/bin/doppioni +48 -0
- data/bin/du- +9 -0
- data/bin/duplicates +48 -0
- data/bin/echodo +7 -0
- data/bin/ensure_line_present +82 -0
- data/bin/epoch2date +5 -0
- data/bin/fanout +100 -0
- data/bin/find-broken-symlink +26 -0
- data/bin/find-duplicates +48 -0
- data/bin/find-special-chars-within-filenames +12 -0
- data/bin/fix-terminal +5 -0
- data/bin/gce-create-centos-instance +5 -0
- data/bin/gce-create-custom-image +8 -0
- data/bin/gce-curl-get-instances-for-project +7 -0
- data/bin/gce-get-token +3 -0
- data/bin/gce-getproject-metadata +35 -0
- data/bin/gce-public-ip +4 -0
- data/bin/gcutil-fetch +36 -0
- data/bin/giallo +2 -0
- data/bin/git-clone-in-non-empty-dir +21 -0
- data/bin/git-ignore +3 -0
- data/bin/git-repos +98 -0
- data/bin/git-repos.py +99 -0
- data/bin/gitinfo +2 -0
- data/bin/google-spreadsheet-cat +40 -0
- data/bin/google_ips +5 -0
- data/bin/gray +3 -0
- data/bin/green +2 -0
- data/bin/grigio +3 -0
- data/bin/gsutil-debug-bucket +12 -0
- data/bin/gsutil-get-oauth2-token +4 -0
- data/bin/gugol-image +74 -0
- data/bin/hamachi-ubuntu-install +17 -0
- data/bin/head-1^-1 +5 -0
- data/bin/ifdownup +13 -0
- data/bin/immature/ok2 +25 -0
- data/bin/immature/twice-still-broken +9 -0
- data/bin/install-gic-repo +13 -0
- data/bin/install-sakura-on-debian-latest +6 -0
- data/bin/iphoto_big_files.sh +37 -0
- data/bin/itunes +140 -0
- data/bin/jason-xpath.rb +54 -0
- data/bin/jsawk +1128 -0
- data/bin/json-xpath.rb +54 -0
- data/bin/keepup +13 -0
- data/bin/lsof-top10 +3 -0
- data/bin/minicook +218 -0
- data/bin/mv2. +2 -0
- data/bin/mv2desktop +2 -0
- data/bin/mv2dropbox +2 -0
- data/bin/mv2here +2 -0
- data/bin/mvto +39 -0
- data/bin/nero +2 -0
- data/bin/never_as_root +18 -0
- data/bin/not +16 -0
- data/bin/ok +42 -0
- data/bin/orange +4 -0
- data/bin/pink +2 -0
- data/bin/polygen-dell +7 -0
- data/bin/polygen-heanet +6 -0
- data/bin/polygen-labs +4 -0
- data/bin/print_key_val +4 -0
- data/bin/rainbow +10 -0
- data/bin/recipe +19 -0
- data/bin/red +2 -0
- data/bin/remember-command +140 -0
- data/bin/remember-command.rb +140 -0
- data/bin/richelp +99 -0
- data/bin/ricorda-comando +140 -0
- data/bin/rosa +2 -0
- data/bin/rosso +2 -0
- data/bin/run-parts.sh +50 -0
- data/bin/sakura-check-version +48 -0
- data/bin/sakura-init.DRAFT +5 -0
- data/bin/sakura-version +2 -0
- data/bin/sano +5 -0
- data/bin/sbianca +3 -0
- data/bin/sblua +2 -0
- data/bin/setterm-reset +5 -0
- data/bin/sgialla +2 -0
- data/bin/sgrigia +2 -0
- data/bin/split +37 -0
- data/bin/split.rb +37 -0
- data/bin/srosa +1 -0
- data/bin/srossa +2 -0
- data/bin/strip-white-spaces +2 -0
- data/bin/stty-sane +5 -0
- data/bin/sudo^-1 +18 -0
- data/bin/sverda +6 -0
- data/bin/swift-saio-install.sh +336 -0
- data/bin/synergyc +0 -0
- data/bin/synergys +0 -0
- data/bin/syracuse.pl +29 -0
- data/bin/tail-n+2 +5 -0
- data/bin/tellme +31 -0
- data/bin/tellme-time +4 -0
- data/bin/timeout3 +91 -0
- data/bin/top5 +4 -0
- data/bin/trim +4 -0
- data/bin/trova-broken-symlink +26 -0
- data/bin/twice +5 -0
- data/bin/twice.rb +5 -0
- data/bin/ubuntu-install-hamachi64 +17 -0
- data/bin/ultimo +5 -0
- data/bin/upload.py +2380 -0
- data/bin/usleep +0 -0
- data/bin/varia +90 -0
- data/bin/verde +2 -0
- data/bin/vermelho +2 -0
- data/bin/vim-whereveritis +5 -0
- data/bin/viola +1 -0
- data/bin/virsh-list-all-vms.py +21 -0
- data/bin/virtualbox-manage +41 -0
- data/bin/weekend +12 -0
- data/bin/whattimeisit +4 -0
- data/bin/whereis-ip +5 -0
- data/bin/white +3 -0
- data/bin/whitefy +3 -0
- data/bin/yellow +2 -0
- data/bin/yellowfy +2 -0
- data/bin/zombies +25 -0
- data/docz/polygen/dell.grm +100 -0
- data/docz/polygen/frati.grm +85 -0
- data/docz/polygen/heanet.grm +54 -0
- data/docz/richelp/gcompute.yml +52 -0
- data/docz/richelp/gcutil.yml +52 -0
- data/docz/richelp/gmail.yml +2 -0
- data/docz/richelp/ruby.yml +81 -0
- data/docz/richelp/sakura.yml +20 -0
- data/docz/richelp/sql.yml +12 -0
- data/docz/richelp/ubuntu.yml +22 -0
- data/docz/richelp/yaml.yml +39 -0
- data/docz/richelp/yml.yml +39 -0
- data/etc/sakura/devel.yml +36 -0
- data/etc/synergy.conf.example +37 -0
- data/images/color-sample.png +0 -0
- data/images/google.jpg +0 -0
- data/images/icons/toilet.png +0 -0
- data/images/sakura.jpg +0 -0
- data/images/sakura2.jpg +0 -0
- data/init.rb +5 -0
- data/lib/classes/arrays.rb +246 -0
- data/lib/classes/debug_ric.rb +196 -0
- data/lib/classes/fake_data.rb +8 -0
- data/lib/classes/ric_debug.rb +0 -0
- data/lib/classes/ricconf.rb +110 -0
- data/lib/classes/richelp.rb +70 -0
- data/lib/classes/strings.rb +284 -0
- data/lib/facter/google_compute_engine.rb +10 -0
- data/lib/recipes/20120411-puppet-rump-palladius.recipe +2 -0
- data/lib/recipes/20120726-skype.ubuntu.recipe +16 -0
- data/lib/recipes/20130206-puppet3.ubuntu.recipe +32 -0
- data/lib/recipes/20130206-redis.linux.recipe +17 -0
- data/lib/recipes/20130208-vanilla.linux.recipe +37 -0
- data/lib/recipes/Makefile +4 -0
- data/lib/recipes/README.md +29 -0
- data/lib/recipes/scripts/redis.sh +14 -0
- data/lib/ric.rb +156 -0
- data/lib/ric_colors.rb +313 -0
- data/lib/ric_strings.rb +285 -0
- data/lib/sonice-players/itunes_mac.rb +43 -0
- data/lib/sonice-players/itunes_win.rb +47 -0
- data/lib/sonice-players/mpd.rb +45 -0
- data/lib/sonice-players/rhythmbox.rb +38 -0
- data/profile +1 -0
- data/sakuric.gemspec +40 -0
- data/sbin/install-sakura-on-debian +25 -0
- data/sbin/make-install.sh +10 -0
- data/sbin/mate-createsymlink +4 -0
- data/sounds/0.ogg +0 -0
- data/sounds/0.wav +0 -0
- data/sounds/01.ogg +0 -0
- data/sounds/02.ogg +0 -0
- data/sounds/03.ogg +0 -0
- data/sounds/08.ogg +0 -0
- data/sounds/09.ogg +0 -0
- data/sounds/1.ogg +0 -0
- data/sounds/1.wav +0 -0
- data/sounds/10.ogg +0 -0
- data/sounds/100.ogg +0 -0
- data/sounds/11.ogg +0 -0
- data/sounds/12.ogg +0 -0
- data/sounds/13.ogg +0 -0
- data/sounds/14.ogg +0 -0
- data/sounds/15.ogg +0 -0
- data/sounds/16.ogg +0 -0
- data/sounds/17.ogg +0 -0
- data/sounds/18.ogg +0 -0
- data/sounds/19.ogg +0 -0
- data/sounds/2.ogg +0 -0
- data/sounds/2.wav +0 -0
- data/sounds/20.ogg +0 -0
- data/sounds/21.ogg +0 -0
- data/sounds/22.ogg +0 -0
- data/sounds/23.ogg +0 -0
- data/sounds/24.ogg +0 -0
- data/sounds/26.ogg +0 -0
- data/sounds/3.ogg +0 -0
- data/sounds/3.wav +0 -0
- data/sounds/30.ogg +0 -0
- data/sounds/34.ogg +0 -0
- data/sounds/4.ogg +0 -0
- data/sounds/4.wav +0 -0
- data/sounds/40.ogg +0 -0
- data/sounds/42.ogg +0 -0
- data/sounds/45.ogg +0 -0
- data/sounds/47.ogg +0 -0
- data/sounds/5.ogg +0 -0
- data/sounds/5.wav +0 -0
- data/sounds/50.ogg +0 -0
- data/sounds/6.ogg +0 -0
- data/sounds/6.wav +0 -0
- data/sounds/60.ogg +0 -0
- data/sounds/7.ogg +0 -0
- data/sounds/7.wav +0 -0
- data/sounds/70.ogg +0 -0
- data/sounds/8.ogg +0 -0
- data/sounds/8.wav +0 -0
- data/sounds/80.ogg +0 -0
- data/sounds/9.ogg +0 -0
- data/sounds/9.wav +0 -0
- data/sounds/90.ogg +0 -0
- data/sounds/a.ogg +0 -0
- data/sounds/aaahhh.ogg +0 -0
- data/sounds/abologna.ogg +0 -0
- data/sounds/adargenta.ogg +0 -0
- data/sounds/alzatiecammina.ogg +0 -0
- data/sounds/apache.ogg +0 -0
- data/sounds/attenzione.ogg +0 -0
- data/sounds/awesome.m4a +0 -0
- data/sounds/bazinga.mp3 +0 -0
- data/sounds/bazinga.ogg +0 -0
- data/sounds/bela regaz.wav +0 -0
- data/sounds/benvenuti.wav +0 -0
- data/sounds/benvenuti2.wav +0 -0
- data/sounds/bergonz.ogg +0 -0
- data/sounds/boh.ogg +0 -0
- data/sounds/buahah.ogg +0 -0
- data/sounds/buonasera.ogg +0 -0
- data/sounds/buongiorno.ogg +0 -0
- data/sounds/burp.ogg +0 -0
- data/sounds/carlo.ogg +0 -0
- data/sounds/cena.ogg +0 -0
- data/sounds/che figata.m4a +0 -0
- data/sounds/che figlio di puttana.m4a +0 -0
- data/sounds/che.ogg +0 -0
- data/sounds/ciao.ogg +0 -0
- data/sounds/ciao.wav +0 -0
- data/sounds/da.ogg +0 -0
- data/sounds/davide.ogg +0 -0
- data/sounds/demone.ogg +0 -0
- data/sounds/dhcp.ogg +0 -0
- data/sounds/dinuovo.ogg +0 -0
- data/sounds/dns.ogg +0 -0
- data/sounds/dopo.ogg +0 -0
- data/sounds/e'.ogg +0 -0
- data/sounds/eattivo.ogg +0 -0
- data/sounds/ee.ogg +0 -0
- data/sounds/ehi.ogg +0 -0
- data/sounds/eoragiu.ogg +0 -0
- data/sounds/eorasu.ogg +0 -0
- data/sounds/eripartita.ogg +0 -0
- data/sounds/estato.ogg +0 -0
- data/sounds/estatoriavviato.ogg +0 -0
- data/sounds/fratro.ogg +0 -0
- data/sounds/frozenbubble.ogg +0 -0
- data/sounds/funziona.ogg +0 -0
- data/sounds/go raibh mile maith agaibh.m4a +0 -0
- data/sounds/grazie.ogg +0 -0
- data/sounds/h1.ogg +0 -0
- data/sounds/hainuovaposta.ogg +0 -0
- data/sounds/hogiamangiato.ogg +0 -0
- data/sounds/host.ogg +0 -0
- data/sounds/il.ogg +0 -0
- data/sounds/ilcomputer.ogg +0 -0
- data/sounds/ilnumerodaleiselezionatoe.ogg +0 -0
- data/sounds/ilprocesso.ogg +0 -0
- data/sounds/ilprogramma.ogg +0 -0
- data/sounds/ilservizio.ogg +0 -0
- data/sounds/imap.ogg +0 -0
- data/sounds/imieisuperpoterimidiconoche.ogg +0 -0
- data/sounds/infunzione.ogg +0 -0
- data/sounds/inpunto.ogg +0 -0
- data/sounds/ipmon.ogg +0 -0
- data/sounds/laconnessioneadinternet.ogg +0 -0
- data/sounds/lastampante.ogg +0 -0
- data/sounds/lazzaron.ogg +0 -0
- data/sounds/ldap.ogg +0 -0
- data/sounds/linterfaccia.ogg +0 -0
- data/sounds/lucilla.ogg +0 -0
- data/sounds/ma vaffanculo.m4a +0 -0
- data/sounds/majjal.wav +0 -0
- data/sounds/mamma.ogg +0 -0
- data/sounds/mauro.ogg +0 -0
- data/sounds/max.ogg +0 -0
- data/sounds/meerda.wav +0 -0
- data/sounds/meno.ogg +0 -0
- data/sounds/merda clo.wav +0 -0
- data/sounds/mezza.ogg +0 -0
- data/sounds/mila.ogg +0 -0
- data/sounds/mille.ogg +0 -0
- data/sounds/minuti.ogg +0 -0
- data/sounds/named.ogg +0 -0
- data/sounds/no.ogg +0 -0
- data/sounds/nohofame.ogg +0 -0
- data/sounds/nonfunziona.ogg +0 -0
- data/sounds/nonriescoatrovare.ogg +0 -0
- data/sounds/nonsarebbeoradilavorare.ogg +0 -0
- data/sounds/nonstalavorando.ogg +0 -0
- data/sounds/numero.wav +0 -0
- data/sounds/ooohhh.ogg +0 -0
- data/sounds/pinger.ogg +0 -0
- data/sounds/pocofa.ogg +0 -0
- data/sounds/pop3.ogg +0 -0
- data/sounds/porca puttana.m4a +0 -0
- data/sounds/porcapupazza.ogg +0 -0
- data/sounds/ppp.ogg +0 -0
- data/sounds/pranzo.ogg +0 -0
- data/sounds/prego.ogg +0 -0
- data/sounds/prima.ogg +0 -0
- data/sounds/qualcosamidice.ogg +0 -0
- data/sounds/raggiungibile.ogg +0 -0
- data/sounds/riccardo.ogg +0 -0
- data/sounds/salsa ridge.wav +0 -0
- data/sounds/scusa.ogg +0 -0
- data/sounds/seriously man.m4a +0 -0
- data/sounds/si.ogg +0 -0
- data/sounds/sito porno con sonoro.wav +0 -0
- data/sounds/socmel.wav +0 -0
- data/sounds/sono.ogg +0 -0
- data/sounds/sonoacasa.ogg +0 -0
- data/sounds/sonole.ogg +0 -0
- data/sounds/sputo.ogg +0 -0
- data/sounds/ssh.ogg +0 -0
- data/sounds/stagiocando.ogg +0 -0
- data/sounds/statospento.ogg +0 -0
- data/sounds/stopaiodipalle.ogg +0 -0
- data/sounds/thesedicks.wav +0 -0
- data/sounds/tornatosu.ogg +0 -0
- data/sounds/trapoco.ogg +0 -0
- data/sounds/trequarti.ogg +0 -0
- data/sounds/tutti.ogg +0 -0
- data/sounds/una.ogg +0 -0
- data/sounds/unquarto.ogg +0 -0
- data/sounds/virgola.ogg +0 -0
- data/sources/c/usleep.c +50 -0
- data/spec/my_first_spec.rb +6 -0
- data/tasks/sakuric-gem.rake +21 -0
- data/tasks/testing.rake +15 -0
- data/templates/bashrc.inject +10 -0
- data/templates/happy_christmas.ascii_art +5 -0
- data/test/roodi.sh +10 -0
- data/test/test_mini_failing.rb +3 -0
- data/test/test_mini_ok.rb +3 -0
- data/test/test_ruby_syntax.sh +12 -0
- data/third-party/jsawk/README.markdown +437 -0
- data/third-party/jsawk/jsawk +1128 -0
- metadata +835 -0
@@ -0,0 +1,196 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# copied from Mixins in Programming ruby book, pag 119
|
4
|
+
|
5
|
+
module RicDebug
|
6
|
+
puts "DEBUG: including module RicDebug, as a mixin within #{self.class}"
|
7
|
+
|
8
|
+
def whoami?
|
9
|
+
"#{self.class.name} (\##{self.object_id}): #{self}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def trace()
|
13
|
+
puts "== Riccardo Debug Trace program (excuse verboity) =="
|
14
|
+
puts "File: #{__FILE__}"
|
15
|
+
#TODO put verbose context like call stack, ...
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_verbose_s()
|
19
|
+
whoami?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
################################################################################################################
|
26
|
+
# DEBUG AND ERRORS
|
27
|
+
################################################################################################################
|
28
|
+
|
29
|
+
$_debug_tags = []
|
30
|
+
|
31
|
+
=begin
|
32
|
+
|
33
|
+
This is a denbug with steroids
|
34
|
+
|
35
|
+
Introduced tags: NORMAL deb() works.
|
36
|
+
If you launch debug_on('reason', :tags => [ :this, :foo, :bar])
|
37
|
+
from this moment on normal debug is prevented unless you debug using the explicit tags..
|
38
|
+
|
39
|
+
Il vecchio debug era:
|
40
|
+
debug (s, :really_write => true,:write_always => false )
|
41
|
+
|
42
|
+
=end
|
43
|
+
|
44
|
+
def debug(s, opts = {} )
|
45
|
+
out = opts.fetch(:out, $stdout)
|
46
|
+
tag = opts.fetch(:tag, '_DFLT_')
|
47
|
+
really_write = opts.fetch(:really_write, true) # you can prevent ANY debug setting this to false
|
48
|
+
write_always = opts.fetch(:write_always, false)
|
49
|
+
|
50
|
+
raise "ERROR: ':tags' must be an array in debug(), maybe you meant to use :tag?" if ( opts[:tags] && opts[:tags].class != Array )
|
51
|
+
final_str = "#RDeb#{write_always ? '!' : ''}[#{opts[:tag] || '-'}] #{s}"
|
52
|
+
final_str = "\033[1;30m" +final_str + "\033[0m" if opts.fetch(:coloured_debug, true) # color by gray by default
|
53
|
+
if (debug_tags_enabled? ) # tags
|
54
|
+
puts( final_str ) if debug_tag_include?( opts )
|
55
|
+
else # normal behaviour: if NOT tag
|
56
|
+
puts( final_str ) if ((really_write && $DEBUG) || write_always) && ! opts[:tag]
|
57
|
+
end
|
58
|
+
end #/debug()
|
59
|
+
alias :deb :debug
|
60
|
+
|
61
|
+
def debug_tags_enabled?
|
62
|
+
$_debug_tags != []
|
63
|
+
end
|
64
|
+
|
65
|
+
def debug_tag_include?(opts)
|
66
|
+
assert_array($_debug_tags, 'debug_tags')
|
67
|
+
assert_class( opts[:tag], Symbol, "tag must be a symbol, ", :dontdie => true ) if opts[:tag]
|
68
|
+
assert_array( opts[:tags] , 'opts[:tags]' ) if opts[:tags]
|
69
|
+
return $_debug_tags.include?(opts[:tag].to_sym) if opts[:tag]
|
70
|
+
return ($_debug_tags & opts[:tags]).size > 0 if opts[:tags]
|
71
|
+
#return $_debug_tags.include?(tag_or_tags.to_sym) if (tag.class == String || tag.class == Symbol)
|
72
|
+
return false
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def debug_on(comment="enabling debug (SVNID=#{$SVN_ID rescue 'ERR'})", opts={} )
|
77
|
+
$DEBUG = true
|
78
|
+
deb "debug_on(): #{comment}"
|
79
|
+
_manage_debug_tags(opts)
|
80
|
+
if opts[:tags]
|
81
|
+
deb "debug_on(): new tags enabled (#{opts[:tags]}). Now ONLY debug called explicitly with one of those tags will work! To go back to normal behaviour just run: 'debug_reset_tags()'"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
def debug_off(comment="Disabling DEBUG for once in a while :)", opts={})
|
85
|
+
deb "debug_off(): #{comment}"
|
86
|
+
$DEBUG = false
|
87
|
+
end
|
88
|
+
|
89
|
+
def debug_tags
|
90
|
+
$_debug_tags
|
91
|
+
end
|
92
|
+
def debug_reset_tags
|
93
|
+
$_debug_tags = []
|
94
|
+
end
|
95
|
+
def deb2(str)
|
96
|
+
debug "(ERR) #{str}", :out => $stderr, :tag => 'stderr' # , :really_write => true,:write_always => false,
|
97
|
+
end
|
98
|
+
def stradebug(str)
|
99
|
+
deb str, :tags => %w(verbose stradebug vvv)
|
100
|
+
end
|
101
|
+
alias :stradeb :stradebug
|
102
|
+
|
103
|
+
#####################
|
104
|
+
# All the foloowing has been transferred to 'ric' gem
|
105
|
+
# to be removed in the future..
|
106
|
+
|
107
|
+
# if DEBUG is true, then execute the code
|
108
|
+
def deb?()
|
109
|
+
yield if $DEBUG
|
110
|
+
end
|
111
|
+
alias :if_deb :deb?
|
112
|
+
alias :if_deb? :deb?
|
113
|
+
|
114
|
+
def debug?()
|
115
|
+
$DEBUG == true
|
116
|
+
end
|
117
|
+
|
118
|
+
def debo(obj)
|
119
|
+
deb "debo: #{obj.ispeziona}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def err(str)
|
123
|
+
$stderr.puts "ERR[RicLib] #{$0}: '#{str}'"
|
124
|
+
end
|
125
|
+
|
126
|
+
def fatal(ret,str)
|
127
|
+
err "#{get_red 'RubyFatal'}(#{ret}) #{str}"
|
128
|
+
exit ret
|
129
|
+
end
|
130
|
+
|
131
|
+
def warning(s)
|
132
|
+
err "#{yellow 'WARN'} #{s}"
|
133
|
+
end
|
134
|
+
|
135
|
+
#def d()
|
136
|
+
# flag( "Cielcio (TBS arlecchinami di colori)", 'it')
|
137
|
+
#end
|
138
|
+
#def tbd(comment="TODO")
|
139
|
+
# puts "#{white :TBD} (#{__FILE__}:#{__LINE__}): #{comment}"
|
140
|
+
# raise "TBD_EXCEPTION! ''#{comment}''"
|
141
|
+
#end
|
142
|
+
|
143
|
+
# copiato da:
|
144
|
+
# http://stackoverflow.com/questions/622324/getting-argument-names-in-ruby-reflection
|
145
|
+
$shadow_stack = []
|
146
|
+
|
147
|
+
set_trace_func( lambda {
|
148
|
+
|event, file, line, id, binding, classname|
|
149
|
+
if event == "call"
|
150
|
+
$shadow_stack.push( eval("local_variables", binding) )
|
151
|
+
elsif event == "return"
|
152
|
+
$shadow_stack.pop
|
153
|
+
end
|
154
|
+
} )
|
155
|
+
|
156
|
+
def obsolete(msg)
|
157
|
+
puts "#{pink '_OBSOLETE_'} (#{file_line}): #{red msg}"
|
158
|
+
#deb "TBD dammi la traccia chiamante, cazzo! Local functions: #{eval( 'local_variables') }"
|
159
|
+
pgray("Obsolescense:\n -- " + caller().join("\n -- "))
|
160
|
+
end
|
161
|
+
|
162
|
+
# copiato da qui: http://www.caliban.org/ruby/rubyguide.shtml#style
|
163
|
+
def silently(&block)
|
164
|
+
deb( "[DEBUG] Calling silently! warn_level is '#{$VERBOSE}'" )
|
165
|
+
warn_level = $VERBOSE
|
166
|
+
$VERBOSE = nil
|
167
|
+
result = block.call
|
168
|
+
$VERBOSE = warn_level
|
169
|
+
result
|
170
|
+
end
|
171
|
+
|
172
|
+
# TBD sposta in altro file
|
173
|
+
class RicException < Exception
|
174
|
+
attr_reader :description, :options
|
175
|
+
|
176
|
+
def initialize(str,opts={})
|
177
|
+
description = str
|
178
|
+
opts = options
|
179
|
+
super(str)
|
180
|
+
end
|
181
|
+
|
182
|
+
def to_s
|
183
|
+
"Ric_Exception (figata direi!): '''#{red description}'''"
|
184
|
+
end
|
185
|
+
end #/RicException
|
186
|
+
|
187
|
+
private
|
188
|
+
def _manage_debug_tags(opts)
|
189
|
+
#puts "_manage_debug_tags: #{opts}"
|
190
|
+
$_debug_tags ||= []
|
191
|
+
$_debug_tags += opts[:tags] if opts[:tags]
|
192
|
+
#$_debug_tags << opts[:tag] if opts[:tag]
|
193
|
+
$_debug_tags = $_debug_tags.uniq
|
194
|
+
#puts "$_debug_tags: #{$_debug_tags} (#{$_debug_tags.map{|x| x.class}})"
|
195
|
+
deb "_manage_debug_tags(): new tags are: #{$_debug_tags}", :tag => :debug
|
196
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
|
2
|
+
################################################################################
|
3
|
+
# fake data for some tests :)
|
4
|
+
#$a = [1 ,2 ,3, '4', 'cinque', :simbolo ] rescue nil
|
5
|
+
#$h = { :key => 'value', :answer => 42 , 'float' => 4.2 , :sym => 'bol', :foo => 'bar1 (symbol)', "foo" => 'bar2 (symbol)' } # rescue nil
|
6
|
+
#$s = "This is a test string with some color TBD and some @tags @personal ok?!?"
|
7
|
+
|
8
|
+
|
File without changes
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
=begin
|
4
|
+
Nella mia mente malvagia e maliziosa, questa classe dovrebbe contenere tutta la mia configurazione...
|
5
|
+
Meglio una classe che un insieme di metodi a cazzo di cane, che dici? La uso piu' per scope (protezione/namespace)
|
6
|
+
che per ereditarieta' e menate varie... vorrei poter dire: RicConf.inspect e avere tutto il buridone di configurazione
|
7
|
+
e null'altro...
|
8
|
+
=end
|
9
|
+
|
10
|
+
$RIC_SVNUSER ||= 'riccardo'
|
11
|
+
# TODO9 questa variabile a tendere dovrebbe essere distrutta e sostituita da $prog_conf nel programma devel..
|
12
|
+
$devel_conf = YAML.load(File.read("#{$SAKURADIR}/etc/sakura/devel.yml")) # dato che ci accedo da devel.rb
|
13
|
+
|
14
|
+
def ric_services
|
15
|
+
sane_service_regex = /^[a-z_\.-]+$/
|
16
|
+
arr_services = [
|
17
|
+
hostconf('services') , # .split(',').trim_all, # host_services =
|
18
|
+
networkconf('services'), # .split(',').trim_all ,
|
19
|
+
] rescue [ "Eccezione: #{$!}" ]
|
20
|
+
deb arr_services
|
21
|
+
return arr_services.compact.flatten.join(',').split(',').trim_all.select{|srv|
|
22
|
+
# TODO rimuovi le right vuote
|
23
|
+
# next if srv == ''
|
24
|
+
ok = srv.match(sane_service_regex)
|
25
|
+
deb("ricconf.rb:#{__LINE__} Beware, illegal service here: ''#{red srv}'' (services: #{gray arr_services.join(', ')})") unless ok
|
26
|
+
ok
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
class RicConf
|
32
|
+
attr_accessor :ver, :home, :user, :svn, :nreloads, :path
|
33
|
+
$obsolete_tags = %w{ sobenme sobenme_services sobenme_tags hea lavoro SobenmeGlobalConfDistObsolete }
|
34
|
+
|
35
|
+
def initialize()
|
36
|
+
#puts "DEB RicConf::initialize(): Initializing a new #{self.class}"
|
37
|
+
self.ver = $RICLIB_VERSION
|
38
|
+
self.home = $HOME
|
39
|
+
self.user = $USER || get_username # = 'riccardo'
|
40
|
+
self.path = ENV['PATH'].split(':').uniq.sort # = 'riccardo'
|
41
|
+
self.svn = ENV['SVNRIC']
|
42
|
+
self.nreloads ||= 0
|
43
|
+
self.nreloads += 1 # lo riassegna quindi vale sempre uno a ogni costruzione..
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_s
|
47
|
+
"RicConf: #{yellow self.inspect}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# after migration svn!
|
51
|
+
def SVNRIC
|
52
|
+
File.expand_path(ENV['SVNRIC'] || "~/git/gic" )
|
53
|
+
end
|
54
|
+
|
55
|
+
# x is a string
|
56
|
+
def cool_eval(x)
|
57
|
+
y = (eval(x.to_s)) rescue "CoolEvalEsception: '#{$!}'"
|
58
|
+
deb "CoolEval('#{yellow x}' (#{x.class})) --> ''#{azure(y)}'' (class=#{y.class})"
|
59
|
+
return y
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_tags()
|
63
|
+
deb "$network_conf is a #{$network_conf.class}"
|
64
|
+
deb "$host_conf is a #{$hostconf.class}"
|
65
|
+
[ '$host_conf', '$network_conf', '2+3', 'RicConf' ].each{|var|
|
66
|
+
# x = 'var.inspect()'
|
67
|
+
# y = eval(x)
|
68
|
+
# deb "Supercool: Evaluing('#{x}') for #{blue var} (#{var.class}) --> #{azure(y)} (class=#{y.class})"
|
69
|
+
cool_eval(var)
|
70
|
+
}
|
71
|
+
# my_network_tags = $network_conf['tags'] rescue []
|
72
|
+
tags = {
|
73
|
+
# :conf_network => my_network_tags.split(',') ,
|
74
|
+
:ENV_TAGS => ENV['HOST_TAGS'].split(','),
|
75
|
+
:ENV_SRVS => ENV['HOST_SERVICES'].split(','),
|
76
|
+
}
|
77
|
+
tags[:conf_host] = $host_conf['tags'].split(',') rescue [] # fatal("Conf missing for this host: #{$!}")
|
78
|
+
tags[:conf_network] = $network_conf['tags'] .split(',') rescue [] # fatal("Conf missing for this host: #{$!}")
|
79
|
+
tags.each{|k,v|
|
80
|
+
deb "#{k}: #{v}"
|
81
|
+
}
|
82
|
+
cleanup_tags = tags.values.flatten.compact.map{|x| x.strip }.uniq.sort
|
83
|
+
deb tags.inspect
|
84
|
+
# obsolete tags:
|
85
|
+
my_obsolete_tags = cleanup_tags & $obsolete_tags
|
86
|
+
deb "#Obsolete tags: #{red(my_obsolete_tags.map{|tag| "'#{tag}' from #{tags.map{|k,v| k if v.match(tag) }.compact }"}) }"
|
87
|
+
return cleanup_tags - $obsolete_tags
|
88
|
+
end
|
89
|
+
|
90
|
+
end # /RicConf
|
91
|
+
|
92
|
+
def get_username
|
93
|
+
$USER ||= `whoami`.strip
|
94
|
+
end
|
95
|
+
alias :username :get_username
|
96
|
+
|
97
|
+
def get_tags()
|
98
|
+
RicConf.new.get_tags
|
99
|
+
end
|
100
|
+
|
101
|
+
# Terminal stuff
|
102
|
+
def supports_64k_colors?
|
103
|
+
good_terminals = %w{ iTerm.app } # these support 64k, i.e. orange
|
104
|
+
bad_terminals = %w{ Apple_Terminal } # these support only 16 colors, i.e. red
|
105
|
+
my_terminal = ENV['TERM_PROGRAM'].to_s
|
106
|
+
return true if good_terminals.include?(my_terminal)
|
107
|
+
return false if bad_terminals.include?(my_terminal)
|
108
|
+
raise "Unknown terminal #{red my_terminal.quote}, please define me in: #{yellow __FILE__}"
|
109
|
+
return nil
|
110
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
|
2
|
+
module RicHelpModule
|
3
|
+
|
4
|
+
$HELP_DIR = "#{$SAKURADIR}/doc/richelp/"
|
5
|
+
|
6
|
+
def helpfile_parse(helpfile_name)
|
7
|
+
err = ''
|
8
|
+
helpfile = helpfile_name
|
9
|
+
helpfile += ".yml" unless helpfile_name.match( /.yml$/ )
|
10
|
+
helpfile = "#{$HELP_DIR}/#{helpfile}" unless helpfile.match(/\//) # has a slash
|
11
|
+
conf = YAML.load_file(helpfile) rescue exception_yml($!)
|
12
|
+
err = $!
|
13
|
+
deb("_conf: " + conf['_conf'].inspect)
|
14
|
+
$color_title = conf['_conf']['colors']['title'] rescue "azure"
|
15
|
+
$color_line_key = conf['_conf']['colors']['line_key'] rescue "blue"
|
16
|
+
$color_line_val = conf['_conf']['colors']['line_val'] rescue 'lgray'
|
17
|
+
deb [ $color_title , $color_line_key , $color_line_val ]
|
18
|
+
return conf unless conf.nil?
|
19
|
+
return { 'Some error' => { 'parsing YML file' => "'#{$!}'" , "11" => 2 } }
|
20
|
+
end
|
21
|
+
|
22
|
+
def show_help(query_str)
|
23
|
+
n=0
|
24
|
+
$help_opt.each{ |menu_title,submenu|
|
25
|
+
next if special_help_title?(menu_title)
|
26
|
+
n += 1
|
27
|
+
if (! query_str.nil? ) # searching for sth
|
28
|
+
# foreach (father, sons)I have to visualize ALL sons and the matching father if and only if:
|
29
|
+
# 1. father string matches , OR
|
30
|
+
# 2. at least ONE son matches
|
31
|
+
# if father matches, I give ALL sons. If father doesnt, I publish the father with ONLY the matching sons :)
|
32
|
+
ret_search = ret_all = ''
|
33
|
+
submenu.each{ |k,v|
|
34
|
+
ret_search += help(k,v,query_str).to_s
|
35
|
+
ret_all += help(k,v,'')
|
36
|
+
}
|
37
|
+
father_matches = menu_title.match(query_str)
|
38
|
+
sons_match = ret_search.length > 0
|
39
|
+
if (father_matches || sons_match)
|
40
|
+
title("#{n}. #{menu_title.capitalize}")
|
41
|
+
puts father_matches ? ret_all : ret_search
|
42
|
+
end
|
43
|
+
else # no searching: visualizing everything
|
44
|
+
#puts "Querystring: #{query_str} (#{query_str.length})"
|
45
|
+
title("#{n}. #{menu_title.capitalize}")
|
46
|
+
submenu.each{ |k,v|
|
47
|
+
puts help(k,v,query_str)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def sanitize_help_file(file_str)
|
54
|
+
file_str = file_str.gsub(/\.yml$/,'')
|
55
|
+
File.expand_path "#{$HELP_DIR}/#{file_str}.yml"
|
56
|
+
end
|
57
|
+
|
58
|
+
def show_test(file_str)
|
59
|
+
file = sanitize_help_file(file_str)
|
60
|
+
hash_or_errorstring = YAML.load_file( file ) rescue "#{$!}"
|
61
|
+
if hash_or_errorstring.class == Hash
|
62
|
+
puts "OK File yml: #{green file}"
|
63
|
+
exit 0
|
64
|
+
else
|
65
|
+
puts "Some problems with '#{file}': #{red hash_or_errorstring}"
|
66
|
+
exit 78
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,284 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class String
|
4
|
+
include RicDebug
|
5
|
+
|
6
|
+
def basename
|
7
|
+
split('/').last
|
8
|
+
end
|
9
|
+
|
10
|
+
def left(length,padding)
|
11
|
+
mylen = self.length
|
12
|
+
padding_char = padding[0] # troppo difficile fare che paddi "abc" su 8 fa "abcabcab" checcavolo :)
|
13
|
+
mylen < length ?
|
14
|
+
self + padding * (length - mylen) :
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def color(mycolor = :orange )
|
19
|
+
send(mycolor,self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def uncolor()
|
23
|
+
scolora(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
# trovata qui: la mia funziona cmq
|
27
|
+
# http://www.ruby-forum.com/topic/96222
|
28
|
+
def to_class
|
29
|
+
Object.const_get(self)
|
30
|
+
#ret = eval(self)
|
31
|
+
#deb "this is a class? cls=#{ret.class}"
|
32
|
+
#raise "Exception its not a class!" if ret.class.to_s != 'Class'
|
33
|
+
#return ret
|
34
|
+
end
|
35
|
+
|
36
|
+
def nlines
|
37
|
+
split("\n").size
|
38
|
+
end
|
39
|
+
|
40
|
+
# rimuove spazi a inizio e fine
|
41
|
+
def trim
|
42
|
+
self.gsub(/^\s+/,'').gsub(/\s+$/,'')
|
43
|
+
end
|
44
|
+
|
45
|
+
def escape_printf
|
46
|
+
gsub("%",'%%')
|
47
|
+
end
|
48
|
+
|
49
|
+
def escape_double_quotes
|
50
|
+
gsub('"','\"')
|
51
|
+
end
|
52
|
+
def escape_single_quotes
|
53
|
+
gsub("'","\'")
|
54
|
+
end
|
55
|
+
|
56
|
+
# dumps string to file (in APPEND) :)
|
57
|
+
def tee(opts={})
|
58
|
+
filename = opts.fetch :file, __FILE__ + ".tmpric"
|
59
|
+
verbose = opts.fetch :verbose, true
|
60
|
+
preamble = lambda {|where| return "# Teeing string (pid=#{$$}, size=#{self.size}B, opts=#{opts}) into file: #{blue filename}\n" }
|
61
|
+
deb "Teeing string (#{self.size}B, opts=#{opts}) into file: #{blue filename}"
|
62
|
+
File.open(filename, 'a') {|f|
|
63
|
+
f.write("# {{{ String.tee #{} from #{__FILE__}\n") if verbose
|
64
|
+
f.write(preamble.call(:BEGIN)) if verbose
|
65
|
+
f.write(self)
|
66
|
+
f.write("\n" + preamble.call(:END))if verbose
|
67
|
+
f.write("\n# }}} Tee stop pid=##{$$}\n")if verbose
|
68
|
+
} # i think it closes it here...
|
69
|
+
puts "Written #{self.size}B in append to: '#{yellow filename}'" if verbose
|
70
|
+
return self
|
71
|
+
end
|
72
|
+
|
73
|
+
=begin
|
74
|
+
return string with regex highlighted
|
75
|
+
|
76
|
+
TODO highlight just the matching regex
|
77
|
+
=end
|
78
|
+
def grep_color(regex, opts={} )
|
79
|
+
deb "string grep_color(regex: '#{regex}')"
|
80
|
+
color = opts[:color] || true # false
|
81
|
+
verbose = opts[:verbose] || true # TODO false
|
82
|
+
return red(self) if self.match(regex)
|
83
|
+
return verbose ?
|
84
|
+
self :
|
85
|
+
''
|
86
|
+
end
|
87
|
+
|
88
|
+
# Doesnt work. Look at ~/bin/uptimes for a VERY nice implementation
|
89
|
+
# def color_grep(regex, mycolor, opts={} )
|
90
|
+
# #deb "string grep_color(regex: '#{regex}' w/ color='#{mycolor}')"
|
91
|
+
# color = opts[:color] || true # false
|
92
|
+
# return self.gsub(regex, $1.color(mycolor)) if self.match(regex)
|
93
|
+
# return self
|
94
|
+
# end
|
95
|
+
|
96
|
+
alias :right :left
|
97
|
+
|
98
|
+
def flag(nation)
|
99
|
+
flag(self, flag = '')
|
100
|
+
end
|
101
|
+
|
102
|
+
# enclose string in single quotes..
|
103
|
+
def quote(sep = nil)
|
104
|
+
sep ||= "'"
|
105
|
+
sep + self + sep
|
106
|
+
end
|
107
|
+
def double_quote(); quote('"') ; end
|
108
|
+
|
109
|
+
def depurate_for_file
|
110
|
+
gsub(/[\/: \.]/ , '_')
|
111
|
+
end
|
112
|
+
|
113
|
+
def prepend(str)
|
114
|
+
str.to_s+self
|
115
|
+
end
|
116
|
+
def append(str)
|
117
|
+
self+str.to_s
|
118
|
+
end
|
119
|
+
|
120
|
+
# a: b
|
121
|
+
# c: d
|
122
|
+
# -->
|
123
|
+
def to_hash(description='String::to_hash() made by genious RCarlesso (give a better description if u dont like this!)')
|
124
|
+
arr = Hash.new
|
125
|
+
arr['_meta'] = Hash.new
|
126
|
+
arr['_meta']['description'] = description
|
127
|
+
arr['_meta']['time'] = Time.now
|
128
|
+
self.split("\n").each{|line|
|
129
|
+
k,v = line.split(': ')
|
130
|
+
arr[k.strip] = v.strip
|
131
|
+
} rescue arr['_meta']['errors'] = $!
|
132
|
+
arr
|
133
|
+
end
|
134
|
+
|
135
|
+
def starts_with?(ch)
|
136
|
+
self.match(/^#{ch}/)
|
137
|
+
end
|
138
|
+
|
139
|
+
# 'abcde' => '*****'
|
140
|
+
def asterisks(ch='*')
|
141
|
+
ch * (self.size)
|
142
|
+
end
|
143
|
+
|
144
|
+
def shorten (count = 50)
|
145
|
+
if self.length >= count
|
146
|
+
shortened = self[0, count]
|
147
|
+
splitted = shortened.split(/\s/)
|
148
|
+
words = splitted.length
|
149
|
+
splitted[0, words-1].join(" ") + ' ...'
|
150
|
+
else
|
151
|
+
self
|
152
|
+
end
|
153
|
+
end
|
154
|
+
# alias :excerpt :shorten
|
155
|
+
# no dai, in realta excerpt sarebbe con SEARCH di parola e ci orla intorno...
|
156
|
+
|
157
|
+
# sanitizza un filename
|
158
|
+
def sanitize_path
|
159
|
+
gsub(/[\/: ]/,'_')
|
160
|
+
end
|
161
|
+
|
162
|
+
# see arrays!
|
163
|
+
# def method_missing
|
164
|
+
# end
|
165
|
+
|
166
|
+
def to_html
|
167
|
+
%(<span class="ricsvn_string" >#{self}</span>)
|
168
|
+
end
|
169
|
+
|
170
|
+
def initial; self[0..0] ; end
|
171
|
+
|
172
|
+
|
173
|
+
# canonicalize: delete leading and trailing spaces, replaces newlines
|
174
|
+
# with one space and then replace all continuouse spaces with one ' '
|
175
|
+
# (including tabs and other fancy things)
|
176
|
+
|
177
|
+
# non funziona bene perche non so come CACCHIO mappare il /g.
|
178
|
+
# oare che in ruby ci sia solo /i x(xtended) n(multiline)
|
179
|
+
def canonicalize
|
180
|
+
value = self
|
181
|
+
value = value.gsub( /^\s+/, '') # s/^\s+//;
|
182
|
+
value = value.gsub( /\s+$/, '') # value =~ s/\s+$//;
|
183
|
+
value = value.gsub( /\r*\n/n, ' ') # value =~ s/\r*\n/ /g;
|
184
|
+
value = value.gsub( /\s+$/n , ' ') # value =~ s/\s+$/ /g;
|
185
|
+
deb "Original: '''#{self}'''"
|
186
|
+
deb "Canonical: '''#{value}'''"
|
187
|
+
return value
|
188
|
+
end
|
189
|
+
|
190
|
+
# a manhouse :-(
|
191
|
+
def singolarizza
|
192
|
+
return self.singularize if self.respond_to?(:singularize)
|
193
|
+
deb("singularize '#{self}'")
|
194
|
+
m = self.match( /(.*)es$/) # i.e. matches
|
195
|
+
return m[1] if (m)
|
196
|
+
m = self.match( /(.*)s$/)
|
197
|
+
return m[1] if m
|
198
|
+
return m
|
199
|
+
end
|
200
|
+
|
201
|
+
=begin
|
202
|
+
greppa dalla prima occorrenza di FROM in poi
|
203
|
+
|
204
|
+
=end
|
205
|
+
|
206
|
+
def from_first_line_matching(regex_from)
|
207
|
+
arr_lines = self.split("\n")
|
208
|
+
ix1 = arr_lines.index_regex(regex_from) || 0
|
209
|
+
if ! ix1
|
210
|
+
throw "Cattivo Indice per arr_lines. Non greppa una fava con: #{regex_from}"
|
211
|
+
ix1 = 0
|
212
|
+
end
|
213
|
+
ix2 = arr_lines.length
|
214
|
+
deb "#{ix1}..#{ix2}"
|
215
|
+
joint = arr_lines[ix1..ix2].join("\n") #rescue ''
|
216
|
+
return joint
|
217
|
+
end
|
218
|
+
|
219
|
+
def to_first_line_matching(regex_from)
|
220
|
+
arr_lines = self.split("\n")
|
221
|
+
ix2 = arr_lines.index_regex(regex_from)
|
222
|
+
#ix2 = arr_lines.length
|
223
|
+
return arr_lines[0..ix2].join("\n")
|
224
|
+
end
|
225
|
+
|
226
|
+
end #/Class String
|
227
|
+
|
228
|
+
|
229
|
+
### Miscellaneous string functions
|
230
|
+
|
231
|
+
def clear_screen
|
232
|
+
print "\e[2J\e[f"
|
233
|
+
end
|
234
|
+
alias :clear :clear_screen
|
235
|
+
|
236
|
+
def title(s)
|
237
|
+
title_n(s)
|
238
|
+
end
|
239
|
+
def title_n(s,n=2)
|
240
|
+
"== #{s} =="
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin at purus id ante pulvinar dapibus. Donec risus justo, gravida ac vulputate a, lacinia eget leo. Duis quam tellus, tempus at feugiat a, eleifend et velit. Donec et enim id libero malesuada luctus nec at nibh. Sed elit est, interdum sit amet sollicitudin ac, vulputate eget metus. In hac habitasse platea dictumst. Cras vitae justo at turpis elementum sollicitudin. Etiam quis quam placerat erat tincidunt fermentum. Ut vel mauris magna. Vestibulum luctus leo eget lectus gravida ac dignissim enim vestibulum. Integer facilisis mi sed justo aliquet a lacinia lacus scelerisque.
|
246
|
+
|
247
|
+
Aliquam sed purus vel felis euismod pharetra eu a ipsum. Suspendisse potenti. Mauris aliquet, lorem id mattis ornare, dolor mauris tincidunt tellus, ac feugiat urna sem eget diam. Nulla venenatis urna et elit lobortis eleifend. Ut feugiat adipiscing nisi vitae accumsan. Aliquam ullamcorper odio a nibh scelerisque non tincidunt urna ullamcorper. Sed vitae eleifend quam. Nunc vulputate vulputate viverra. Duis eu enim eros. Nunc lacinia nibh neque, sit amet varius arcu.
|
248
|
+
|
249
|
+
Maecenas facilisis porttitor vestibulum. Phasellus nisl elit, porttitor id pulvinar nec, malesuada quis lectus. Suspendisse lacinia odio vitae eros molestie suscipit. Vivamus eu nulla ac augue adipiscing luctus. Curabitur rhoncus placerat dui a consectetur. Integer suscipit felis vitae eros mattis cursus. Integer sollicitudin ante in risus feugiat tincidunt sed sit amet libero. Nunc molestie lorem ut nulla aliquam viverra. Etiam bibendum mollis mattis. Phasellus ipsum tortor, egestas consequat sollicitudin non, hendrerit eu tortor. Nam at magna ipsum, non convallis ligula. Etiam ac eros a nunc elementum bibendum vitae vitae lacus. Vivamus placerat quam sit amet urna mattis in luctus nulla venenatis. Praesent tempus egestas interdum. Nulla facilisi. Nulla id ligula et nunc egestas dictum sed sodales tellus. Integer vestibulum commodo mauris, blandit porta lectus tincidunt quis. Vestibulum varius est eu turpis ultrices pellentesque.
|
250
|
+
|
251
|
+
Donec aliquam elit quis augue tristique id lacinia augue laoreet. Duis placerat tellus eget urna vehicula volutpat. Vestibulum tortor dui, ultricies quis luctus sed, ultricies sit amet dui. Sed nec magna ac mauris imperdiet venenatis in id velit. Vestibulum non nibh nisi, eu elementum metus. Integer porttitor scelerisque pharetra. Maecenas eu tincidunt augue. Donec viverra diam lacinia ligula rhoncus viverra. Cras dictum rhoncus nisi sit amet malesuada. Quisque consectetur sollicitudin magna, nec faucibus nulla lacinia ac. Donec accumsan gravida odio, nec vehicula enim hendrerit sed. Etiam in mauris et mi sollicitudin congue non sit amet augue. Praesent nisi tortor, posuere vehicula rutrum interdum, tincidunt non tortor. Aliquam adipiscing mollis odio, eget accumsan lectus blandit sed. Sed tristique, ipsum eu laoreet dignissim, nunc nisi rhoncus tellus, sed molestie turpis ante vitae orci. Nullam tincidunt suscipit ligula sit amet sodales. Curabitur auctor tempus rutrum.
|
252
|
+
|
253
|
+
Donec non venenatis lectus. Ut imperdiet felis quis augue viverra pellentesque. Duis sodales, magna at tincidunt volutpat, turpis tellus auctor lacus, et mollis ante odio in tellus. Aliquam euismod tempor aliquam. Vivamus at eros eget felis consequat faucibus dignissim consequat diam. Cras et dolor sagittis mi pharetra tincidunt vitae a tortor. Vestibulum at dictum augue. Sed commodo magna quis lectus bibendum accumsan. Aliquam consectetur feugiat augue, eget suscipit mi mattis ac. Donec at tristique lorem. Nulla non nisl sed felis volutpat ullamcorper." unless defined?(LOREM_IPSUM)
|
254
|
+
|
255
|
+
def lorem_ipsum(len=0)
|
256
|
+
len == 0 ?
|
257
|
+
LOREM_IPSUM :
|
258
|
+
LOREM_IPSUM[0..len]
|
259
|
+
end
|
260
|
+
|
261
|
+
alias :lorem :lorem_ipsum
|
262
|
+
|
263
|
+
# supports: strings, arrays and regexes :)
|
264
|
+
# @returns a Regexp
|
265
|
+
def autoregex(anything)
|
266
|
+
deb "Autoregex() supercool! With a #{blue anything.class}"
|
267
|
+
case anything.class.to_s
|
268
|
+
when 'String'
|
269
|
+
if anything.match(/^\/.*\/$/) # '/asd/' is probably an error! The regex builder trails with '/' automatically
|
270
|
+
fatal 23,"Attention, the regex is a string with trailing '/', are you really SURE this is what you want?!?"
|
271
|
+
end
|
272
|
+
return Regexp.new(anything)
|
273
|
+
when 'Regexp'
|
274
|
+
return anything # already ok
|
275
|
+
when 'Array'
|
276
|
+
return Regexp.new(anything.join('|'))
|
277
|
+
else
|
278
|
+
#msg = "#{__FILE__}.#{__LINE__}: autoregex() Exception: Unknown class for autoregexing: #{red anything.class}"
|
279
|
+
msg = "Unknown class for autoregexing: #{red anything.class}"
|
280
|
+
$stderr.puts( msg )
|
281
|
+
raise( msg )
|
282
|
+
end
|
283
|
+
return nil
|
284
|
+
end
|