random notes
05 January 2018
Recursively delete files in Windows
Recursively delete files in a folder with long file names:
robocopy /MIR D:\temp\empty D:\folder\with\long\names
robocopy will recursively copy files. But with /MIR switch, there is an attempt to mirror source folder to destination folder.
If destination folder is having files with long file names and is getting difficult to delete, you can force it to mirror an empty folder which will recursively delete it in an attempt to mirror an empty folder.
Neat trick.
Source : http://clintboessen.blogspot.com.au/2014/05/how-to-delete-files-which-exceed-255.html
20 May 2016
Example apps for Tomcat and JBoss
I would personally encourage you to try tomEE+ and they have examples for you to try out as well.
You can also see tomcat supported versions and tomEE supported versions for the JEE environment.
If you are thinking JBoss Wildfly, take a look at the Ticket Monster example app by JBoss.
08 February 2016
Git Branching and Merging
New Branch
-----------
To create a new branch
$ git checkout -b BRANCH-NAME
This is same as
$ git branch BRANCH-NAME
$ git checkout BRANCH-NAME
New Tag
-------
Create a new tag. This will create one locally
$ git tag -a TAG-NAME -m "commit message"
Push the new created tag to remote
$ git push --follow-tags
To view git tag message
$ git tag --list
Merge Branches
--------------
Note: When merging, it's the local copies that get merged. So make sure you have the latest copies locally for both branches.
To merge your branch to master
Switched to branch 'master'
$ git checkout master
$ git pull
Assuming you have the latest in your branch.
$ git merge BRANCH-NAME
If there are any merge conflicts, then you have to resolve them first before you push the merge. So after resolving any conflicts, just push the merge
$ git commit origin master
$ git push origin master
-----------
To create a new branch
$ git checkout -b BRANCH-NAME
This is same as
$ git branch BRANCH-NAME
$ git checkout BRANCH-NAME
New Tag
-------
Create a new tag. This will create one locally
$ git tag -a TAG-NAME -m "commit message"
Push the new created tag to remote
$ git push --follow-tags
To view git tag message
$ git tag --list
Merge Branches
--------------
Note: When merging, it's the local copies that get merged. So make sure you have the latest copies locally for both branches.
To merge your branch to master
Switched to branch 'master'
$ git checkout master
$ git pull
Assuming you have the latest in your branch.
$ git merge BRANCH-NAME
If there are any merge conflicts, then you have to resolve them first before you push the merge. So after resolving any conflicts, just push the merge
$ git commit origin master
$ git push origin master
14 August 2014
Working with multiple jdk's on your local
I installed multiple jdk's on my local today. Played around a bit and figured out this is how I can easily switch between them!
> java -version:1.7 -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
> java -version:1.8 -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
If I want to use specific java version to run my eclipse, I will have to set the "-vm" variable in the eclipse.ini file like so:
Reference:
1. multipe java on stackoverflow
2. Eclipse - Specifying the JVM
> java -version:1.7 -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
> java -version:1.8 -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
If I want to use specific java version to run my eclipse, I will have to set the "-vm" variable in the eclipse.ini file like so:
-vm C:\Program Files\Java\jdk1.8.0_11\bin\javaw.exe
Reference:
1. multipe java on stackoverflow
2. Eclipse - Specifying the JVM
03 July 2014
Eclipse keyboard shortcuts
Introduction to the dark art of Eclipse magic.
Ctr+Shift+L = Display all keyboard shortcuts
Ctr+M = maximises the current view
F4 = display type hierarchy
Ctr+Q = Take you back to your last edit
Alt+LEFT, Alt+RIGHT = navigate backwards and forwards on your last file views.
F3 or Ctr+CLICK = Take me to it's definition
Ctr+L = Jump to a specified line number
Ctr+E = Browse through a list of all the files that is opened in editor.
Ctr+F = Find/Search
Ctr+J = find as you type - incremental search
Ctr+Shift+R = Open a resource
Ctr+I = Indent code
Ctr+D = delete current line
Ctr+Shift+O = Organize imports
Alt+Shift+R = refactor - rename variable/method name.
Alt+Shift+S+R = refactor - generate getters and setters
Alt+Shift+M = refactor out a method
Play with these shortcuts. As you work on your IDE, there are frequent things you keep doing. Look for a keyboard shortcut for it. If you can't find it, then you search for it and create your own in the Preferences window.
You can open it by Ctr+Shift+L and again Ctr+Shift+L.
Something I made up
Ctr+Shift+F = File search
Happy typing.
Reference - http://web.stanford.edu/class/cs108/handouts132/10EclipseGuide.pdf
Ctr+Shift+L = Display all keyboard shortcuts
Ctr+M = maximises the current view
F4 = display type hierarchy
Ctr+Q = Take you back to your last edit
Alt+LEFT, Alt+RIGHT = navigate backwards and forwards on your last file views.
F3 or Ctr+CLICK = Take me to it's definition
Ctr+L = Jump to a specified line number
Ctr+E = Browse through a list of all the files that is opened in editor.
Ctr+F = Find/Search
Ctr+J = find as you type - incremental search
Ctr+Shift+R = Open a resource
Ctr+I = Indent code
Ctr+D = delete current line
Ctr+Shift+O = Organize imports
Alt+Shift+R = refactor - rename variable/method name.
Alt+Shift+S+R = refactor - generate getters and setters
Alt+Shift+M = refactor out a method
Play with these shortcuts. As you work on your IDE, there are frequent things you keep doing. Look for a keyboard shortcut for it. If you can't find it, then you search for it and create your own in the Preferences window.
You can open it by Ctr+Shift+L and again Ctr+Shift+L.
Something I made up
Ctr+Shift+F = File search
Happy typing.
Reference - http://web.stanford.edu/class/cs108/handouts132/10EclipseGuide.pdf
05 February 2014
Git
Git is very different compared to other SCMs. When ever you commit, git creates another image of your project and saves the difference. So when you switch between two different branches, you are switching between two images of your project folder.
If you are on Windows, use Git Bash. Tortoise Git is usually not recommended.
To start, select the folder where you want to manage your code.
Then initialise the folder like so:
$ git init
Check with help to see the available options for git-add
$ git add --help
You can do a trial run to see what will get added before you actually execute it
$ git add -na #This shows what happens if you do - git add -a
Adding specific file/files
$ git add */foo-bar.txt
Adding all files in a specific folder
$ git add */foo/*
Adding modified or deleted tracked files. New files not included.
$ git add -u
Add everything. Add files that are modified, add new files, remove deleted files
$ git add -A
Remove any file
$ git rm file.java
Lets say you added some code, and you want to start committing code.
$ git add *
$ git commit -m 'comments to your commit'
You want to push these to a remote server and start collaborating
$ git remote add origin https://server.com/foo-bar/project-name.git
# Creates a remote named "origin" pointing at your remote repository
$ git push origin master
# Pushes code to HEAD or master or trunk or main 'thing'
You want to get an existing project from the remote server
$ git clone https://server.com/foo-bar/project-name.git
To get the latest code
$ git pull
You changed something and now you want to discard your changes without committing.
$ git checkout -- finename
Instead of totally discarding your changes, you want to save/stash them, for just in case moments
$ git stash save --keep-index
Show me all the branches
$ git fetch
#this updates branch information from remote server
$ git branch --all
#this shows all the branches
You want to know what's up with your project folder
$ git status
You want to change to another branch, commit all local changes and do this:
$ git checkout --track origin/branch_name
If you want some graphical output of the git tree
$ git log --graph --oneline
Display list of files in the commit
$ git log --name-only
To create a new branch
$ git checkout -b new-branch-name
This is same as
$ git branch new-branch-name
$ git checkout new-branch-name
Create a new tag. This will create one locally
$ git tag -a v8.0 -m "commit message"
Push the new created tag to remote
$
git push --follow-tags
This should get you started.
Happy gitting!
26 September 2013
Bash in 5 minutes
Every time you login, /etc/profile script is run first to initialize.
Then these files are run
.profile
.bash_login
.bash_profile
these files are best to configure PATH variables.
when you logout, .bash_logout script is run.
#refers to home - /home/indu/
~/
#refers to current folder
./
#command to check the PATH variables
echo $PATH
#changing permissions
#chmod refer - http://ss64.com/bash/chmod.html
# change to rwxr-xr-x
chmod 755 file-or-folder
# all(a) get added(+) permissions rw to file
chmod a+rw file-or-folder
# others(o) get removed(-) permissions rw to file
chmod o-rw file-or-folder
# owner(u) get added(+) permissions x to file
chmod u+x file-or-folder
# change ownership
sudo chown username:group file-or-folder
#! - specifies a shell
#!/bin/bash
# Ubuntu version
lsb_release -r
--------------------------------------------------------
bash commands
--------------------------------------------------------
ps //lists what shell prompt you are usingcd //goes to home
cd ~/folder-at-home //this ~/ refers to home location
pwd //shows which directory you are working in
mv f1 f2 //moves file f1 to file f2 - can be used to rename file
cp f1 f2 //copies file f1 to file f2. If f2 exists, then it is overwritten without warning
cp -i f1 f2 //asks before copying and overwriting f2
ls //lists files in a directory
ls -lt // order the list by creation date
ls -ltr // order the list by creation date in reverse order
ls -l //lists files in more detail
ls -a //lists hidden files that start with '.'
ls -F //lets you identify directories with a slash
cat text-file-name //outputs contents of the file to the terminal
cat file1 file2 //outputs contents of file1 and then prints out file2
tail -f file-name //outputs the logs that are getting generated, live
less text-file-name //outputs contents page wise - use :q to quit to terminal
more text-file-name //outputs contents page wise and quits to terminal just like cat
rm //removes file
rm -r //removes a directory along with the files in it
rm -i //asks before deleting a file
hostname //displays the name of the system you are working on
//searches recursively in /directory/ for
//file or folder named item
$find /directory/ -name item -print
//searches and prints all lines that contain string in filename
grep 'string' filename
// searches for specified text in
// all files in the current directory
grep -lir "some text" *
grep -lir "some text" /this/folder/location // searches for specified text in the specified directory location
-l - files that match
-i - ignore case
-r - read all files under each directory recursively
head filename //displays first 10 lines of text in file
head -3 filename //displays first 3 lines of text in file
tail filename //displays last 10 lines of text in file
tail -6 filename //displays last 6 lines of text in file
sort //displays contents of file with lines sorted according to alphabetical order
:q //quits the man page and goes to terminal
| //pipe - output of one process will become the input to another process
echo //send messages from scipts to screen, and more
whereis java //lets you know where all java executable is installed
which java //locates utility copy that you are going to use
bzip2 file.txt //binary-sorting file compressor
bunzup2 file.txt.bz2 //uncompress
gzip file.txt //GNU zip compressor
gunzip file.txt.gz //GNU uncompressor
#tar //tape archive
tar -czvf allmyfiles.tar.gz * //gunzips all the files in the current folder
tar -czvf folder.tar.gz foldername/ //gunzips a folder
tar -zxvf allmyfiles.tar.gz //this will extract the zip file in the current folder
tar -ztvf file.tar.gz //list files that is zipped in this tar file
clear //clears the screen
fg //brings the background process to foreground
#redirecting standard output
command options > destination_file //output of command will be put in destination_file, by erasing the previous contents.
command options >> destination_file //output of command added to the end of destination_file.
#redirecting standard input
command options < filename //command's input to come from file with the provided options
#pipes
command options | command options // output of one command is input to another command
#same as
command options > tempfile
command options < tempfile
jobs //lists the current running jobs with process ids
kill %process_id //kills the process with the process
diff --brief --recursive folder1 folder2 > difference.txt // gets the difference between two folders
--------------------------------------------------------
chmod - chaning file permissions
--------------------------------------------------------
File permissions read(r), write(w) and execute(x) have numbers.
r = 4
w = 2
x = 1
0 - ---
1 - --x
2 - -w-
3 - -wx
4 - r--
5 - r-x
6 - rw-
7 - rwx
chmod 644 filename // user = -rw-, usergroup = -r--, all = -r--
chmod 777 filename // user = -rwx, usergroup = -rwx, all = -rwx
--------------------------------------------------------
short-cut keys
--------------------------------------------------------
ctrl+U //clears your typed matter at the terminal
ctrl+Z //kills the current running program
\q //escapes current view
Ctrl+D //quit or exit
31 August 2010
Logo design at Logosnap
I recently came across this amazingly simple and yet powerful site to design your own logos. Its called Logosnap.com and is owned by logodesignguru.com. I know how cash strapped we are when we are a recent start up. This site is ideal to come up with your own design. You also get to credit yourself to all your friends and family and share that you did it yourself. Its a feeling unmatched. Do visit them and give it a try. You may begin to love your own work, thanks to Logosnap.com
27 August 2010
Setting and Reading Cookies in python Django
I recently tried to figure out how to set and get cookie values. I knew how to do sessions, but I wanted to have my own custom cookie. I was looking for a key-value pairs I could let it be stored on user's browser instead of on the database which is the case with sessions.
Here's how to set a cookie.
Here's how to read the cookie.
That's it. Have fun with cookies.
Reference : http://docs.djangoproject.com/en/dev/ref/request-response/
Here's how to set a cookie.
response.set_cookie(key="mykey", value="myvalue")
Here's how to read the cookie.
if "mykey" in request.COOKIES:
read_value = request.COOKIES["mykey"]
That's it. Have fun with cookies.
Reference : http://docs.djangoproject.com/en/dev/ref/request-response/
03 June 2010
Python Best Practices
Here are two interesting articles that will shed some light on the Python Best Practices
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
http://blog.apps.chicagotribune.com/2010/02/26/best-practices/
http://www.python.org/dev/peps/pep-0008/
Let me see if I can summarize it in the future post.
.
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
http://blog.apps.chicagotribune.com/2010/02/26/best-practices/
http://www.python.org/dev/peps/pep-0008/
Let me see if I can summarize it in the future post.
.
Subscribe to:
Posts (Atom)