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
/**
* API扩展
*
* Class ApiTrait
*/
trait ApiTrait
{
/**
* 设置允许跨域访问的域名白名单
*/
@jerrybendy
jerrybendy / filter_relative_url.php
Last active July 6, 2018 10:18
PHP转换网址相对路径到绝对路径的一种方法 https://icewing.cc/php-conv-addr-re-ab-2.html
/**
* 把从HTML源码中获取的相对路径转换成绝对路径
* @param string $url HTML中获取的网址
* @param string $URI 用来参考判断的原始地址
* @return 返回修改过的网址,如果网址有误则返回FALSE
*/
function filter_relative_url($url, $URI){
//STEP1: 先去判断URL中是否包含协议,如果包含说明是绝对地址则可以原样返回
if(strpos($url, '://') !== FALSE){
return $url;
@jerrybendy
jerrybendy / .babelrc
Last active August 17, 2016 10:16
React 组件中调用方法避免使用 .bind(this) 的一种方式,使用 ES6 和 ES7 的新特性
{
"presets": [
"react",
"es2015"
],
"plugins": [
"transform-class-properties"
]
}
@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 / 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 / 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 / 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 / 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 / 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;
}