Skip to content

Instantly share code, notes, and snippets.

View MrRaindrop's full-sized avatar

Parzival MrRaindrop

View GitHub Profile
@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 / 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)
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: 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)
}
@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 / php: calculate subnet addresses.php
Created October 13, 2014 14:48
php: calculate subnet addresses
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>testCalcSubnet</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
IP Address:
<br/><input type="text" name="ip[]" size="3" maxlength="3" />
@MrRaindrop
MrRaindrop / php: HTTP_Upload for file uploading.php
Created October 11, 2014 14:14
php: HTTP_Upload for file uploading
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>testHTTPUpload</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"
enctype="multipart/form-data">
@MrRaindrop
MrRaindrop / php: upload file 2.php
Created October 11, 2014 13:56
php: upload file 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>testUpload2</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"
enctype="multipart/form-data">
@MrRaindrop
MrRaindrop / php: upload file.php
Created October 11, 2014 01:06
php: upload file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>testUpload</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"
enctype="multipart/form-data">
@MrRaindrop
MrRaindrop / php: HTML_QuickForm2 to render a form and validate it.php
Created October 9, 2014 14:47
php: use HTML_QuickForm2 to render and valiate a form
<?php
require_once("HTML/QuickForm2.php");
require_once("HTML/QuickForm2/Renderer.php");
$languages = array(
"" => "Choose Languages:",
"C#" => "C#",
"JavaScript" => "JavaScript",
"Perl" => "Perl",