Skip to content

Instantly share code, notes, and snippets.

@moward
moward / .wincd
Created February 9, 2017 18:41
CD from Windows Path in WSL
#! /bin/sh
# Allows user to change directory through drag And drop in Windows Subsystem for Linux
# Note: Requires quotes around path since backslash is metacharacter in bash
wincd(){
if case $1 in "C:\\"*) false;; *) true;; esac; then
>&2 echo "path invalid: $1"
else
NEWDIR="$(echo ${1:2} | sed -e 's/\\/\//g')"
@moward
moward / unzip.sh
Created February 9, 2017 17:51
unzipping all
# zip
for i in *.zip;
do unzip $i -d ${i%.*};
done
@moward
moward / ocamltips.md
Last active February 1, 2016 04:32
CIS 120 OCaml Style Tips

Finding tab characters

If you want to see if your file contains tab characters from Eclipse, this is the easiest way.

  • Hit Ctrl+F/CMD+F to open the "Find/Replace" dialog.
  • Type \t into the "Find:" box.
  • Make sure the "Regular Expression" box is checked.
  • Click "Find"

If your file contains any tab characters, it will highlight them. As a quick fix, you can then type two spaces into the "Replace with:" box and hit "Replace All" to get rid of all tab characters. Better yet, just change your settings to use spaces instead of tabs (below).

Set Eclipse to use spaces instead of tabs

@moward
moward / convert.c
Last active December 8, 2015 05:11
convert a char to ASCII Hex
void byteToHex(char b, char* out1, char* out2) {
char lowerFour = b & 0xF;
if (lowerFour < 0xA) {
*out1 = '0' + lowerFour;
} else {
*out1 = 'a' + lowerFour - 0xA;
}
char upperFour = b >> 4;
if (upperFour < 0xA) {
*out2 = '0' + upperFour;