I recently had to access Django session data from a cookie in a third party application (based on Tomcat) with no access to the Django infrastructure. This example shows how I did it.
Continue reading Decode Django session data without the infrastructure
Category: Programming
Programming stuff.
Remote command execution in python using paramiko that supports arbitrary input
I recently decided to use paramiko to develop a remote command execution tool.
It was very easy to setup initially and ran much faster than my existing pexpect implementation but it had a problem with sudo commands because they required the password to be provided as input.
I solved the problem by using a pseudo-terminal and by creating my own ChannelFile objects for stdin and stdout/stderr. The solution should be general enough to handle any case that requires simple input but it is not as flexible as pexpect. I hope that you find it useful.
Continue reading Remote command execution in python using paramiko that supports arbitrary input
Simple python functions that provide openssl -aes-256-cbc compatible encrypt/decrypt
The example here shows how to encrypt and decrypt data using python in a way that is fully compatible with openssl aes-256-cbc. It is based on the work that I did in C++ Cipher class that is published on this site. It works for both python-2.7 and python-3.x.
The key idea is based on the way that openssl generates the key and iv data from password as well as the “Salted__” prefix that it uses.
The complete routine can be downloaded here: mycrypt.py.
Continue reading Simple python functions that provide openssl -aes-256-cbc compatible encrypt/decrypt
Private data management tool using client side javascript
I recently created a web based tool that allows you to manage your private data and generate passwords safely. If you are interested in trying it click here.
I suspect that it will only work on newer browsers. I have only tested it on Firefox 15, IE 9 and Chrome 23. See the tool help for more detailed information.
Continue reading Private data management tool using client side javascript
Bash script to install gcc 4.7.2 and boost 1.51.0 on CentOS 5.5+ and 6.3
I recently installed gcc 4.7.2 and boost 1.51.0 on CentOS 5.5, 5.8 and 6.3 to take advantage of the improved support for C++-11. It was painful to do manually so I automated the process with this script: http://projects.joelinoff.com/gcc-4.7.2/bld.sh. Hopefully this will make it easier for folks that want to experiment with the latest version of the GNU C++ compiler.
Continue reading Bash script to install gcc 4.7.2 and boost 1.51.0 on CentOS 5.5+ and 6.3
Installing jshint and rhino for command line javascript analysis
I recently had to install jshint and rhino. It was a bit of a challenge because they needed ant and npm (node package manager). This blog describes what I did and provides a bash shell script that you can use.
Continue reading Installing jshint and rhino for command line javascript analysis
gcc 4.7.0 bash install script updated to support binutils-2.22
This week I updated the gcc-4.7.0 bash install script to include binutils-2.22 with gold support enabled. See this blog entry to download it.
Continue reading gcc 4.7.0 bash install script updated to support binutils-2.22
C++ class that interfaces to OpenSSL ciphers
I have developed a class named Cipher that allows you to encrypt and decrypt files or strings using the OpenSSL AES-256-CBC cipher and SHA1 digest algorithms. It is interoperable with the openssl
command line tool which makes it a good introduction to using OpenSSL for ciphers.
The project has been moved to github: https://github.com/jlinoff/openssl-aes-cipher. The latest version is 1.3. It has been updated to work with the opaque contexts that were introduced in openssl-1.1.
I am re-releasing version 1.2 into the public domain on 2013-11-21 because I wish that I had found something like it when I was starting out with OpenSSL.
Continue reading C++ class that interfaces to OpenSSL ciphers
Bash script to install gcc 4.7.0 and boost 1.49
I recently wanted to build gcc 4.7.0 on CentOS 5.5 to get access to more C++11 features so I put together this script to do all of the work. It is released in text mode so that you can cut-n-paste it from the web page. The shell version is also available: http://projects.joelinoff.com/gcc-4.7.0/bld.sh if you want to download it directly using a tool like wget.
The full installation of gcc-4.7.0 and boost-1.49 requires about 4GB of disk space. After the build is complete you can delete the archives, bld and src directory trees to reclaim about 3.4GB of disk space.
Continue reading Bash script to install gcc 4.7.0 and boost 1.49
Bash script to download, build and install gcc 4.6.3 and boost 1.49
I recently had to build gcc 4.6.3 on CentOS 5.5 so I put together this script to do all of the work. It is released in text mode so that you can cut-n-paste it from the web page. The shell version is also available: http://projects.joelinoff.com/gcc-4.6.3/bld.sh if you want to download it directly using a tool like wget.
The full installation of gcc-4.6.3 and boost-1.49 requires about 4GB of disk space. After the build is complete you can delete the archives, bld and src directory trees to reclaim about 3.4GB of disk space.
Continue reading Bash script to download, build and install gcc 4.6.3 and boost 1.49
Simple C++ text file parser class
This class defines a very simple line oriented parser that tokenizes the data on each line while discarding comments. I created it because the need for parsing very simple files with comments came up over and over again but the traditional istream and fscanf approaches would not allow me to handle comments.
Continue reading Simple C++ text file parser class
Added a table that presents the same commands in bash and tcsh
I put together a table that presents the same commands in bash and tcsh because I sometimes have to switch between shells and needed a handy reference. It was built up over time by as I came across tidbits that I wanted to remember.
In some cases there are different ways of doing the same thing so I simply chose my preferred approach (such as [[]] expressions rather than [] in the if statements).
I hope that you find it useful.
NX password scrambling and unscrambling algorithms in python 2.7
The NX web page entitled “The password scrambling algorithm in NX client” describes their password scrambling algorithm in C++ and perl but it does not describe it in python. Nor does it describe how to unscramble the data.
This blog describes how I implemented both algorithms in python. I was surprised that NX didn’t use a standard symmetrical key algorithm like blowfish or DES for storing the keys but they must have some good reason.
Continue reading NX password scrambling and unscrambling algorithms in python 2.7
Released change.py 1.1
I released version 1.1 of change.py today. It has two fixes:
- When a file was renamed in in-place mode the file with the old name was not deleted.
- File permissions were not correctly set in some cases when changes were made.
The version is here: http://projects.joelinoff.com/change-1.0/change.py.
I simply replaced the 1.0 version.
Bash script to download, build and install gcc 4.6.2 and boost 1.48
I recently had to build gcc 4.6.2 on CentOS 5.5 and found it to be quite painful so I put together this script to do all of the work: http://projects.joelinoff.com/gcc-4.6.2/bld.sh.txt. I am releasing it in text mode so that you can cut-n-paste it from the web page.
The shell version is also available: http://projects.joelinoff.com/gcc-4.6.2/bld.sh if you want to download it directly using something like wget.
Continue reading Bash script to download, build and install gcc 4.6.2 and boost 1.48
Edit multiple files at once using change.py
For many years I have used a home grown tool that allows me to make simple changes to multiple files with one command. It is called change and has existed as csh, bash and perl incarnations over the years. I recently rewrote it in python and thought that it might be useful to others so I am publishing it. Here is an example of how it works:
1 2 3 4 |
#!/bin/bash files=$(find . -type f) change.py 'Copyright (c) 2010' 'Copyright (c) 2012' $files change.py 'Version 1.0' 'Version 1.2' $files |
I suspect that lots of you have written your own, similar tools. If that is the case, please look it over send me suggestions for improvements.
Continue reading Edit multiple files at once using change.py
2 Color Chooser tool now available
I released my web based, interactive “2 color chooser” tool today. You can find it here or in the “USEFUL LINKS” section on my blog page.
This tool allows you to select two colors using RGB or HSV. Here are some of different uses that motivated me to me write it. Here is what it looks like in action:
Note that the little + sign next to the gradient allows you to see the CSS source code for the gradient commands.
The tool can be used to see how well two nested colors contrast which is useful for determining the effectiveness of color schemes. This is especially useful for determining how well a scheme works for fonts in page headers/footers or to determine whether color blind users can distinguish the colors.
It can also be used to see how well two colors work in a gradient. Different browsers support different gradient options. This tool is tuned for FF because that is what I use. Any suggestions for other browsers would be greatly appreciated.
Finally it can be used to test color differences on different monitors. You can bring it up side by side on two monitors and visually compare/contrast the color display. I have used it for tuning my HP and Dell monitors. I was surprised at the initial variation.
This tool demonstrates client side javascript programming techniques using JQuery including dynamic updates, slider bars and simple menus. If you are interested in the source code you can download it by selecting one of the links below.
The files that I wrote are 2-color-chooser.html, 2-color-chooser.js, 2-color-chooser.css and hdr.css. All of the rest are from various public domain packages.
You are free to modify or incorporate the software but I would be grateful if you would cite me as a source.
And last but not least, I would be remiss in not mentioning the book “Javascript, The Definitive Guide” by David Flanagan. If you are at all interested in the learning javascript this book is a must have. I have read both the 5th and 6th editions and heartily recommend both, although, in my view, the 6th edition is slightly better.
Have fun!
SecEd released
I officially released SecEd into the public domain today, you can find it here.
SecEd was written using Python 2.7 and the wxPython 2.8 package. It allows you to securely edit sensitive data. It also has a feature that allows you to rate the strength of your password.
Because it is written in Python it is portable and because it is open source you can use it to learn about wxPython and/or teach me more about it.
Have fun!
Find gcc/g++ header files and/or contents
There have been a number of times when I wanted to find out where an include file was in the default compiler search path and there have been other times when I wanted to find out which header file contained a specific setting so I created this simple little bash script that does both in the hopes that it will be useful.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#!/bin/bash # # This tool allows you to search for header files in the compiler # search path using the find syntax. # # % find-header.sh -name unistd.h # % find-header.sh -name syscall.h # # You can also search the contents of headers. # # % find-header.sh -name '*.h' -exec grep -n __NR_ {} \; -print # % find-header.sh -iname '*.h' -exec grep -l __NR_ {} \; # # If you just want to see the include paths: # # % find-header.sh # # Collect the arguments. N=$# ARGS=() while (( $# > 0 )) ; do ARGS=( "${ARGS[@]}" "$1" ) shift done # Get the compiler paths for gcc and g++. $(g++ -print-prog-name=cc1plus) -v > /tmp/$$.txt 2>&1 <<EOF EOF $(gcc -print-prog-name=cc1plus) -v >> /tmp/$$.txt 2>&1 <<EOF EOF INCS=$(sort -fu /tmp/$$.txt | egrep '^[ ]+/' | uniq) rm -f /tmp/$$.txt # Search the include paths. for INC in ${INCS[@]} ; do if (( $N == 0 )) ; then echo $INC else #echo find $INC -type f ${ARGS[@]} find $INC -type f ${ARGS[@]} fi done |