Skip to content

Instantly share code, notes, and snippets.

View MrOrz's full-sized avatar
💤
Sleepy everyday

Johnson Liang MrOrz

💤
Sleepy everyday
View GitHub Profile
@mathiasbynens
mathiasbynens / deterministic-math-random.js
Last active July 22, 2024 16:40
Here’s a 100% deterministic (predictable) alternative to `Math.random`. Useful when benchmarking.
// Here’s a 100% deterministic alternative to `Math.random`. Google’s V8 and
// Octane benchmark suites use this to ensure predictable results.
Math.random = (function() {
var seed = 0x2F6E2B1;
return function() {
// Robert Jenkins’ 32 bit integer hash function
seed = ((seed + 0x7ED55D16) + (seed << 12)) & 0xFFFFFFFF;
seed = ((seed ^ 0xC761C23C) ^ (seed >>> 19)) & 0xFFFFFFFF;
seed = ((seed + 0x165667B1) + (seed << 5)) & 0xFFFFFFFF;
@MrOrz
MrOrz / fbidinject.js
Created April 18, 2012 11:36
This bookmart script adds fbid of each post in facebook into the selector button on the top-right of each post.
(function(){
var elems = document.querySelectorAll('.uiUnifiedStory.uiStreamStory.genericStreamStory');
for(var i = 0; i < elems.length; ++i){
var el = elems[i], a = el.querySelector('.uiSelectorButton.highlightSelectorButton');
if(!a){continue;}
a.href = JSON.parse(el.dataset.ft).fbid;
}
return false;
}())
@yellowled
yellowled / ffmpeg-html5
Created December 6, 2011 19:39
Convert videos to proper formats for HTML5 video on Linux shell using ffmpeg. Will probably convert this to a bash script later, but for the time being, here's some examples. Not sure there have actually sensible dimensions and bitrates for web video.
# webm
ffmpeg -i IN -f webm -vcodec libvpx -acodec libvorbis -ab 128000 -crf 22 -s 640x360 OUT.webm
# mp4
ffmpeg -i IN -acodec aac -strict experimental -ac 2 -ab 128k -vcodec libx264 -vpre slow -f mp4 -crf 22 -s 640x360 OUT.mp4
# ogg (if you want to support older Firefox)
ffmpeg2theora IN -o OUT.ogv -x 640 -y 360 --videoquality 5 --audioquality 0 --frontend