Skip to content

Instantly share code, notes, and snippets.

View jerrybendy's full-sized avatar
🏢
Hard working

Jerry Bendy jerrybendy

🏢
Hard working
View GitHub Profile
@jerrybendy
jerrybendy / loadScript.js
Created July 9, 2019 07:40
Load a JavaScript file from the server, then execute it.
/**
* Load a JavaScript file from the server, then execute it.
*
* Code comes from `https://github.com/ded/script.js`
* If your want more features, please follow the original
*
* @usage:
* loadScript('http://example.com/test.js', function() {
* console.log('Loaded')
* });
@jerrybendy
jerrybendy / resolveHttps.js
Created June 27, 2019 09:10
Force modify a URL to HTTPS if your website is under HTTPS
/**
* Force modify a URL to HTTPS if your website is under HTTPS
*
* @example resolveHttps('http://example.com')
* If you are under a HTTPS website, it'll return `https://example.com`,
* Else it'll return `http://example.com`
*
* @param {string} url
* @return {string}
*/
@jerrybendy
jerrybendy / flat-data-to-tree.js
Created March 29, 2019 02:23
Convert flat data to tree format 平铺格式转树状结构
/**
* Convert flat data to tree format
*
* @see http://blog.csdn.net/chelen_jak/article/details/21290769
*
* @param {array} a json数据
* @param {String} idStr id的字符串
* @param {String} pidStr 父id的字符串
* @param {String} childrenStr children的字符串
* @return {array} 数组
@jerrybendy
jerrybendy / multiple-line-overflow.css
Created December 6, 2018 09:30
CSS Multiple Line Overflow
div {
overflow : hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2; /* should be the line count limited */
-webkit-box-orient: vertical;
}
@jerrybendy
jerrybendy / getQueryString.js
Last active January 3, 2021 03:43
Get parameter from URL query(search) string
/**
* Get parameter from URL query(search) string
*
* Example:
* ```
* var id = getQueryString('id')
* ```
*
* @param {string} name
* @returns {string}
@jerrybendy
jerrybendy / mixPanelDetectBrowser.js
Created November 20, 2017 11:35
Get browser infomation for MixPamel (node)
/**
* Get browser infomation for MixPamel (node)
*
* Usage:
* var detectBrowser = require('./mixPanelDetectBrowser.js')
* mixpanel.track('some events', Object.assign({}, detectBrowser(theUserAgentYouGet), {
* // your properties
* }));
*
* @param userAgent
@jerrybendy
jerrybendy / index.html
Created January 5, 2017 03:33
一个使用 HTML5 录音的例子(网上看到的,收藏下)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<div>
<audio controls autoplay></audio>
<input onclick="startRecording()" type="button" value="录音" />
@jerrybendy
jerrybendy / contenteditable.js
Created September 17, 2016 14:25
Angular 1.x 为元素添加 contenteditable 支持
/**
* contenteditable 支持, 代码来自 http://stackoverflow.com/questions/23047093/contenteditable-in-angular-js
* 对于添加了 contenteditable 属性的元素, 可以直接用 `ng-model` 双向绑定
*/
app.directive('contenteditable', function() {
return {
restrict: 'A', // only activate on element attribute
require: '?ngModel', // get a hold of NgModelController
link: function(scope, element, attrs, ngModel) {
if(!ngModel) return; // do nothing if no ng-model
@jerrybendy
jerrybendy / getQueryString.js
Last active September 5, 2016 10:03
获取 URL 参数的简单实现
function getQueryString (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
@jerrybendy
jerrybendy / .babelrc
Last active August 17, 2016 10:16
React 组件中调用方法避免使用 .bind(this) 的一种方式,使用 ES6 和 ES7 的新特性
{
"presets": [
"react",
"es2015"
],
"plugins": [
"transform-class-properties"
]
}