Skip to content

Instantly share code, notes, and snippets.

def stat(path)
if File.exist?(path)
File.stat(path.to_s)
else
nil
end
end
The below ,removes anything but ascii characters like:
variant_type.gsub!(/[^0-9A-Za-z.\-]/, '')
sql = "INSERT INTO my_table VALUES(#{rows[i].map{|x| x.inspect}.join(', ')})"
vs
sql = "INSERT INTO my_table VALUES(#{ ary.map{ |i| '"%s"' % i }.join(', ') })"
TODO:
Add these two lines to your ~/.inputrc file:
"\eOC": forward-word
"\eOD": backward-word
and press Ctrl-x Ctrl-r to reread the file to make the changes active in your current session.
You will be able to use Ctrl-Right and Ctrl-Left to move right or left word by word.
http://donsnotes.com/tech/charsets/ascii.html
x1F
\x00 =>> null ...
Control Characters
CTRL (^D means to hold the CTRL key and hit d)
Oct Dec Char Hex Key Comments
\000 0 NUL \x00 ^@ \0 (Null byte)
#in vim
echo &encoding
# count lines with grep
za:~ za$ grep -c ".*" file.txt
2 for Hexadecimal, you could use hd
echo Hello world | hd
Bitwise , beause we operate on bits ..example the number 5 has the binary represenation of 01100001 . Bits can also be translated into
true or false.where repersenting a number where 1 will be false and 0 will be true.
Given two binary strings, complete the following logic operation:
01101 xor 01101
The answer is :
01101
@codepedia
codepedia / rails
Last active January 30, 2016 05:08
rails notes
<!-- <%= link_to ' log out ', destroy_user_session_path, :method => :delete %>
<%= link_to(
#want to read more about this helper ...content_tag =>> http://apidock.com/rails/ActionView/Helpers/TagHelper/content_tag
content_tag(
# adda div or h3 here for "log out"
:i,
nil,
class: 'fa fa-user-times'
),
# Find out if you are root or not for admin tasks.
(( EUID )) && { echo 'Run this script with root priviliges.'; exit 1; } || echo 'Running as root, starting service...'
find userID:
]$ id -u
44502
#za:~ za$ brew search /*\net*/
#!/bin/sh
Print keys and values from hash
The \A and \Z are just like "^" and "$"
my @keys;
while (<>) {
chomp; # Or: s/\s+\z//;
push @keys, $_;
}
# returns back what was changed after gitting pull locally.
git diff HEAD^^ HEAD nmae/of/thefile.rb
FYI ,
# this will show what was last added your local "showing newly added changes"
git diff --color HEAD^ HEAD
# this will do the reverse .. it will show the commit prior to pulling from the remote.
git diff --color HEAD HEAD^