Skip to content

Instantly share code, notes, and snippets.

@martineno
martineno / Makefile
Created May 19, 2019 02:53
Only run `npm install` when needed
# An example of how to only run `npm install` only when package.json or package-lock.json
# have changed. This might be helpful for situation where you run `npm install` every time
# and app or service lauches (e.g. for local development), but the install takes a long time.
#
# This approach creates a tracking file called `make_installed`. Whenever `npm install` is
# invoked, this file is touched. If the file is newer then the modification date on either
# package.json or package-lock.json then no installation is done. If it is older,
# then installation is done.
#
# This also works with git. When you checkout a previous commit the modification date for
@martineno
martineno / delete-tm-snapshots.sh
Created February 18, 2019 19:53
Quickly delete all the local Time Machine snapshots on an APFS volume
# tail -n +2 to remove the first line of the `tmutil listlocalsnapshotdates` command
# sort -r to start deleting the most recent ones first
for d in $(tmutil listlocalsnapshotdates | tail -n +2 | sort -r)
do
tmutil deletelocalsnapshots $d
done
@martineno
martineno / 👀
Last active July 6, 2017 04:20
Because I have nothing better to do with my time then to transcribe silly programming memes. This compiles on macOS 10.12.5 Xcode 8.3.3. I am not the author, my source is: https://twitter.com/jarrod_dixon/status/882328017502130176
#include <iostream>
#include <vector>
namespace 🔵 = std;
using 🔢 = int;
using 💀 = void;
using 🕖 = time_t;
using 👌 = bool;
#define 👂 auto
@martineno
martineno / mp3tag-to-csv.py
Created November 1, 2015 20:38
Processes all the .mp3 files in the current directory and creates a CSV file that contains their album, artist and title.
#!/usr/bin/env python
import eyed3
import csv
import glob
import argparse
# eyed3 is a required module that is used to process the files. Install: pip --user eyed3
def main():
/**
* A simulation written to help experiment with the well known water puzzle:
*
* If you have two unmarked jugs: a 5 gallon one and a 3 gallon. Provide a series of steps
* to fill one of the jugs with 4 gallons of water.
* This doesn't acutally solve the puzzle, but provides constraints to let the user experiment
* with the puzzle.
*
* The constraints are:
* # You can drain a jug completely see: drain
@martineno
martineno / gist:edc3b42c95bf596259d0
Created June 23, 2014 02:24
An attempt at a Swift really const array
// Swift has the somewhat unusual const array semntatics in that a
// const array can still have its individual elements changed. I was thinking if there
// was a way to get the const behavior that one might expect, i.e. in a const array
// not only is the length of an array fixed, but also all of its elements.
//
// Here is my attempt:
struct ConstArray<T> {
var array: Array<T> = []
init(array: Array<T>) {
@martineno
martineno / uncconvert.py
Created September 27, 2012 19:06
UNC to SMB OS X Text Service

I run into UNC paths fairly often and they can be a pain to deal with on OS X. So I wrote a little text service action that helps with this problem.

After you set this up, you will be able to highlight any text in a text field, right click and have the text converted from a UNC path to a smb:// style URL. This is especially helpful when using these in Finder with the Go -> Connect to Server dialog box.

To use this:

  1. Open Automator
  2. Select File -> New
  3. For the document type, choose "Service"
  4. Add the "Run Shell Script" action