Skip to content

Instantly share code, notes, and snippets.

@kccqzy
kccqzy / clean_trash.js
Last active September 12, 2023 06:01
This gist cleans your OS X trash by permanently removing items trashed more than X days ago
#!/usr/bin/env osascript -l JavaScript
var numDaysToKeep = 20;
var now = $.NSDate.date;
console.log("Now:", now.description.js);
var deleteThreshold = now.dateByAddingTimeInterval(-86400 * numDaysToKeep);
console.log("Will delete items whose date added is earlier than", deleteThreshold.description.js);
var urlPath = $.NSURL.alloc.initFileURLWithPathIsDirectory($('~/.Trash').stringByExpandingTildeInPath, true);
var fm = $.NSFileManager.defaultManager;
var urlContents = fm.contentsOfDirectoryAtURLIncludingPropertiesForKeysOptionsError(urlPath, ["NSURLAddedToDirectoryDateKey"], $.NSDirectoryEnumerationSkipsHiddenFiles, null).js;
@kccqzy
kccqzy / RNCryptor.hs
Created December 13, 2014 13:12
Quick Implementation of RNCryptor
{-# LANGUAGE RecordWildCards #-}
module RNCryptor (Credentials(..), encrypt, decrypt) where
import Control.Applicative ((<$>), (<*>), pure)
import Control.Monad
import Control.Monad.Trans (liftIO)
import Control.Error (hoistEither, note, hush, runEitherT, EitherT)
import qualified Data.ByteString as B
import qualified Data.Attoparsec.ByteString as PB