Skip to content

Instantly share code, notes, and snippets.

@yqt
yqt / unbound-wrappers.js
Created September 25, 2013 09:10
use both call and apply together to create fast, unbound wrappers
/*retrieved from http://bonsaiden.github.io/JavaScript-Garden/#function.arguments*/
function Foo() {}
Foo.prototype.method = function(a, b, c) {
console.log(this, a, b, c);
};
// Create an unbound version of "method"
// It takes the parameters: this, arg1, arg2...argN
Foo.method = function() {
@yqt
yqt / check_type.js
Created October 9, 2013 01:52
check the type of an object in js
function is(type, obj) {
var clas = Object.prototype.toString.call(obj).slice(8, -1);
return obj !== undefined && obj !== null && clas === type;
}
is('String', 'test'); // true
is('String', new String('test')); // true
@yqt
yqt / Hightchart_show_extra_data.js
Created October 11, 2013 11:04
show extra data in tooltips of Highchart.
//live testing on http://jsfiddle.net/yqtted/9xKuR/
//shared tooltip version on http://jsfiddle.net/yqtted/WUMfB/
$(function () {
$('#container').highcharts({
series: [{
name: "line1",
composition: {
"data1": [129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4]
},
@yqt
yqt / prevent_double_submission_of_forms.js
Created October 13, 2013 06:36
jQuery plugin to prevent double submission of forms
// jQuery plugin to prevent double submission of forms
jQuery.fn.preventDoubleSubmission = function() {
$(this).on('submit',function(e){
var $form = $(this);
if ($form.data('submitted') === true) {
// Previously submitted - don't submit again
e.preventDefault();
} else {
// Mark it so that the next submit can be ignored
@yqt
yqt / __isset_example.php
Created October 15, 2013 08:07
empty(private value) and __isset()
class Test{
private $name = "test";
private $name1 = "test1";
public function __get($name){
echo "__get() triggered! $$name: " . $name . "\n";
return $this->name;
}
public function __isset($tmp){
echo "__isset() triggered! $$tmp: " . $tmp . "\n";;
$ret = isset($tmp);
@yqt
yqt / params_add_and_remove
Created November 17, 2013 02:14
params add & remove for angularjs
//just look at the fiddle
//http://jsfiddle.net/yqtted/3Me8d/
@yqt
yqt / remove ^M
Created January 9, 2014 08:15
remove ^M in bash script
:set ff=unix<return>
:x<return>
@yqt
yqt / Rename file starting with a dash(-)
Created January 9, 2014 08:45
Rename file starting with a dash(-)
Rename file starting with a dash(-)
If having problem renaming a file that starts with a dash:
Since the file name begins with a '-' it looks like an option to the
command. You need to force it to not look like an option. Put a ./
in the front of it. Or give it the full file name path. Or tell the
command you are through with options by using the double dash to end
all option processing. This is common to most traditional UNIX
commands.
@yqt
yqt / getIEVersion.js
Created January 24, 2014 08:16
get version of IE
var _IE = (function(){
var v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);
return v > 4 ? v : false ;
}());
@yqt
yqt / ocserv.route.conf
Created October 4, 2015 15:16
cisco anyconnect ocserv.conf的路由选择,使用粗略路由。请注意,新的ocserv已经支持 no route命令,因此你可以指定中国的路由不经过vpn咯(这次没有展示,下次不上)
route = 23.0.0.0/255.0.0.0
route=31.13.0.0/255.255.0.0
route = 54.0.0.0/255.0.0.0
route=64.0.0.0/255.0.0.0
route=68.0.0.0/255.248.0.0
route=69.0.0.0/255.0.0.0
route = 74.0.0.0/255.0.0.0
route = 93.0.0.0/255.0.0.0
route = 96.0.0.0/255.0.0.0
#route = 100.0.0.0/248.0.0.0