Skip to content

Instantly share code, notes, and snippets.

@lisaah
lisaah / convert_svg_to_pdf.sh
Created January 25, 2014 18:15
Simple shell script to convert all .svg in directory to .pdf
# Dependency:
# sudo apt-get install librsvg2-bin
find . -type f -name "*.svg" -exec bash -c 'rsvg-convert -f pdf -o $0.pdf $0' {} \;
@lisaah
lisaah / convert_aiff_to_wav.bat
Last active November 11, 2022 15:47
Simple batch script to convert .aiff files in current directory into .wav and put them in a directory. Didn't feel like setting sox as an environment variable so it's called directly.
@echo off
REM Dependency:
REM SoX: http://sox.sourceforge.net/
mkdir converted_wav
for %%f in (*.aiff) do (
"C:\Program Files (x86)\sox-14-4-1\sox" %%~nf.aiff "converted_wav/%%~nf.wav"
)
pause
from random import choice
'''
Some quick code to try out applying Q-Learning to Nim game in Python.
'''
def get_best_action(q, s):
'''
Given the q table and state,
pick the best action.
'''
// Rotate an array to right by n.
function rotate(a, n) {
// Convert negative to positive.
if (n < 0) n = ((n % a.length) + a.length);
n = n % a.length;
reverse(a, 0, a.length); // Move to bottom to reverse to the left.
reverse(a, 0, n);
reverse(a, n, a.length);
}
@lisaah
lisaah / expand.js
Created April 26, 2015 16:28
Format a string by expanding values mapped with String values in a nested Object.
/**
* Expand a string using a supplied regex to denote the properties and a
* possibly nested object to supply the values.
*
* inputString - The string to be formatted.
* valuesObject - An Object holding either values stored as strings or other Objects
* nestSeparator - The marker used to indicated a nested property
* propRegex - Regex used to indicate the property in the inputString. Assumes the actual
* key value will be indicated by using ().
*
@lisaah
lisaah / changeLumosity.js
Last active December 24, 2015 19:27
Change the brightness/darkness for a 3 or 6 digit hex color by adding white/black. Input '#' is optional, returns in 6-digit format like so '#ffffff'.
/**
* Takes a decimal value and changes it by the specified percentage (based off of the distance
* from 0 or 255, depending on whether the percentage change is negative or positive, respectively)
* @param {Number} value - number from [0, 255]
* @param {Number} percent - number from [0.0, 1.0]
* @return {Number} - number from [0, 255]
*/
function updateValue(value, percent) {
// Absolute distance from reference value
var distance = percent > 0 ? (255 - value) : value;