Skip to content

Instantly share code, notes, and snippets.

View hamaluik's full-sized avatar
👋
I may be slow to respond.

Kenton Hamaluik hamaluik

👋
I may be slow to respond.
View GitHub Profile
@hamaluik
hamaluik / perCpuUsage.py
Created August 16, 2012 18:05
Reporting Per-CPU Processor Usage With Python
#!/usr/bin/env python
import psutil
while True:
print psutil.cpu_percent(interval=1, percpu=True)
@hamaluik
hamaluik / gist:3372222
Created August 16, 2012 18:09
Getting HTML Data From a Webpage Using Python
#!/usr/bin/env python
import urllib2
# get the html of a url
def GetHTML(url):
# open it up
f = urllib2.urlopen(url)
str = f.read()
return str
@hamaluik
hamaluik / gist:3372229
Created August 16, 2012 18:09
Sorting objects in Java
class Derp {
// hold the rank of each derp here
int rank;
}
// now, we must make a comparator class which knows how to sort our Derp class:
class DerpComp implements Comparator<Derp> {
public int compare(Derp a, Derp b) {
// return -1 if a < b
if(a.rank < b.rank)
@hamaluik
hamaluik / gist:3372233
Created August 16, 2012 18:10
Spanning Multiple Rows or Columns in Tables in LaTeX
\usepackage{multirow}
...
\begin{table}[H]
\begin{center}
\caption{Example}
\label{tab:example}
\begin{tabular}{lcc}
Column A & \multicolumn{2}{c}{Columns B and C} \\
@hamaluik
hamaluik / gist:3372235
Created August 16, 2012 18:10
Adding Slanted Fractions in LaTeX
\usepackage{xfrac}
...
\begin{itemize}
\item 1$\sfrac{1}{4}$ cups of sugar
\item $\sfrac{1}{2}$ cup of butter
\end{itemize}
@hamaluik
hamaluik / gist:3372567
Created August 16, 2012 18:44
Parsing XwXdXhXmXs time into number of seconds
private boolean isLong(String str) {
try {
Long.parseLong(str);
}
catch(NumberFormatException e) {
return false;
}
return true;
}
@hamaluik
hamaluik / cppLinearInterpolator
Created January 15, 2013 04:53
Basic linear interpolator class in C++
#include <map>
#include <vector>
/**
* Provides a basic interpolation mechanism in C++ using the STL.
* Maybe not the fastest or most elegant method, but it works (for
* linear interpolation!!), and is fast enough for a great deal of
* purposes. It's also super easy to use, so that's a bonus.
*/
class LinearInterpolator {
@hamaluik
hamaluik / UnityLauncher
Created January 15, 2013 05:03
An application "shortcut" in Ubuntu Unity (modify and drag to launcher to setup)
[Desktop Entry]
Name=Dispay Name of App
GenericName=Basic Name of App
Comment=Comment
Keywords=keywords;separated;with;semi-colons
Exec=/path/to/file/to/run with parameters
Terminal=true|false
Type=Application
StartupNotify=true
Icon=/path/to/icon.png
@hamaluik
hamaluik / listOfSymbols.tex
Created January 30, 2013 23:16
List of symbols, taken from http://filer.case.edu/oxb6/listofsymbols.html for ease of use with Gists
%% Your packages
\usepackage{array} %for vertical thick lines in tables
\usepackage{multirow} %multirow tables
\usepackage{nicefrac} %for fractions like 1/4
%Package list ends here
% Macro for 'List of Symbols', 'List of Notations' etc...
\def\listofsymbols{\input{symbols} \clearpage}
\def\addsymbol #1: #2#3{$#1$ \> \parbox{5in}{#2 \dotfill \pageref{#3}}\\}
@hamaluik
hamaluik / secondsToHMS
Created November 15, 2013 00:54
This isn't something that is very difficult. However, I often find I need to do the conversion from total number of seconds (example: 5412s) to the number of hours, minutes, and seconds that is (hh:mm:ss - 1:30:12 in this case). Here is a little snippet in Python that does this.
# secs is the total number of seconds
secs = 5412
# calculate things..
hours = secs / 3600
minutes = (secs - hours * 3600) / 60
seconds = secs % 60
# now print the results!
print '%02d:%02d:%02d' % (hours, minutes, seconds)