70 karma · joined September 20, 2017
ruby -e 'x = "a\n25\n" ; if x =~ /^\d+$/ ; puts "yes" ; else ; puts "no" ; end'
yes
Good to know. $ ruby -e 'x = "25" ; if x =~ /^\d+$/ ; puts "yes" ; else ; puts "no" ; end'
yes
$ ruby -e 'x = "25\n" ; if x =~ /^\d+$/ ; puts "yes" ; else ; puts "no" ; end'
yes
$ ruby -e 'x = "a25\n" ; if x =~ /^\d+$/ ; puts "yes" ; else ; puts "no" ; end'
no
Also, you'd want to use something that parameterizes the query with '?' (I use the Sequel gem) instead of just stuffing it into a sql string.https://en.wikipedia.org/wiki/Number_form
https://www.discovermagazine.com/health/the-rare-humans-who-...
http://www.cs.cmu.edu/afs/.cs.cmu.edu/help/content/unix_linu...
Consolidating everything you want into /usr/local (exclude packages you don't want). I used to use this at my old job before package managers were ubiquitous.
https://en.wikipedia.org/wiki/Number_form
https://www.discovermagazine.com/health/the-rare-humans-who-see-time-and-have-amazing-memoriesJust because there are attacks or ways around a particular defense doesn't mean it's worthless, that's why we have defense in depth.
% cat /tmp/sh
var=variables
x=$(
cat <<EOT
This string has 'single' and "double" quotes and can interpolate '$var'
EOT
)
echo $x
% bash /tmp/sh
This string has 'single' and "double" quotes and can interpolate 'variables' command | ruby -e 'ARGF.each { |line| #do stuff with line }' (long pipeline that generates lots of output) | xclip
Or even just xclip < /some/file
Now paste where necessary. cat /etc/passwd | grep root | awk -F: '{print $3}'
ruby -e 'puts File.read("/etc/passwd").lines.select { |line| line.match(/root/) }.first.split(":")[2]'
A little more verbose, but the idea is the same.https://alvinalexander.com/scala/fp-book/how-functional-prog...
It's an amazing series. Must watch if you want to know how much we humans understand about our universe.
https://en.wikipedia.org/wiki/Organlegging
Lovely. % echo 'one\ntwo\nthree' | sed -e 's,$, four,'
one four
two four
three fourSweetleaf is generally what I use.
# events per day
ndbh.fetch('select ts from tbl').all.map { |row|
row[:ts]
}.map { |t|
t.strftime('%Y-%m-%d')
}.each { |day|
days[day] += 1
}
(yes this could be conciser)This is generally frowned on, and I'm sure everyone who likes having this style
foo
.map {}
.select {}
.blah {}
will frown as well, but it's so much more visually appealing to me, coming from a C/perl background when I first encountered Ruby (many years ago).Funny how important syntax is. So easy to look at code in another style/language and go THATS NOT RIGHT!!