Skip to content

Instantly share code, notes, and snippets.

View rugbyprof's full-sized avatar

Terry Griffin rugbyprof

View GitHub Profile
@rugbyprof
rugbyprof / dyn2Darray.cpp
Last active September 8, 2021 05:21
Dynamic 2D array
#include <iostream>
using namespace std;
int main() {
int **Matrix; //Declare a pointer to pointer (integer in this case).
int maxRows = 5; //Size in rows of your array.
int maxCols = 5; //Size in cols of your array (does not have to == rows, could be a staggered array).
Matrix = new int *[maxRows]; //Point table to an array of size maxRows holding null pointers right now.
@rugbyprof
rugbyprof / clean_unused_kernels
Created January 26, 2012 00:21
Ubuntu Cleanup: How to Remove All Unused Linux Kernel Headers, Images and Modules
//Credit goes to - http://ubuntugenius.wordpress.com
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
@rugbyprof
rugbyprof / dir_traverse.php
Created February 20, 2012 21:14
Php Iterative Directory Traversal
<?php
//From php.net comments written by:
//donovan dot pp at gmail dot com
function dir_tree($dir) {
$path = '';
$stack[] = $dir;
while ($stack) {
$thisdir = array_pop($stack);
if ($dircont = scandir($thisdir)) {
$i=0;
@rugbyprof
rugbyprof / php_get_extension.php
Created February 20, 2012 21:25
Php return file extension
function file_extension($filename)
{
return end(explode(".", $filename));
}
@rugbyprof
rugbyprof / print_r_to_file.php
Created February 23, 2012 02:02
print_r to a file
<?php
//sebasg37 at gmail dot com
//If you have to catch the output without showing it at all at first (for example, if you want to append the //print_r output to a file), you can do this:
ob_start();
print_r( $some_array );
$output = ob_get_clean();
@rugbyprof
rugbyprof / recursive_bin_search.cpp
Created February 23, 2012 05:26
Recursive Binary Search
//Source: http://www.fredosaurus.com/notes-cpp/algorithms/searching/rbinarysearch.html
int recBinarySearch(int sortedArray[], int first, int last, int key) {
// function:
// Searches sortedArray[first]..sortedArray[last] for key.
// returns: index of the matching element if it finds key,
// otherwise -(index where it could be inserted)-1.
// parameters:
// sortedArray in array of sorted (ascending) values.
// first, last in lower and upper subscript bounds
// key in value to search for.
@rugbyprof
rugbyprof / exif.php
Last active February 14, 2020 02:03
meta data from images php
#!/usr/bin/php -q
<?php
/*
* exif.php
* This script gets meta headers from image files.
*
* (For use with command line)
* Usage Usage: php exif.php <image>
* Example: php exif.php beach.jpg
@rugbyprof
rugbyprof / Find_Large_Files
Created April 24, 2013 17:43
find large files on linux box
find {/path/to/directory} -type f -size +{file-size-in-kb}k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
@rugbyprof
rugbyprof / linux_count_files_directory.sh
Last active February 14, 2020 02:10
Count files in linux directory.
ls -1 targetdir | wc -l
@rugbyprof
rugbyprof / Clean_boot_partition.md
Last active September 29, 2017 17:09
Cleaning /boot partition when to many kernel copies exist.

Remove all but the last kernels with:

sudo apt-get purge linux-image-{3.0.0-12,2.6.3{1-21,2-25,8-{1[012],8}}}

This is shorthand for:

sudo apt-get purge linux-image-3.0.0-12 linux-image-2.6.31-21 linux-image-2.6.32-25 linux-image-2.6.38-10 linux-image-2.6.38-11 linux-image-2.6.38-12 linux-image-2.6.38-8