Skip to content

Instantly share code, notes, and snippets.

@jcordeiro
jcordeiro / disks.sh
Created June 15, 2013 01:48
Just a small shell file I had to write for my OS class that goes through the first 4 disks on a linux system and prints out the number of partitions they have.
#!/bin/bash
echo "The following hard disks are currently present in your system:"
for DISK in /dev/sda /dev/sdb /dev/sdc /dev/sdd
do
echo "The disk $DISK appears to have `fdisk -l $DISK 2> /dev/null | grep -E $DISK\[0-9]\ | wc -l` partitions."
done
@jcordeiro
jcordeiro / LogNSDictionary.m
Last active August 29, 2015 13:56
Iterate over an NSDictionary and output the contents to NSLog
NSString *key;
for(key in dict){
NSLog(@"Key: %@, Value %@", key, [dict objectForKey: key]);
}
@jcordeiro
jcordeiro / AndroidScreenDensity.java
Last active March 25, 2016 21:29
Determines device screen size(small, normal, etc) and screen density (ldpi, mdpi, etc) and displays result in a Toast
//Determine screen density
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int density = metrics.densityDpi;
if (density == DisplayMetrics.DENSITY_TV) {
Toast.makeText(this, "DENSITY_TV... Density is " + String.valueOf(density), Toast.LENGTH_LONG).show();
}
else if (density == DisplayMetrics.DENSITY_XXXHIGH) {
Toast.makeText(this, "DENSITY_XXXHIGH... Density is " + String.valueOf(density), Toast.LENGTH_LONG).show();
@jcordeiro
jcordeiro / isNetworkConnected.java
Last active August 29, 2015 13:57
A method to determine whether or not an Android device has network connectivity
private boolean isNetworkConnected() {
// get Connectivity Manager to get network status
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
return true; //we have a connection
} else {
@jcordeiro
jcordeiro / UpdateNode
Created May 21, 2014 03:08
Update Node.js with npm
sudo npm cache clean -f
sudo npm install -g n
sudo n stable #updates to the latest stable version
@jcordeiro
jcordeiro / pngoptimize.sh
Created April 10, 2015 01:45
Loops through a directory of .png files and uses pngquant to optimize them and shrink their size
#!/bin/bash
for PNG in $(find . -name '*.png'); do
pngquant -ext .png -force 256 ${PNG}
echo "Optimized PNG: ${PNG}"
done
@jcordeiro
jcordeiro / svg2png.sh
Created April 10, 2015 21:44
Iterates through a directory of .svg images and converts them to .png images. Requires the inkscape command line tool to be installed.
#!/bin/sh
for i in *.svg
do
IFS='.' read -a array <<< "$i"
inkscape -f "$i" -e "${array[0]}.png"
rm $i