Skip to content

Instantly share code, notes, and snippets.

View fstamour's full-sized avatar

Francis St-Amour fstamour

View GitHub Profile
@fstamour
fstamour / uriDecode.sh
Last active December 18, 2015 14:38
Shell Function to decode URI (i.e. replace %xx with the character with xx as hexadecimal code)
function uriDecode() {
#Usage echo Some%URI | uriDecode
echo -e "$(sed 's/%/\\x/g' <&0)"
}
@fstamour
fstamour / fileArray.sh
Created June 18, 2013 16:43
Shell snippet to get a file list into an array.
#From http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
# save and change IFS
OLDIFS=$IFS
IFS=$'\n'
# read all file name into an array
fileArray=($(find $DIR -type f))
# restore it
@fstamour
fstamour / third_redirection.sh
Created June 19, 2013 07:22
Really hacky shell snippet, could be used to get specific data from subshell to parent shell.
BLAH=$(( (echo out >&1; echo err >&2; echo other >&3;) 1>/dev/null ) 3>&1)
@fstamour
fstamour / gcd.hpp
Created December 9, 2013 23:27
Minimal (templated) implementation of the Euclidean algorithm for finding the greatest common divisor (GCD) of two number.
template< typename T >
T gcd( T a, T b ) {
T remainder = a % b;
while(remainder) {
a = b;
b = remainder;
remainder = a % b;
}
return b;
}
@fstamour
fstamour / lcm.hpp
Created December 9, 2013 23:53
Minimal (templated) implementation of the least common multiple (LCM) of two number. (Requires my gist for GCD.)
template< typename T >
T lcm( T a, T b ) {
return a*b/gcd( a, b );
}
@fstamour
fstamour / brok_symlink.sh
Created January 15, 2014 15:31
Shell command to list broken symlinks. May vary on different systems.
@fstamour
fstamour / print_binary.cpp
Created May 1, 2014 19:25
C++ printing binary representation
#include <bitset>
char a = 'b';
std::bitset<8> x{a};
std::cout << x;
(defun iota (m &optional (n 1) (step 1))
(defun iter (m n lst)
(cond ((> n m) (reverse lst))
(t (iter m (+ n step) (cons n lst)))))
(iter m n nil))
@fstamour
fstamour / ditch-unity.sh
Created May 6, 2014 16:41
ditch-unity.sh - For ubuntu 12.04
# For ubuntu 12.04
# Remove unity
sudo apt-get remove --purge unity unity-2d unity-2d-panel unity-2d-spread unity-asset-pool unity-services unity-lens-files unity-lens-music unity-lens-applications gir1.2-unity-5.0 unity-common indicator-sound indicator-power indicator-appmenu libindicator7 indicator-application indicator-datetime indicator-messages libnux-2.0-0 nux-tools libunity-misc4 unity-2d-common
# Install gnome-shell
sudo add-apt-repository ppa:gnome3-team/gnome3
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install gnome-shell
@fstamour
fstamour / safePrint.cpp
Created May 7, 2014 03:19
Printing null-terminated string without buffer-overflows
// @todo I'm sure it could be more efficient if we used a "safe" strlen and
// write the string into the stream using "ostream.write( const char*, size_t size)"
std::ostream& safePrint( std::ostream& out, const char* szStr, size_t maxSize ) {
for( size_t i = 0; i < maxSize && szStr[i] != '\0'; ++i) {
out.put(szStr[i]);
}
return out;
}