Skip to content

Instantly share code, notes, and snippets.

View MrRaindrop's full-sized avatar

Parzival MrRaindrop

View GitHub Profile
@MrRaindrop
MrRaindrop / php: session handler via mySQL.php
Last active August 29, 2015 14:07
php: session handler via mySQL
<?php
class MySQLSessionHandler {
private $_dblink;
private $_sessionName;
private $_sessionTable;
CONST SESS_EXPIRE = 3600;
@MrRaindrop
MrRaindrop / javascript: crazy dancing elements.js
Created November 12, 2014 09:45
javascript: crazy dancing elements
javascript:(function() {
function c() {
var e = document.createElement("link");
e.setAttribute("type", "text/css");
e.setAttribute("rel", "stylesheet");
e.setAttribute("href", f);
e.setAttribute("class", l);
document.body.appendChild(e)
}
import sublime
import sublime_plugin
import re
class CompactExpandCssCommand(sublime_plugin.TextCommand):
def run(self, edit, action='compact'):
rule_starts = self.view.find_all('\{')
rule_ends = self.view.find_all('\}')
@MrRaindrop
MrRaindrop / javascript: detect activity of web page
Created February 1, 2015 08:20
javascript: detect whether this web page is visible/activated or not
(function() {
var hidden = "hidden";
// Standards:
if (hidden in document)
document.addEventListener("visibilitychange", onchange);
else if ((hidden = "mozHidden") in document)
document.addEventListener("mozvisibilitychange", onchange);
else if ((hidden = "webkitHidden") in document)
document.addEventListener("webkitvisibilitychange", onchange);
else if ((hidden = "msHidden") in document)
@MrRaindrop
MrRaindrop / js: notification-as-promise.js
Created February 26, 2015 06:59
js: use web notification as a promise.
function notifyMessage(message, options, callback) {
if (Notification && Notification.permission === 'granted') {
var notification = new Notification(message, options);
callback(null, notification);
} else if (Notification.requestPermission) {
Notification.requestPermission(function (status) {
if (Notification.permission !== status) {
Notification.permission = status;
}
if (status === 'granted') {
@MrRaindrop
MrRaindrop / js: react+线性分割算法实现的类似flickr的图片布局
Last active August 29, 2015 14:16 — forked from kejun/gist:72112e5848f5e3921b0d
js: react+线性分割算法实现的类似flickr的图片布局
var React = require('react');
var EventListener = require('react/lib/EventListener');
var partition = require('linear-partitioning');
var TileLayout = React.createClass({
getDefaultProps: function() {
return {
gutter: 0,
photos: []
}
@MrRaindrop
MrRaindrop / js: simple-template-implementation.js
Last active August 29, 2015 14:24
js: simple-template-implementation
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
@MrRaindrop
MrRaindrop / js: es6-template-string-for-if.js
Created July 3, 2015 08:02
js: es6-template-string-for-if
#!/usr/bin/env iojs
function $for(data, tpl) {
return data.map(tpl).join('');
}
function $if(condition, datathen, tplthen) {
return {
$else: function(dataelse, tplelse) {
if (!!condition) {
@MrRaindrop
MrRaindrop / js: simple implementation of browserifyjs.js
Created July 14, 2015 07:06
js: simple implementation of browserifyjs
// author ranyifeng
// link: http://www.ruanyifeng.com/blog/2015/05/commonjs-in-browser.html
//
// Usage
//
// require.register("browser/debug.js", function(module, exports, require){
// // Module code goes here
// });
//
// var debug = require("browser/debug.js");
@MrRaindrop
MrRaindrop / Remove node_modules from git repo
Last active August 29, 2015 14:25 — forked from paulallies/gist:0052fab554b14bbfa3ef
Remove node_modules from git repo
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master