Skip to content

Instantly share code, notes, and snippets.

View ouzhenkun's full-sized avatar
🎯
Focusing

ryan ouzhenkun

🎯
Focusing
View GitHub Profile
@ouzhenkun
ouzhenkun / bytesToSize.js
Created April 17, 2019 02:33 — forked from lanqy/bytesToSize.js
JavaScript To Convert Bytes To MB, KB, Etc
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
@ouzhenkun
ouzhenkun / cloudSettings
Last active February 3, 2021 03:23
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-02-03T03:22:55.031Z","extensionVersion":"v3.4.3"}
@ouzhenkun
ouzhenkun / GIT_CHEATSHEET.md
Last active June 1, 2016 16:02 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@ouzhenkun
ouzhenkun / one-liners.js
Created May 17, 2016 16:11 — forked from nepsilon/5-handy-javascript-one-liners.md
5 handy Javascript one-liners
//1. Generate a random string:
Math.random().toString(36).substr(2);
//This simply generates a random float, casts it into a String using base 36 and remove the 2 first chars 0 and ..
//2. Clone an array:
var newA = myArray.slice(0);
//This will return a copy of the array, ensuring no other variables point to it.
//3. Remove HTML tags:
"<b>A</b>".replace(/<[^>]+>/gi, "");
@ouzhenkun
ouzhenkun / bytes.filter.coffee
Created January 21, 2015 07:01
bytes 字节数转换成可读的字符
angular.module('testApp').filter 'bytes', ->
(bytes, precision) ->
if isNaN(parseFloat(bytes)) || !isFinite(bytes) then return '-'
precision = 1 if !precision?
units = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB']
number = Math.floor(Math.log(bytes) / Math.log(1024))
(bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number]