Skip to content

Instantly share code, notes, and snippets.

View sunmockyang's full-sized avatar

Sunmock Yang sunmockyang

View GitHub Profile
@sunmockyang
sunmockyang / parseTimelapseFrames.rb
Last active July 11, 2016 04:57
Parses directories for valid timelapse frames, copies to a destination names ascending in modification time. Valid frames are those taken at 7AM to 8:05AM
require "fileutils"
def parse_contents(contents)
valid_frames = []
contents.each do |frame|
if valid_frame?(frame)
valid_frames.push(frame)
end
end
@sunmockyang
sunmockyang / file-utils.rb
Last active June 15, 2016 05:30
A collection of ruby file management functions
require 'fileutils'
require 'digest/md5'
def smart_cp(src, dest)
cp = Proc.new {|src, dest| cp_r(src, dest) }
smart_transfer(src, dest, cp)
end
def smart_mv(src, dest)
mv = Proc.new {|src, dest| mv_r(src, dest) }
@sunmockyang
sunmockyang / timelapse60.sh
Last active May 25, 2016 21:16
Take 60 pictures with a minute in between each whenever we reach a specified hour. Meant for making raspi camera timelapses
#!/bin/sh
WIDTH=1920
HEIGHT=1080
# DIR="."
DIR="/media/OSXSUNNY/timelapse"
INTERVAL_MINUTES=1
HOUR_TO_RECORD=7
NUM_FRAMES=60
@sunmockyang
sunmockyang / bashTernary.sh
Last active May 24, 2016 14:46
Set fileName to customName if it's defined, otherwise, use defaultName
fileName=${customName:-$defaultName}
@sunmockyang
sunmockyang / neko
Created March 11, 2016 20:03
A more visible echo command for use in debugging. Place in any directory that's in $PATH
#!/bin/bash
echo "$(tput setaf 3)neko: $(tput setaf 5)$@$(tput sgr0)"
@sunmockyang
sunmockyang / LoadJSONFile.js
Created March 3, 2016 03:35
Load remote JSON data
var dataSrc = "js/data.json";
var data = null;
function loadJSON(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', dataSrc, true);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
callback(xobj.responseText);
@sunmockyang
sunmockyang / file_archiver.rb
Created February 8, 2016 05:34
Takes all files recursively in a path and organizes based on date modified, puts them all into monthly folders
# File Archiver
# Takes all files and organizes based on date modified
# Puts them all into monthly folders
# Usage:
# ruby file-archiver.rb SRC_PATH [DEST_PATH]
# If DEST_PATH isn't entered, then SRC_PATH will be used as destination
require 'fileutils'
@sunmockyang
sunmockyang / delete_empty_dir.rb
Created February 8, 2016 05:20
Deletes all empty directories in a path recursively. Any directory containing no files but only folders is considered empty
def delete_empty_dir(root_dir)
recursive_dirs = Dir["#{root_dir}/**/*"].select { |f| File.directory?(f) }
# Sort into deepest dirs first
recursive_dirs = recursive_dirs.sort { |a, b| b.split("/").length - a.split("/").length }
puts recursive_dirs.each { |d|
if (Dir.entries(d) - %w[ . .. ]).empty?
Dir.rmdir(d)
end
}
@sunmockyang
sunmockyang / timelapse_jpg.sh
Created January 14, 2016 00:34
Create a timelapse from all jpg images in a folder
ls *.jpg > stills.txt && mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -flip -vf scale=1920:1080 -o timelapse.avi -mf type=jpeg:fps=30 mf://@stills.txt
@sunmockyang
sunmockyang / HighlightElement.js
Created December 16, 2015 04:01
Highlight an element and fade highlight after a delay
function HighlightItem(delay, element) {
var startTime = -1;
var duration = 3000;
var startC = [255, 255, 255, 0];
var highlightC = [255, 255, 100, 1];
element.style.backgroundColor = "rgba(" + highlightC.join() + ")";
function highlightLoop(){
var t = (Date.now() - startTime) / duration;