Skip to content

Instantly share code, notes, and snippets.

@patterns
patterns / mergesort.go
Created October 5, 2016 10:53
Merge sort recursive
package main
import (
"fmt"
"bufio"
"os"
)
//see Cracking Code Interview
//practice merge sort (recursive; next try iterative...)
//input is n items on line 1, then space separated values on line 2
@patterns
patterns / quicksort.go
Created October 7, 2016 05:33
Quick sort recursive
package main
import (
"fmt"
"bufio"
"os"
)
//see Cracking Code Interview
//practice quick sort (recursive)
@patterns
patterns / lru.go
Created October 7, 2016 08:47
LRU caching example
package main
import (
"fmt"
"bufio"
"os"
"errors"
)
//practice LRU cache
@patterns
patterns / spotifytrack.applescript
Last active October 9, 2016 08:33
Write Spotify track info to file
-- Original script is on Spotify Applescript API page
-- Creates a notification with information about the currently playing track
-- Main flow
set theFile to (((path to desktop folder) as string) & "trackinfo.txt")
if appIsRunning("Spotify") then
set currentlyPlayingTrack to getCurrentlyPlayingTrack()
----displayTrackName(currentlyPlayingTrack)
writeTextToFile(currentlyPlayingTrack, theFile, true)
@patterns
patterns / lru.py
Created October 24, 2016 20:45
My very first Python script ever!
#lru.py
#loop input until 'EXIT'
read_line = ""
data = []
while read_line.lower() != "exit":
read_line = raw_input()
if read_line.lower() != "exit":
data.append(read_line)
@patterns
patterns / readme.txt
Created October 27, 2016 05:31
Practice adapter pattern on SHA1 / SHA256 / .....
Reference https://msdn.microsoft.com/en-us/library/orm-9780596527730-01-04.aspx
Attempt of the pluggable adapter according to this excerpt:
// Existing way requests are implemented
class Adaptee {
public double Precise (double a, double b) {
return a/b;
}
}
@patterns
patterns / lib.go
Created October 28, 2016 10:41
Microsvc to compare adapters vs facade
package main
import (
"crypto/sha1"
"crypto/sha256"
"fmt"
)
// Adaptee is the existing functionality.
type Adaptee struct {
@patterns
patterns / splice-sound.sh
Created February 3, 2017 04:17
Use ffmpeg to splice sound file by specifying start time position (-ss) and duration (-t)
#!/bin/sh
ffmpeg -ss 00:00:00.000 -i Source.mp3 -t 44 -c copy cut00.mp4
@patterns
patterns / extract-sound.sh
Created February 3, 2017 04:25
Use ffmpeg to extract audio from source video files
#!/bin/bash
INFILE="$1"
TMPOUTFILE="${INFILE%.*}"
OUTFILE="${TMPOUTFILE##*/}.m4a"
ffmpeg -i "${INFILE}" -vn -acodec copy "${OUTFILE}"
@patterns
patterns / youtube-dl.sh
Created February 3, 2017 04:28
Save sound from Youtube video URL
#!/bin/bash
#brew install youtube-dl
#brew install ffmpeg
youtube-dl --extract-audio --audio-format mp3 -k https://youtu.be/short-url-path