Skip to content

Instantly share code, notes, and snippets.

@shussekaido
shussekaido / machine.js
Created August 31, 2020 07:23
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@shussekaido
shussekaido / machine.js
Last active August 16, 2020 01:15
Generated by XState Viz: https://xstate.js.org/viz
/*
Retrying logic for https://egghead.io/lessons/xstate-use-xstate-null-events-and-transient-transitions-to-immediately-transition-states
*/
const fetchMachine = Machine({
id: 'fetch',
initial: 'idle',
context: {
tries: 0
},
states: {
@shussekaido
shussekaido / ffmpeg-throttle.txt
Created August 9, 2018 17:50
Throttle ffmpeg
Reference:
https://lorenzo.mile.si/2016/07/limiting-cpu-usage-and-server-load-with-ffmpeg/
https://github.com/opsengine/cpulimit
brew install cpulimit
Run ffmpeg with:
nice -19 cpulimit -l 30 -- ffmpeg blah blah -threads 1 /tmp/yourvideo.mp4
Note that '-threads 1' needs to be the last option.
@shussekaido
shussekaido / polling.js
Created January 9, 2017 07:04
Use Promise to wait until polled condition is satisfied
function ensureFooIsSet() {
return new Promise(function (resolve, reject) {
(function waitForFoo(){
if (lib.foo) return resolve();
setTimeout(waitForFoo, 30);
})();
});
}
// http://stackoverflow.com/questions/30505960/use-promise-to-wait-until-polled-condition-is-satisfied
@shussekaido
shussekaido / koohiistroke.js
Created November 1, 2014 15:18
Adds kanji stroke order to the Study and Review sections of kanji.koohii.com. Works with Tampermonkey or Greasemonkey for Chrome or Firefox.
// ==UserScript==
// @name Kanji.koohii Stroke Order
// @namespace koohiistroke
// @description Adds kanji stroke order to the study and review sections on kanji.koohii.com
// @include http://kanji.koohii.com/study/kanji/*
// @include https://kanji.koohii.com/study/kanji/*
// @include http://kanji.koohii.com/review*
// @include https://kanji.koohii.com/review*
// @grant GM_xmlhttpRequest
// @version 1.1
@shussekaido
shussekaido / Koohii Review stroke order
Created February 23, 2014 12:03
Adds Kanji Stroke Order to the Review section of kanji.koohii.com. Tested in Chrome with Tampermonkey.
// ==UserScript==
// @name Kanji.koohii Stroke Order - Review section
// @namespace koohiireview
// @description Adds Kanjis Stroke Order to the Review section
// @include http://kanji.koohii.com/review*
// @include https://kanji.koohii.com/review*
// @version 1.0
// ==/UserScript==
@shussekaido
shussekaido / Remove timecodes from SRT
Created September 30, 2013 16:10
Creates plain text from SRT files by removing timecodes
To simply remove timecodes (this is a long command that should be on one line):
cat episode01.srt
|cat "$@"|tr -d '\r'
|grep -v '^[0-9]*$'
|grep -v '^[0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9] --> [0-9]'
> episode01.txt
To remove timecodes and linebreaks:
@shussekaido
shussekaido / gist:ddd94060539ef90f7eaf
Last active January 9, 2017 07:09
Confluence 5 on FreeBSD 9 with OpenJDK 7
# 
#Prepare
# 
# On brand new FreeBSD do:
portsnap fetch extract
# Otherwise do:
portsnap fetch update
@shussekaido
shussekaido / our_setup_script.js
Created December 5, 2012 14:56
MongoDB M102 week6 file
db = db.getSisterDB("config");
var mongosConn = db; // assume we connected to a mongos to get going
var res = null;
function check() {
printjson(res);
if( !res || !res.ok ) {
throw "check(): not ok, stopping";
@shussekaido
shussekaido / m101_hw_2.2.js
Created November 2, 2012 16:46
M101 HW 2.2
// Assign your query to a variable. To quote the assignment: "select homework documents, sort by student and then by score"
var students = db.grades./* YOUR CODE */
// Create a variable to track student_id so we can detect when it changes
var id = "";
// Loop through our query results. Each document in the query is passed into a function as 'student'
students.forEach(function (student) {
if (id !== student.student_id) { // Check if the student_id is new
db.grades./* YOUR CODE */ // If your 'students' query is correct the document with the lowest homework score is here. Remove it.