Tag Archive
3D 3dprinting android ant BigData bitcoin Browsers C/C++ cryptocurrency CSS dd ddrescue dogecoin DOS editors find Games Git hadoop html html5 Java Linux litecoin node perl Postgres Programming Python scripting Shell SQL Swing TOTK Utilities utilization vi Video Web Web Design Wifi Windows Wordpress XML Zelda
Issue with f.lux and screenshots on Windows 10
Recently I was helping my daughter with some homework and it was going well. That is until I tried to take a screen shot. The screen shot came out with a red tint to everything I captured. It took me a while as I worked through if it was a Snipping Tool issue or a general screen shot issue. It was any screen shot which was even more frustrating. I searched the internet for answers and saw some issues with Lenovo laptops but I am on a HP Laptop so that was no help. I tried updating the drivers for my video cards and that was no help.
Finally I thought of what could be adjusting colors on my computer and remembered I had installed f.lux to help with my sleep patterns as it helps to make the color levels of your monitor change as the night time arrives. It turns out that f.lux was messing with the screen capture and disabling f.lux made my screen captures look correct.
Counting lines, words and characters with wc
There is a simple Linux utility for counting characters, lines and words in files called wc. This allows you to give a file as an argument or a stream and get the counts of the aforementioned items.
wc <filename>
or
cat <filename> | wc
The options that wc accepts
-c,–bytes | print the byte counts |
-m,–chars | print the character counts |
-l,–lines | print the line counts |
-L,–max-line-length | print the length of the longest line |
-w,–words | print the word counts |
The ouput with no arguments will be three numbers (words,lines,characters. Otherwise the the number will reflect the argument you have passed.
And if you pass multiple filenames the output displays counts for all files and totals.
>wc -l HelloWorld.java sample.txt 8 HelloWorld.java 25 sample.txt 33 total
Screen: Send a Ctrl-A to a terminal
When you are using the Linux tool screen, there are times
that I need to send a ctrl-a character. This is a special command key in
screen that drives most of the other commands. But I use the ctrl-a to go
to the beginning of some of my commands and in order for the terminal to
get a ctrl-a you need to use the following key sequence:
ctrl-a a
So to explain, you need to hold ‘control’ or ‘ctrl’ key and the ‘a’ key together
and then release the ‘ctrl’ key and press ‘a’ key and it will send a ctrl-a to
the terminal.
Linux: Processor info and speed
There are times that I get on a Linux box and want to know about some of the resources available to me. There are tools that can accomplish this, but there are some files that contain basic settings about the resources available to the system. One of those file is:
/proc/cpuinfo
This file contains information about the Processors and you can do a simple:
more /proc/cpuinfo
to see all the details or you can grep for certain fields:
processor -- This will show you how many processor entries there are. cpu MHz or MHz -- This will show you the speed of the processors. cache size -- This will show you the cache size available to the processor. model -- This will show you the type and model of the processor you are using.
There are quite a few more fields, but these are the ones that I check the most.
Perl: Hashes
Here are some basics about Perl hashes that can be helpful to be used when an you need to associate a label with some value such as for names and telephone numbers or account numbers with amounts owed.
Create a hash variable.
my %hashvar;
Create a hash reference
my $refhash = {};
Add a value to a hash variable.
$hashvar{'somekey'} = 'someval';
Add a value to a hash reference.
$hashref->{'somekey'} = 'someotherval';
Access a value in a hash.
print $hashvar{'somekey'};
Access a value in a hash reference.
print $hashref->{'somekey}';
Access all Keys in a hash variable.
foreach my $k (keys(%hashvar))
{
print $hashvar{$k};
}
Access all Keys in a hash reference.
foreach my $k (keys(%$hashref)) { print $k . "n"; }
Access all Keys and values in a hash.
while (my ($key,$value) = each %hashvar) { print "Key: " . $key . " has value:" . $value . "n"; }
Access all Keys and values in a hash.
while (my ($key,$value) = each %$refhash) { print "Key: " . $key . " has value:" . $value . "n"; }
Assigning multiple values to a hash
%hasvar = ( 'test2' => 'myval', 'test3' => 'myval3' );
Note: This will clear the existing hash.
Delete a value from a hash
delete $hashvar{'key1'};
Delete a value from a hash reference.
delete $hashref->{'key1'};
Linux:Script to find files
I regularly have to find where a file is located and usually use find:
find . | grep
Where
#!/bin/sh if [ $# -lt 1 ]; then echo 1>&2 Usage: $0 "" exit 127 fi icase= while [ $# -ge 1 ]; do case $1 in -i) icase=$1;; *) search=$1 ;; esac shift done find . | grep $icase $search
This is just a simple script which I have named ffind that searches starting from the current directory. This lets me search with the following commands:
ffind bak$
This will search for all files that end with “bak” .
ffind -i edr
This will search for all files with “edr” regardless of case
Using find and grep to search files
I have been searching through source code and files for years. And I used to use find with a few arguments to get what I was looking for.
find . -exec grep {} ; -print
I used the -print after the exec arguments to show the file only when the grep succeeded. This worked but was a bit to type each time I used it. So I came up with a little script that would help me to search for the an argument and even allow a case insensitive search as well.
#!/bin/sh if [ $# -lt 1 ]; then echo 1>&2 Usage: $0 "" exit 127 fi icase= search= while [ $# -ge 1 ]; do case $1 in -i) icase=$1;; *) search=$1 ;; esac shift done find . -type f -print0 | xargs -0 grep $icase $search
The script takes at least one argument and excepts a ‘-i’ argument to make grep use a case insensitive search. This will print the file name and the line that matches the search term. It can be easily adapted to show the count of matched patterns (‘-c’) or the line number (‘-n’).
Mounting drives in Linux
Sometimes you have a drive that your want to mount under Linux. The mount command can make the drive available to you. But you need to also create a directory to hold the mount point.
mkdir /mnt/drivepoint
Then you can mount the drive to that mount point by using the mount command and giving the device identifier, in this case it is /dev/sda1, and the mount point which we created as /mnt/drivepoint. One thing to note, is that the mount will use whatever directory you specify, so if there are files located in the directory you use as a mount point, they will no longer be visible.
mount /dev/sda1 /mnt/drivepoint
This must be run as root or with the sudo command.
Windows: Grep for windows
If you don’t have access to a Unix environment on your windows box, you can still search files with findstr. The findstr command will allow you to search files close to the same way as grep.
findstr /S "search string"
will recursively find your string in the current directory and subdirectories.
There are more options that you can find if you run the following command:
findstr /?
will show you the help message.
Capturing the screen in Windows
For the longest time, I thought the “Print Screen” or “PrtScr” Key on my keyboard was a throw back to much older computers with sheet fed dot matrix printers and would just print out the current Dos command shell.
Once I figured out how to use it in windows, it has become an invaluable tool.
I used to create presentations of source code issues. It was a great help to be able to grab a copy of the screen and place it in a Powerpoint slide or Word Doc.
If you need a complete screen capture or even just the current window, here is what you can do.
If you need to capture the complete screen, press the “Print Screen” button located near the top of the keyboard with the scroll lock or Pause key. It may seem like nothing has happened, but the complete image of your current desktop has been saved into the clipboard in windows.
If you want to just capture the current window, make sure the window you want is active and press the Alt and “Print Screen” keys together.
Now open Paint, MS Word or any other program capable of handling images, and type Ctrl-V. This will take the image that has been captured into memory and place it in the program. Now you can manipulate the image to crop it or use it in your document.
This is a built in function of the MS Windows Operating system.
If you need more control there are other applications that can let you capture portions of the screen at any time and create a file with a simple keystroke, such as SnagIt!