A programmer’s wife sends him to the grocery store with the instructions, “get a loaf of bread, and if they have eggs, get a dozen.” He comes home with a dozen loaf of bread and tells her, “they had eggs.”
Google+: View post on Google+
Post imported by Google+Blog. Created By Daniel Treadwell.
Any JavaScript programmers out there? I'm trying to figure out why x[count] changes in the next loop iteration without me touching it when I do this:
for (var count = 0; count < 7; count++){
x[count] = y[count];
}
but it stays the same when I do this:
for (var count = 0; count < 7; count++){
x[count] = y[count] + 0;
}
Yes, I sat here for hours banging my head and all I added was a "+ 0". When is the last time "+ 0" solved anything? Did JavaScript all the sudden say "hey, lets treat this as a variable instead of a string!", or maybe I somehow created a reference?
Google+: View post on Google+
Post imported by Google+Blog. Created By Daniel Treadwell.
Ice Ice Baby (in C++)
- KristoffI powered up an old box I used to play around on and found a file called ice.cpp. I guess this is what Vanilla Ice would come up with if he were a C++ programmer? Man, I used to do some weird stuff…
stop(); if(collaberate && listen){ ice = back; width(new invention); something.grabs(me, "tightly"); harpoon>>daily>>nightly; if(stop){ lights = 0; VanillaIce.glow = 1; rockMike("vandal"); lights = 1; Chump.wax("candle"); } }
stop();
if(collaberate && listen){
ice = back;
width(new invention);
something.grabs(me, "tightly");
harpoon>>daily>>nightly;
if(stop){
lights = 0;
VanillaIce.glow = 1;
rockMike("vandal");
lights = 1;
Chump.wax("candle");
}
}Feel free to comment!
http://www.hackingforkids.com/?p=50209
Embedded Link
Kristoff’s Linux Tips and Tricks
I’ve been collecting tips and tricks over the years working as a linux engineer. A lot are pretty simple, some are a bit more advanced. Feel free comment with any questions or suggestions! Ba…
Google+: View post on Google+
Post imported by Google+Blog. Created By Daniel Treadwell.
Kristoff’s Linux Tips and Tricks
- KristoffI’ve been collecting tips and tricks over the years working as a linux engineer. A lot are pretty simple, some are a bit more advanced. Feel free comment with any questions or suggestions!
Bash Tricks
Find the largest files on a system
This will output a very nice stylized list like so:
[root@upgrayedd ~]# find / -size +100M -printf '%k %p\n' 2> /dev/null | sort -nr | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf 1.0 G ******************** /home/kris/Videos/Miro/Uploads-by-ComputerHistory/videoplayback-upn=m_QO_nJsugQ_sparams=cp,id,ip,ipbits,itag,.84494F724332988A7D79CF622EB53CFD5709DA5C.mp4 869.0 M ******************** /home/kris/Videos/Miro/Uploads-by-ComputerHistory/videoplayback-upn=Z7EuUGE7A8c_sparams=cp,id,ip,ipbits,itag,.3499AD411FFA0B830460CB619600181C21CADA7C.mp4 700.6 M ******************** /home/kris/Videos/Miro/Uploads-by-ComputerHistory/videoplayback-upn=pp_vMJGe03w_sparams=cp,id,ip,ipbits,itag,.A29E845C92F058212D3CEA59844B3165A7C93C79.mp4 420.6 M ******************* /home/kris/Videos/Miro/Hak5--HD-MP4-/hak5--1213--how-to-remove-amazon-from-your-ubuntu--hd720p30.h264.mp4 396.9 M ******************* /home/kris/Videos/Miro/Hak5--HD-MP4-/hak5--1215--use-wine-in-computers--hd720p30.h264.mp4 147.5 M ***************** /home/kris/montagueot.tar.gz 113.2 M ***************** /home/kris/Dropbox/Camera Uploads/2012-09-12 20.24.02.m4v 110.6 M ***************** /var/cache/yum/i386/17/fedora/gen/filelists_db.sqlite 110.3 M ***************** /home/kris/Videos/Miro/TEDTalks--hd-/BobbyGhosh_2012X-480p.mp4 108.4 M ***************** /home/kris/Dropbox/Camera Uploads/2012-12-30 22.06.10.m4v 108.2 M ***************** /home/kris/Videos/Miro/Nixie-Pixel-Geekbuzz--HD-MP4---30fps-/nixiepixel--0046--pelican-case-u100--hd720p30.h264.mp4 104.3 M ***************** /home/kris/Videos/Miro/TEDTalks--hd-/JonathanTrent_2012G-480p.mp4 100.1 M ***************** /usr/lib/locale/locale-archive
[root@upgrayedd ~]# find / -size +100M -printf '%k %p\n' 2> /dev/null | sort -nr | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf 1.0 G ******************** /home/kris/Videos/Miro/Uploads-by-ComputerHistory/videoplayback-upn=m_QO_nJsugQ_sparams=cp,id,ip,ipbits,itag,.84494F724332988A7D79CF622EB53CFD5709DA5C.mp4
869.0 M ******************** /home/kris/Videos/Miro/Uploads-by-ComputerHistory/videoplayback-upn=Z7EuUGE7A8c_sparams=cp,id,ip,ipbits,itag,.3499AD411FFA0B830460CB619600181C21CADA7C.mp4
700.6 M ******************** /home/kris/Videos/Miro/Uploads-by-ComputerHistory/videoplayback-upn=pp_vMJGe03w_sparams=cp,id,ip,ipbits,itag,.A29E845C92F058212D3CEA59844B3165A7C93C79.mp4
420.6 M ******************* /home/kris/Videos/Miro/Hak5--HD-MP4-/hak5--1213--how-to-remove-amazon-from-your-ubuntu--hd720p30.h264.mp4
396.9 M ******************* /home/kris/Videos/Miro/Hak5--HD-MP4-/hak5--1215--use-wine-in-computers--hd720p30.h264.mp4
147.5 M ***************** /home/kris/montagueot.tar.gz
113.2 M ***************** /home/kris/Dropbox/Camera Uploads/2012-09-12 20.24.02.m4v
110.6 M ***************** /var/cache/yum/i386/17/fedora/gen/filelists_db.sqlite
110.3 M ***************** /home/kris/Videos/Miro/TEDTalks--hd-/BobbyGhosh_2012X-480p.mp4
108.4 M ***************** /home/kris/Dropbox/Camera Uploads/2012-12-30 22.06.10.m4v
108.2 M ***************** /home/kris/Videos/Miro/Nixie-Pixel-Geekbuzz--HD-MP4---30fps-/nixiepixel--0046--pelican-case-u100--hd720p30.h264.mp4
104.3 M ***************** /home/kris/Videos/Miro/TEDTalks--hd-/JonathanTrent_2012G-480p.mp4
100.1 M ***************** /usr/lib/locale/locale-archiveChange the “500M” to whatever you want. Swich the M to a G if you’d like to search for gigabyte sized files.
find / -size +500M -printf '%k %p\n' 2> /dev/null | sort -nr | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf ("%6.1f\t%s\t%25s %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}'
find / -size +500M -printf '%k %p\n' 2> /dev/null | sort -nr | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf ("%6.1f\t%s\t%25s %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}'Change to the last working directory
Useful if you temporarily change to a directory and want to get back to where you were.
cd -cd -
Filter out comments and blank lines from configuration files
Tired of all those comments and blank lines in configuration files? Try this out for a clearer view.
grep -Ev "^#|^$" foobar.conf
grep -Ev "^#|^$" foobar.conf
Filter out comments and blank lines from configuration files w/ syntax highlighting
Want syntax highlighting? Check this out. Type “:q!” to exit vim.
grep -Ev "^#|^$" foobar.conf | vim -Rc 'set ft=conf' -
grep -Ev "^#|^$" foobar.conf | vim -Rc 'set ft=conf' -
Convert epoch time to human time
That ugly large number is epoch.
date -d @1317755469
date -d @1317755469
Delete files older than 7 days
This will find all files ending with .gz. Change that to whatever extension you want. Remove everything after the “+7″ to test and not actually delete anything (highly recommended).
find /var/log/*.gz -type f -mtime +7 -exec rm {} \;
find /var/log/*.gz -type f -mtime +7 -exec rm {} \;See if a package is available on a RedHat system
yum list packagename
yum list packagename
Clear a Dell DRAC ESM log
omconfig system esmlog action=clear
omconfig system esmlog action=clear
Find what domains in a list are not legit
Put a list of domains into domains_file, one domain per line.
for x in $(cat domains_file); do host $x > /dev/null ; if [ $? -ne 0 ]; then echo "$x"; fi; done
for x in $(cat domains_file); do host $x > /dev/null ; if [ $? -ne 0 ]; then echo "$x"; fi; done
Reverse your grep
This will show everything in a file except what you’re searching for.
grep -v "dumb monkey" filename
grep -v "dumb monkey" filename
Search for multiple things
You can do some fun stuff with regular expressions and grep. I’ve found this the most useful.
egrep "dog|cat|capybara" filename
egrep "dog|cat|capybara" filename
OR
grep -E "dog|cat|capybara" filename
grep -E "dog|cat|capybara" filename
List files in order by date
This will show the newest files first.
ls -lt
ls -lt
This will show the oldest files first.
ls -ltr
ls -ltr
E-mail with attachment
This will let you send a file via commandline with an attached file. Note that the file you want to attach is the “origname.txt” and the second filename can be whatever you want (or the same as the original filename). Either way, you have to specify a filename twice.
(echo "Body of message here"; uuencode origname.txt attachmentname.txt) | mail -s "Subject Goes Here" user@example.com
(echo "Body of message here"; uuencode origname.txt attachmentname.txt) | mail -s "Subject Goes Here" user@example.com
Send an email with attachment and body
Same as above, except put your actual message into body.txt.
(cat body.txt; uuencode origname.txt attachmentname.txt) | mail awesome_person@gmail.com
(cat body.txt; uuencode origname.txt attachmentname.txt) | mail awesome_person@gmail.com
Quickly show how many CPUs a box has:
cat /proc/cpuinfo | grep processor | wc -l
cat /proc/cpuinfo | grep processor | wc -l
Find out what is taking up free space
Keep on adding to the path at the end until you find the culprit(s):
du -hx --max-depth=1 /
du -hx --max-depth=1 /
Remove leading whitespace from file
Where pizza_rocks is filename:
cat pizza_rocks | sed -e 's/^[ \t]*//'
cat pizza_rocks | sed -e 's/^[ \t]*//'
To sort a file by column
Where the number 2 is the number of column to sort by:
sort -k2 awesomefilename
sort -k2 awesomefilename
Is echo/bash displaying things on different lines when it shouldn’t be?
Set the internal field separator (IFS) variable back:
IFS=$'\n'
IFS=$'\n'
Use last command starting with foo
Not recommended for potentially dangerous commands such as rm:
!foo!foo
To change the hostname on a Cent/RedHat box
Recommended restart after change instead of changing $HOSTNAME.:
vim /etc/sysconfig/network
vim /etc/sysconfig/network
“Disown” a job
So you can close the terminal and it will continue to run (where jobID is the job you want disowned):
jobs; disown %jobID
jobs; disown %jobID
Create a large list of IPs
ex. 255.255.0.0, each on newline:
echo -e 192.168.{1..255}.{1..255} >> ips; tr ' ' '\n' < ips > endresult
echo -e 192.168.{1..255}.{1..255} >> ips; tr ' ' '\n' < ips > endresultExecute command on each line in file
Where zaphodbeeblebrox is filename:
for LINE in $( cat zaphodbeeblebrox ) ; do echo "$LINE" ; done
for LINE in $( cat zaphodbeeblebrox ) ; do echo "$LINE" ; done
Show free memory (physical and swap) on a box
free -m
free -m
To override an alias
Use single quotes around command:
'cp' -rf ~/illegalmp3s /media/thumbdrive
'cp' -rf ~/illegalmp3s /media/thumbdrive
OR use a backslash at the beginning of the line
\cp -rf ~/illegalmp3s /media/thumbdrive
\cp -rf ~/illegalmp3s /media/thumbdrive
To tar gzip a folder
tar czvf roflcopter.tar.gz roflcopter/
tar czvf roflcopter.tar.gz roflcopter/
To decompress a tar.gz file
tar xvfz monkeydoodles.tar.gztar xvfz monkeydoodles.tar.gz
To turn off the PC speaker beep in BASH
setterm -blength 0
setterm -blength 0
Paswordless SSH login
(host A, host B)
ssh-keygen -t rsa (on A), cat .ssh/id_rsa.pub | ssh username@B 'cat >> .ssh/authorized_keys'
ssh-keygen -t rsa (on A), cat .ssh/id_rsa.pub | ssh username@B 'cat >> .ssh/authorized_keys'
Generate SHA password for LDAP
As root, hax0r is password)
slappasswd -h {SHA} -s hax0r
slappasswd -h {SHA} -s hax0rDownload entire website w/ bandwidth speed limit
wget --wait=20 --limit-rate=20K -r -p -U Mozilla http://www.hackingforkids.com
wget --wait=20 --limit-rate=20K -r -p -U Mozilla http://www.hackingforkids.com
To see what is in the clipboard buffer every 2 seconds
Useful when pasting to IRC
watch -n 10 xclip -o
watch -n 10 xclip -o
Execute command on each line in file “foo”
for line in `cat foo`; do command $line; done;
for line in `cat foo`; do command $line; done;
To check what kind of architecture a system is running
uname -a
uname -a
To pull files via scp
Example is to pull all files in one dir into home directory on local machine.
scp username@hostname:Documents/* ~
scp username@hostname:Documents/* ~
To see what process is listening on a port
Where tcp is protocol (can use udp) and 80 is port:
sudo fuser -v -n tcp 80
sudo fuser -v -n tcp 80
Show line numbers with less
less -N file
less -N file
To show stdout and stderr to screen and also write to file
-a flag appends to file. Note that “tee” may need to be installed.
programname | tee -a logfilename 2>&1
programname | tee -a logfilename 2>&1
To get a list of users on a system
cut -d: -f1 /etc/passwd
cut -d: -f1 /etc/passwd
To show only unique lines in a file
Foobar is filename
sort foobar | uniq
sort foobar | uniq
To set the number for a screen session
When showing as a list
Ctrl+a, type a colon, then type in "number 24" (no quotes & 24 is win #)
Ctrl+a, type a colon, then type in "number 24" (no quotes & 24 is win #)
Color manpages
1) Install most (apt-get install most), 2) Add the following to ~/.bashrc:
export MANPAGER="/usr/bin/most -s"
export MANPAGER="/usr/bin/most -s"
To push remotely a file to another server
copyme is file to be copied
scp /usr/local/bin/copyme username@remoteservername:/home/username/
scp /usr/local/bin/copyme username@remoteservername:/home/username/
To remove leading spaces from a file
sed 's/^[ \t]*//;s/[ \t]*$//' filename
sed 's/^[ \t]*//;s/[ \t]*$//' filename
To do a direct filesystem copy
Where sda is the source and sdb is the destination
dd if=/dev/sda of=/dev/sdb
dd if=/dev/sda of=/dev/sdb
To grep all .gz files in one directory
zgrep 'ohai' *.gz
zgrep 'ohai' *.gz
To change file attributes on a file
Example will lock a file down so even root can’t delete (uses +/- to add/remove)
chattr +i filenamechattr +i filename
To create a text dialog
You can also create menus for input and other cool things:
dialog --title 'Message' --msgbox 'Hello, world!' 5 20
dialog --title 'Message' --msgbox 'Hello, world!' 5 20
To append an IP range to a file with bash brace expansion
echo -e 192.168.1.{1..255}"\n" >> out
echo -e 192.168.1.{1..255}"\n" >> outVim Tricks
Delete whitespace from the beginning of lines
:%le:%le
To map a function key
Press the key first to see if your window manager traps it. This will execute the current file.
:map : !%:p:map : !%:p
Execute the script that is currently being edited
:!%:p:!%:p
Toggle visible whitespace
:set list!
:set list!
Show manpage for command under cursor
K
K
Run make in current directory
:make:make
Show line numbers
:set number:set number
Turn off line numbers
:set nonumber:set nonumber
To remove blank lines
:v/./d
:v/./d
Change VIM color scheme
“Colo” is short for “colorscheme”. Type that in, space, then control + d to show a list of options. Then start typing in a scheme you want and tab out the rest
:colo adrian wombat256mod default elflord morning peachpuff slate codeschool blue delek evening murphy ron torte vividchalk darkblue desert koehler pablo shine zellner
:colo adrian wombat256mod default elflord morning peachpuff slate codeschool blue delek evening murphy ron torte vividchalk darkblue desert koehler pablo shine zellner
:colo evening
:colo evening
Write + execute script
This will save and execute a script you are currently working on. Add this to your ~/.vimrc. Press F8 in VIM to use.
:map! :w :!%:p :map :w :!%:p
:map! :w :!%:p :map :w :!%:p
Sometimes this doesn’t work right, so I normally use this as a backup instead. This won’t save the file first, so it’ll execute whatever you have saved already. Press F7 in VIM to use.
:map :!%:p :map! :!%:p
:map :!%:p :map! :!%:p
Just For Fun
Sample different cowsay “cows”
Press Enter for next cow
for x in $(ls /usr/share/cowsay/cows); do cowsay -f $x Oh dang.; input; done
for x in $(ls /usr/share/cowsay/cows); do cowsay -f $x Oh dang.; input; done
To output banner-like messages (w/ colors).
You can also output in HTML and IRC colors.
toilet -w 200 -f bigmono9 --gay Hello world!
toilet -w 200 -f bigmono9 --gay Hello world!
A dancing 3d juggler
For the holidays!
/usr/lib/xscreensaver/juggler3d -pattern "2 2"
/usr/lib/xscreensaver/juggler3d -pattern "2 2"
Other
Use less when using mysql interactively
When using mysql, use command:
pager less;pager less;
In HP-UX, if the backspace simply enters a ^? instead of erasing, do the following
Good idea to add to your ~/.profile
stty erase ^?stty erase ^?
Get MAC/IP of DRAC
When ssh’d into system
omreport chassis remoteaccess
omreport chassis remoteaccess
Starting January 19th, I'm going to refrain to the best of my abilities from using Facebook and G+ at all, as well as watching TV and playing video games. I'm going to take this time to up my game and become better. Better at what? Well, better at what I do, and better at what I'd like to be doing. I'm going to focus on doing my job better as well as getting back into shape. I now have a fiance (and a puppy) to support and I've got a good start already. I'm going to shape up to make the best of my life, to make things financially right, and to let myself have some fun with what I do. Life is full of potential and opportunities for us all. You may not think so, but it's true for even you. Social networking has been sort of a sickness for me in particular lately, and it's time to stop.
I remember when I was younger, when I had nothing else I wanted to do other than ride my bike, split wood, work out, and read computer books. I had focus back then because there wasn't much to distract me. There was no Facebook, there was no 42" TV sitting in front of me, and there weren't a lot of really fun games sitting at my disposal. I was kickass, I was on my game, and I've slipped. I want to be that person again. I desperately want to be who I was, because I'm ashamed of who I am now.
I haven't seen a lot of you in years, yet I read what you're doing every day. Unless you're part of my life, it's time to let go of being "friends". If you want to actually hang out sometime, message me with your email address or number, or just get get my number from my profile. I'll be unfriending most of you after a month.
The technicals? I'm going to block social networking sites on my router as well as blackhole the sites in my hosts files. I'm also going to get rid of the apps on my phone. I'd get rid of Internet here at home, but my job kinda requires it, and it's going to be useful for learning new things. I'm also going to get rid of Netflix for a bit, which I should do anyway since I rarely watch it. And last, I'm going to unplug the mess that is my entertainment center, less the wireless router.
Seriously though, if you ever want to hear of me again … ever, give me some contact information. I have a suspicion that I may deactivate my Facebook account after all of this. And if we've never hung out before, it doesn't matter. Good breweries are in abundance around here, and I'd be glad to meet some of you there.
Google+: View post on Google+
Post imported by Google+Blog. Created By Daniel Treadwell.




