Skip to content

Instantly share code, notes, and snippets.

View nickangtc's full-sized avatar

Nick Ang nickangtc

View GitHub Profile
@nickangtc
nickangtc / apply_lut_batch.sh
Last active August 18, 2025 06:12
Batch apply LUTs to video files using Bash and ffmpeg
#!/bin/bash
# Simple LUT Batch Processing Script
# Usage: ./apply_lut_batch_simple.sh <input_folder> <output_folder> <lut_file>
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
@nickangtc
nickangtc / vim-notes.md
Created April 29, 2024 20:24
Notes taken entirely in Vim mode in VS Code while learning Vim :D

Notes learning Vim

Vim's modes enable Vim to have sane keyboard shortcuts instead of Cmd + Shift + whatever the hell next. In Normal mode, w jumps to the next word. In Visual mode, w highlights from current cursor position to the next word. In Insert mode, well w types out the w character.

j goes down instead of up - is this an arbitrary decision? I think not? My intuition says it's down instead of up, and k is up instead of down, because we go down much more often then go up, and it makes sense to let the stronger middle finger do that.

Navigating up with k skips to start of paragraph?? This surprised me. I also got annoyed quickly not being able to move up a line by hitting k or h (left), which you can do in a normal text processor. I'm sure there is a way to do this I don't know about... Yes! b (move back one word, which is like the reverse of w) does something like that.

Motions are commands that you use in Normal mode for navigating faster. _There must be a way to go back

@nickangtc
nickangtc / Contains Duplicate.js
Created May 20, 2023 12:47
LeetCode Contains Duplicates (solution)
// https://leetcode.com/problems/contains-duplicate/
// this solution beats 85% of other submissions in terms of runtime, 57% in terms of memory
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function(nums) {
const memo = {};
@nickangtc
nickangtc / Bear and Steady Gene.js
Created May 19, 2023 15:04
Hackerrank medium: Bear and Steady Gene (n^2 timeout solution - works but too slow)
// https://www.hackerrank.com/challenges/bear-and-steady-gene/problem
function steadyGene(gene) {
const geneArray = gene.split("");
const geneDict = geneArray.reduce(
// O(n) time
(dict, char) => {
return {
...dict,
[char]: dict[char] + 1,
@nickangtc
nickangtc / Sherlock and the Valid String.js
Last active May 18, 2023 16:03
Hackerrank medium: Sherlock and the Valid String
// https://www.hackerrank.com/challenges/sherlock-and-valid-string/problem
function isValid(s) {
const occurrences = {};
for (let i = 0; i < s.length; i++) {
const alphabet = s.charAt(i);
occurrences[alphabet] = occurrences[alphabet]
? occurrences[alphabet] + 1
: 1;
@nickangtc
nickangtc / modifying-ruby-builtin-classes.rb
Last active March 9, 2022 15:48
How Rails extends Ruby builtin classes is actually really simple...
# scenario
# ========
# suppose we want functionality like so on any string:
# "racecar".palindrome? #=> true
#
# where should we could we add that functionality?
# in ruby, this is surprisingly possible:
class String
def palindrome?
@nickangtc
nickangtc / triangle-koan-ruby.rb
Last active March 21, 2022 08:23
an example of beautiful ruby code used to validate a triangle as part of ruby koans exercise
# exercise is from http://rubykoans.com/ - a great way to learn ruby!
#! my not so succinct but works solution
def triangle(a, b, c)
validate_triangle(a, b, c)
if a == b && b == c
:equilateral
elsif a != b && b != c && c != a
:scalene
else
@nickangtc
nickangtc / ruby-array-slicing-weirdness.rb
Last active February 25, 2022 13:24
special case for accessing the first out-of-range element in an array
array = ['foo']
# slicing
p array[0,1] #=> ["foo"]
p array[1,1] #=> [] - SURPRISE!?
p array[2,1] #=> nil
# accessing
# no surprises
p array[0] #=> "foo"
# this example shows that in ruby you can
# define how an object is being compared
# to another object with a custom `==` method
class ProductItem
attr_reader :name, :quantity
def initialize(name, quantity)
@name = name
@quantity = quantity
@nickangtc
nickangtc / insert yyyymmddhhmm timestamp Apple Automator service.js
Last active February 17, 2020 16:36
Apple Automator script using JavaScript to generate a timestamp string in format YYYYMMDDHHMM
// To use JavaScript in Apple Automator, select 'Run JavaScript' action
// copy-paste this code into that action
// no need to have any other action -> output is printed automatically
function run(input, parameters) {
var now = new Date()
var year = now.getFullYear()
var month = now.getMonth() + 1
var day = now.getDate()
var hours = now.getHours()