Skip to content

Instantly share code, notes, and snippets.

View bulatie's full-sized avatar
🏴‍☠️

Michael bulatie

🏴‍☠️
View GitHub Profile
@bulatie
bulatie / 24_time_format
Created February 7, 2015 12:32
24 hours time format
//pads n with zeros on the left,
//digits is minimum length of output
//zeroPad(3, 5); returns "005"
//zeroPad(2, 500); returns "500"
zeroPad: function(digits, n) {
n = n.toString();
while(n.length < digits)
n = '0' + n;
return n;
},
@bulatie
bulatie / test_screen_landscape_or_portrait.js
Created May 25, 2015 10:46
横竖屏切换检测代码
(function() {
var supportOrientation = (typeof window.orientation === 'number' &&
typeof window.onorientationchange === 'object');
var init = function() {
var htmlNode = document.body.parentNode,
orientation;
var updateOrientation = function() {
if (supportOrientation) {
orientation = window.orientation;
@bulatie
bulatie / getAbsolutePosition.js
Last active August 29, 2015 14:26
get element absolute height
function getElementTop(element) {
if (document.documentElement.getBoundingClientRect !== 'undefined') {
return element.getBoundingClientRect().top + document.body.scrollTop;
} else {
var actualTop = element.offsetTop;
var current = element.offsetParent;
while (current !== null) {
actualTop += current.offsetTop;
current = current.offsetParent; 
}
@bulatie
bulatie / getRelativePosition.js
Last active August 29, 2015 14:26
get element position height relate viewport
function getElementViewTop(element) {
if (document.documentElement.getBoundingClientRect !== 'undefined') {
return element.getBoundingClientRect().top
} else {
var actualTop = element.offsetTop
var current = element.offsetParent
while (current !== null) {
actualTop += current.offsetTop
current = current.offsetParent
}
@bulatie
bulatie / $extend.js
Created August 6, 2015 02:25
return merged object
function $extend() {
var arr = arguments,
result = {},
i;
var _isObject = function(o) {
return Object.prototype.toString.call(o) === '[object Object]';
}
var _extend = function self(destination, source) {
addEventListener("scroll",()=> document.title=`read ${(scrollY/document.body.scrollHeight*100).toFixed(2)}%`)
# This configuration file binds many vi- and vim-like bindings to the
# appropriate tmux key bindings. Note that for many key bindings there is no
# tmux analogue. This is intended for tmux 1.3, which handles pane selection
# differently from the previous versions
# split windows like vim
# vim's definition of a horizontal/vertical split is reversed from tmux's
bind s split-window -v
bind v split-window -h
@bulatie
bulatie / toChineseNum.js
Created April 1, 2017 14:47
Translate one hundred or less Arabic numerals into Chinese characters
function toChineseNum (index) {
let str = '' + index
if (index > 99) return '一百'
if (index < 10) {
return str.replace(/1/g, '一')
.replace(/2/g, '二')
.replace(/3/g, '三')
.replace(/4/g, '四')
.replace(/5/g, '五')
.replace(/6/g, '六')
@bulatie
bulatie / autoTextarea.js
Created April 1, 2017 14:52
Make textarea adaptive text height
function autoTextarea (elem, extra, maxHeight) {
extra = extra || 0
var addEvent = function (type, callback) {
elem.addEventListener ? elem.addEventListener(type, callback, false) : elem.attachEvent('on' + type, callback)
}
var getStyle = elem.currentStyle ? function (name) {
var val = elem.currentStyle[name]
if (name === 'height' && val.search(/px/i) !== 1) {
var rect = elem.getBoundingClientRect()
return rect.bottom - rect.top - parseFloat(getStyle('paddingTop')) - parseFloat(getStyle('paddingBottom')) + 'px'