Skip to content

Instantly share code, notes, and snippets.

@joeylin
joeylin / gl-form.py
Created December 10, 2019 06:24 — forked from gpocentek/gl-form.py
python-gitlab login/password auth using cookies
import re
import sys
import requests
import gitlab
URL = 'https://gitlab.com'
SIGN_IN_URL = 'https://gitlab.com/users/sign_in'
@joeylin
joeylin / AutowiringSpringBeanJobFactory.java
Created June 6, 2017 02:25 — forked from jeffsheets/AutowiringSpringBeanJobFactory.java
Configuring Quartz 2.1.7 with Spring 3.1.3 in clustered mode
/**
* Autowire Quartz Jobs with Spring context dependencies
* @see http://stackoverflow.com/questions/6990767/inject-bean-reference-into-a-quartz-job-in-spring/15211030#15211030
*/
public final class AutowiringSpringBeanJobFactory extends SpringBeanJobFactory implements ApplicationContextAware {
private transient AutowireCapableBeanFactory beanFactory;
public void setApplicationContext(final ApplicationContext context) {
beanFactory = context.getAutowireCapableBeanFactory();
}
function versionCompare(a, b) {
var i;
var len;
if (typeof a + typeof b !== 'stringstring') {
return false;
}
a = a.split('.');
b = b.split('.');
@joeylin
joeylin / angularjs-providers-explained.md
Last active August 29, 2015 14:25 — forked from demisx/angularjs-providers-explained.md
AngularJS Providers: Constant/Value/Service/Factory/Decorator/Provider
Provider Singleton Instantiable Configurable
Constant Yes No No
Value Yes No No
Service Yes No No
Factory Yes Yes No
Decorator Yes No? No
Provider Yes Yes Yes

Constant

function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// 此时即支持CORS的情况
// 检查XMLHttpRequest对象是否有“withCredentials”属性
// “withCredentials”仅存在于XMLHTTPRequest2对象里
xhr.open(method, url, true);
} else if (typeof!= "undefined") {
@joeylin
joeylin / pm2.js
Created August 26, 2014 02:31
pm2基本操作
启动
pm2 start app.js -i max
监控
pm2 monit
log
pm2 logs
@joeylin
joeylin / broswer.js
Created August 25, 2014 23:57
浏览器检测代码
Client = (function() {
var d = {engine: {ie: 0,gecko: 0,webkit: 0,opera: 0,khtml: 0},browser: {ie: 0,firefox: 0,chrome: 0,opera: 0,safari: 0,konq: 0}};
var b = navigator.userAgent;
var c = d.engine;
var a = d.browser;
if (window.opera) {
a.version = c.version = window.opera.version();
a.opera = c.opera = parseFloat(c.version)
} else {
if (/AppleWebKit\/(\S+)/.test(b)) {
@joeylin
joeylin / transitionend_name.js
Last active August 29, 2015 14:05
正确取得transitionend事件的可用名字
function getTransitionEndEventName() {
var obj = {
TransitionEvent: "transitionend",
WebKitTransitionEvent: "webkittransitionEnd",
OTransitionEvent: "OTransitionEnd",
otransitionEvent: "otransitionEnd",
MSTransitionEvent: "MSTransitionEnd"
}
// var ev = document.createEvent("TransitionEvent"); // FIXME: un-specified
// ev.initTransitionEvent("transitionend", true, true, "some-unknown-prop", -4.75);
@joeylin
joeylin / mail.js
Created August 6, 2014 16:08
nodemail config
var nodemailer = require('nodemailer');
var config = require('../config/config.js');
// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP", {
service: config.email.service,
auth: {
user: config.email.user,
pass: config.email.pass
}
@joeylin
joeylin / random.js
Last active August 29, 2015 14:04
mongoose random search code
module.exports = function (options) {
var randFn = (options && options.fn) || Math.random;
function random(schema, options) {
var path = (options && options.path) || 'random';
var field = {};
field[path] = {
type: { type: String, default: 'Point' },
coordinates: { type: [Number], default: function () { return [randFn(), randFn()] } }
};