Skip to content

Instantly share code, notes, and snippets.

View swang's full-sized avatar

Shuan Wang swang

  • San Francisco, CA
View GitHub Profile
@swang
swang / locker.js
Created September 29, 2016 22:17
Locker Problem
// fill an 100-element array with zero (0 = closed, 1 = open)
let lockers = new Array(100).fill(0)
// iterate 1-100 in outer loop, iterate i-100, jumping to every i-th term
for (let i = 1; i <= 100; i++) {
for (let j = i; j <= 100; j += i) {
// flip switch on locker value
lockers[j - 1] = !lockers[j - 1] ? 1 : 0
}
}
@swang
swang / gist:8a4bd5b01773b73c0835e54919ba1b02
Last active September 14, 2016 08:19
convert wav audio into mp3 (low qual)
for f in *.wav; do ffmpeg -i "$f" -vn -ar 44100 -ac 2 -ab 64k -f mp3 "${f%.wav}.mp3"; done;
@swang
swang / npm-output.log
Created June 2, 2016 09:34
Output of running ipfs station 1.0.0-alpha.1 on node v6.0
~/Projects/ipfs/station (master): npm run build
> [email protected] build /Users/Projects/ipfs/station
> npm run clean && npm run build:webpack && npm run build:babel && npm run copy
> [email protected] clean /Users/Projects/ipfs/station
> rimraf build && mkdir build

Keybase proof

I hereby claim:

  • I am swang on github.
  • I am swang (https://keybase.io/swang) on keybase.
  • I have a public key ASDjnHZWBRFTaUfB2zLYm6UrXGmUc3VIQdHVWlR9DaqYugo

To claim this, I am signing this object:

@swang
swang / scrap
Last active August 29, 2015 14:21
urls for later
https://nodejs.org/docs/v0.8.26/api/
@swang
swang / medium-editor.js
Last active November 5, 2024 00:13
medium-editor.js
/*global module, console*/
function MediumEditor(elements, options) {
'use strict';
this.init(elements, options);
}
if (typeof module === 'object') {
module.exports = MediumEditor;
}
function MediumEditor(elements, options) {
'use strict';
return this.init(elements, options);
}
if (typeof module === 'object') {
module.exports = MediumEditor;
}
(function (window, document) {
@swang
swang / fizzbuzz.rs
Created January 29, 2014 06:34
FizzBuzz in Rust
fn main() {
let mut counter = 1u;
while counter <= 100 {
let result =
match counter {
z if z % 15 == 0 => ~"FizzBuzz",
z if z % 3 == 0 => ~"Fizz",
z if z % 5 == 0 => ~"Buzz",
_ => counter.to_str()
@swang
swang / intro.md
Created December 31, 2013 01:49
MLM Marketing Scam

Just a small function I wrote to show how much of a scam MLM marketing is.

By default it assumes you want to have 10 people below you peddling wares in your name, and then also assumes the population to be about the number in the US when I made this gist (317,291,776).

@swang
swang / New Yahoo + Avail Players Filter.js
Last active December 24, 2015 13:38
Filters out all the big drops for Yahoo Fantasy Football.
drops = document.querySelectorAll("table.Tst-table tr td.Ta-end:nth-child(even)")
adds = document.querySelectorAll("table.Tst-table tr td.Ta-end:nth-child(odd)")
owners = document.querySelectorAll("table.Tst-table tr td.Ta-start.Nowrap")
for (var i = 0; i < adds.length; i++) { if (!/W \(.*\)/i.test(owners[i].innerText) || parseInt(adds[i].innerText, 10) < parseInt(drops[i].innerText, 10)) { adds[i].parentNode.style.display = 'none' } }