Skip to content

Instantly share code, notes, and snippets.

index := hash & (1 << B - 1)
Size Range Range in Binary no. of bits
4 0..3 0..11 2
8 0..7 0..111 3
10 0..9 0..1111 4
16 0..15 0..1111 4
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return '0 Byte';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}
function bytesToSize(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
@marawannwh
marawannwh / git-aware-bash-prompt.md
Created September 3, 2019 23:42 — forked from eliotsykes/git-aware-bash-prompt.md
Git Aware Bash Prompt
@marawannwh
marawannwh / GitForWindowsSetup.md
Created February 28, 2019 13:31 — forked from dmangiarelli/GitForWindowsSetup.md
How to setup SSH with Git for Windows

How to setup Git for Windows

I know this document seems long, but it shouldn't be too difficult to follow. This guide is based on Windows, but every program here has Linux/Mac equivalents, and in most cases they're built-in. So, take a deep breath and go step by step.

The steps below are for GitHub, but the steps are almost idential for Bitbucket, Heroku, etc.

You'll probably want to make sure Chocolatey is installed, since it streamlines installing this stuff later. If you install via Chocolatey, you don't need to run the installers from the products' respective sites.

Cmder / ConEmu

@marawannwh
marawannwh / runAsync.js
Created February 12, 2019 14:25
Runs a function in a separate thread by using a Web Worker.
const runAsync = fn => {
const worker = new Worker(
URL.createObjectURL(new Blob([`postMessage((${fn})());`]), {
type: 'application/javascript; charset=utf-8'
})
);
return new Promise((res, rej) => {
worker.onmessage = ({ data }) => {
res(data), worker.terminate();
};
@marawannwh
marawannwh / watson
Created December 19, 2018 11:57
Response from Watson TTS HTTP API
{
"mimeResult": {
"mimetype": "audio/l16; rate=22050",
"data": {
"__binary": "base64",
"payload": "BwARABkAGQARAAgAAwAAAP//AQAKAAYAAADz/+H/0P++/7//wP/J/9H/z//N/83/yv/J/9H/3v/s//j//f/6//X/9f/u/+n/5//n/+7/6//n/+z/7P/v/+7/6f/k/9v/2v/b/+n/8/8AAAMAAwD///b/+f/5////BgALAAoA///8//P/6f/n//L/+P8EAAYAEAAGAP///P8BABEAGAAfACIAGQAbABcADgALAAAAAQAAAAcAAAD///L/5P/N/8D/u/++/8b/0//i//P////8/+//5P/N/8z/2v/w/wAAAQD8//D/4f/K/7//wv/C/9H/8P/l/+v/6//o/+n/9f/9/+//8v/p/+z/7P8AAL7/XQAxAKb/7P/R/6H/v//l/6v/lv/i/wYA+v/T/7n/2P8AAPD/1P/1/wAAEgAfAPr/CAApABIACAAGABkAGQASACMANAA7ACAAPgA5ACgANgBAAEQAVQBjAHgAcQBuAHIAXQBTAFYAWgBRAE4AYwBcAGMAZABrAGAAVgBTAFYAaQB4AIgAiACIAIUAiQCGAHQAewB/AHwAiACMAJAAeQB5AGcAVQBFAC0AKgAmACIAGwAXAB8AGwAUABQAEAAAAAsAAwAQABwAKAAjADQANAAcABQAEAAYABgAHAAUABQACwAAAAAA9f/r/+f/5//n/+v/6//e/+L/5//i/+f/6//v/+f/7//z/+v/+P/8//z/+P/z//P/+P/4/wAACAAIAAgABAAVABUAFQARABUAGQARABEAHgAeABEAGQAqACoAJgAzADMAMwA3AEgAVQBRAGEAbgB3AHsAfwCIAIwAiACIAIwAlACZAJ0AoQCZAJkAmQCZAKUAoQCqAKEApQCuALIArgCuAJ0AjAB/AGoAZg
@marawannwh
marawannwh / ts.js
Last active November 1, 2018 00:20
ts voices
{value: 'Matthew', lang: 'en-US', name: 'Matthew (en-US)', sample: 'https://firebasestorage.googleapis.com/v0/b/play-68705.appspot.com/o/0-sample-mathew-speech_20171218030814983.mp3?alt=media&token=63ec628e-aeed-4f9b-b6ba-0d684f9d033e'},
{value: 'en-US_MichaelVoice', lang: 'en-US', name: 'Michael (en-US)', sample: 'https://www.googleapis.com/download/storage/v1/b/play-testing-412e4.appspot.com/o/full_-KW9TW-SvS8uNwlZX_R-.mp3?generation=1518381457510829&alt=media'},
{value: 'en-US_AllisonVoice', lang: 'en-US', name: 'Samantha (en-US)', sample: 'https://www.googleapis.com/download/storage/v1/b/play-68705.appspot.com/o/full_-KgVb-83aMMBMvrwu3dM.mp3?generation=1518483417835485&alt=media'},
{name: "James (en-US)", lang: 'en-US', value: "en-US-Wavenet-A", sample: "https://www.googleapis.com/download/storage/v1/b/play-68705.appspot.com/o/full_-L9221lipExv_CkzIPB2.mp3?generation=1522617039958470&alt=media"},
{name: "Robert (en-US)", lang: 'en-US', value: "en-US-Wavenet-B", sample: "https://www.googleapis.com/download
@marawannwh
marawannwh / ruby language
Created December 18, 2016 19:18 — forked from patriques82/ruby language
A summary of the book "The Ruby Programming Language" by David Flanagana and Yukihiro "Matz" Matsumoto
CONTENT
Expressions, Statements and Controlstructures
Equlaity
Assigments
The ||= idiom
Other assignments
Flip-flops
Iterators
Blocks
Control-flow keywords
// User Code
type User struct {
Id int
Name string
}
// implement auth interface
func (u User) Authenticate(r *http.Request) (interface{}, error) {
// auth
return u, nil
}