Linux
unix
http://www.namhuy.net/3116/how-to-fix-gpg-error-no_pubkey-in-ubuntu.html
commands
chmod -R 777 /var/backups/dog sudo chown -R tim www du -ah /var/www //gives size of directory and everything in it vim . //opens vim with directory tree rename_a_file mv oldname newname landscape-sysinfo grep -r "siteUrlis dog" /var/www/fworks/meteor/epool //search for text recursively sudo ps -x | grep meteor sudo kill -s KILL 29484
finding port of address already in use
$ sudo netstat -nlp | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 125004/nginx
or
# sudo lsof -i :25 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME exim4 2799 Debian-exim 3u IPv4 6645 0t0 TCP localhost:smtp (LISTEN) exim4 2799 Debian-exim 4u IPv6 6646 0t0 TCP localhost:smtp (LISTEN)
perl
handy code
remove blank lines from file
perl -wnl -e 'print $_ unless /^$/' infile.txt >outfile.txt
sed awk
- SED tutorial
- http://tech.bluesmoon.info/2008/09/programming-patterns-in-sed.html
- http://www.vectorsite.net/tsawk_2.html
- lib/images/toolbar/list_ul.png
- lib/images/toolbar/rule.png
- lib/tpl/default/images/interwiki.png
People with shell access to their server can copy the text above and paste it into a file on the system, then run the following commands to check for and remove all those files. Only those that exist are removed.
grep -Ev "^($|#)" /tmp/removeold.txt | xargs -n 1 rm -f
If you are paranoid, replace the "rm -f" with "ls -la" to see what files will be deleted.
To remove directories as well as files you have to use:
grep -Ev "^($|#)" /tmp/removeold.txt | xargs -n 1 rm -fd
However, some systems may not support the "rm -d" option for directory removal. In that case, you have to use recursive removal (just be sure to double-check that the file list does not include any paths that will delete too much):
grep -Ev "^($|#)" /tmp/removeold.txt | xargs -n 1 rm -fr
regex
https://alligator.io/js/regular-expressions-for-regular-people/
http://exploringjs.com/impatient-js/ch_regular-expressions.html
https://www.smashingmagazine.com/2019/02/regexp-features-regular-expressions/
php example
$search = array( '@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments );
$output = preg_replace($search, , $input); return $output; }
?> <?php function sanitize($input) {
if (is_array($input)) { foreach($input as $var=>$val) { $output[$var] = sanitize($val); } } else { if (get_magic_quotes_gpc()) { $input = stripslashes($input); } $input = cleanInput($input); $output = mysql_real_escape_string($input); } return $output;
}
typical
A username fro 3- 16 characters w -or_ /^[a-z0-9_-]{3,16}$/
a password 6-18 long /^[a-z0-9_-]{6,18}$/
a hex number /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
- a number sign is optional because it is followed a question mark but if there takes it(greedy)
- 6 characters or 3 character
a slug /^[a-z0-9-]+$/
- beginning of the string (^), followed by one or more (the plus sign) letters, numbers, or hyphens. and the end of the string ($).
an email /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
- . get delimited \.
- each section in parens
only lower case, nubers or dots'/[^a-z0-9.]/'
url /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
- s? s if you got em
- delimit / and . with \
- you don't need http at all (https?:\/\/)? but be greedy
- \d is any number
- ([\da-z\.-]+) numbers letters dotts or hyphens
- \.([a-z\.]{2,6})~ .com .co .commie
- ([\/\w \.-]*)*\/?$/ files and directories
- ([\/\w \.-]*) * is zero or more, \w is words
html tag /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
- .* any characters
- ([^<]+) any characters but a <
- (?:>(.*)<\/\1>|\s+\/>) non-capture group.it will contain either a greater than sign, some content, and a closing tag; or some spaces, a forward slash, and a greater than sign \1 represents the content that was captured in the first capturing group
no dots: ^[^\.]*$
^ - beginning of string [^\.]* - any character except ., any number of repetitions $ - end of string
replace spaces and punctuation with nothing str.replace(/\W/g, )
- \W not letters digits or underscores
to take out all non alpha characters (Ruby)
test_str = "Madam, I'm Adam" str = test_str.gsub(/[^a-zA-Z]/,'') puts str returns MadamImAdam
- ^[ \t]+ //finds all the space and tabs
- [1-9]\. //finds all the line numbers. (replace with #)
- [A-E]\. //find A. etc (replace with ##)
to clean special characters from a string
$clean = preg_replace("/^[^a-z0-9]?(.*?)[^a-z0-9]?$/i", "$1", $text);
sites
- http://rubular.com
- http://e-texteditor.com/blog/2010/beyond-vi
- http://www.grymoire.com/Unix/Regular.html#uh-2
- http://www.regular-expressions.info/php.html
- http://www.bluebox.net/about/blog/2013/02/using-regular-expressions-in-ruby-part-1-of-3/
expressions
If you want to get'Aloha World'out
Input:
RegEx:
\<div\sclass\=\"somename\"\>(?<Text>.*?)\<\/div\>
Yields:
Aloha World (note: In a single group named Text)