Skip to content

Instantly share code, notes, and snippets.

/**
* A script for transitioning to HTTPS for clients that support it.
*
* This script will make a request to https:yourdomain.com/ping?_clb_=?
* from the loaded http: document.
* If the request is successful, it will convert all the internal links
* to https:
*/
jQuery(function ($) {
if(location.protocol === 'http:') {
@duzun
duzun / backup.sh
Last active August 29, 2015 14:11
MySQL auto-backup script
#! /bin/sh
#
# Author: Dumitru Uzun (DUzun)
#
# Ussage:
# backup [-k <days>] [-s <subdir>] [-d <database>] [-e <exclude_tables_list>]
#
pass='<best-password-ever>'
user=backup
@duzun
duzun / header_cache.php
Last active August 29, 2015 14:11
Set cache control headers and manage http cache logic
/**
* Set cache control headers and manage http cache logic.
*
* @param (int|bool) $expires: true - use cache, false - no cache, int - expires timeout
* @param (time) [$modified]: Last modification time stamp
* @param (string) [$etag]: ETag content identifier
* @param (int) [$die]: 0 - no die, 1 - die on 304, -1 - no 304 headers
*
* @return (mixed) status code if cache, false if headers sent, true otherwise
*
@duzun
duzun / enableSelect-bookmarklet.html
Last active December 22, 2023 08:04
Enable Right Click and Text Selection Bookmarklet
<a class="btn btn-default btn-info bookmarklet" href="javascript:(function(d){var a=d.document,h=function(){},c=a.body||a.getElementsByTagName("body")[0],f=a.documentElement||a.getElementsByTagName("html")[0],k=[c,f,a],l=["webkit","khtml","moz","ms",""],g=["contextmenu","selectstart","select","mousedown","mouseup"],b=d.Selection,e=b&&b.prototype;e&&(e.removeAllRanges=h,b=a.selection)&&(b.clear=h);for(e=k.length;e--;)if(f=k[e]){for(b=g.length;b--;)f["on"+g[b]]=null;if(a=f.style)for(a.cursor="",a.webkitTouchCallout="initial",b=l.length;b--;)a[((c=l[b])?"-"+c+"-":c)+"user-select"]="initial"}(c=d.jQuery||d.Zepto)&&c(d).off(g)})(this);">
Enable Select
</a>
//*******************************************
// Level 1, basic API, minimum support
//*******************************************
/*
Modules IDs are strings that follow CommonJS
module names.
*/
//To load code at the top level JS file,
//or inside a module to dynamically fetch
@duzun
duzun / jq.fn.maxZIndex.js
Created November 12, 2014 09:32
Finds maximum zIndex of an element
/**
* Finds maximum zIndex of an element
*/
;(function (global) {
var $ = global.jQuery || global.Zepto;
var maxZIndex = function maxZIndex(el,min) {
var el = this
, zIdx = el.css('zIndex')
@duzun
duzun / jq.fn.outerHTML.js
Created November 12, 2014 09:25
Gets outerHTML of an element
/**
* Gets outerHTML of an element
*/
;(function (global) {
var $ = global.jQuery || global.Zepto;
$.fn.outerHTML = function fouterHTML() {
$t = $(this);
if ('outerHTML' in $t[0]) {
@duzun
duzun / jq.fn.counto.js
Created November 12, 2014 09:11
Nice count to number
/// Nice count to number (by DUzun)
;(function (global, FUNCTION, Number) {
var $ = global.jQuery || global.Zepto;
$.fn.counto = function fcounto(nr,dl,done) {
if(!dl) dl = 400;
var start = $.now(),
end = start + dl,
delay = 10,
@duzun
duzun / jq.fn.disEnAble.js
Last active August 29, 2015 14:09
A small jQuery plugin to enable/disable any form element, and any generic element (with 'disabled' class)
/**
* A small jQuery plugin to enable/disable any form element,
* and any generic element (with 'disabled' class)
*/
;(function (global) {
var $ = global.jQuery || global.Zepto;
$.fn.enable = function (cls) {
var prp = 'disabled';
@duzun
duzun / url.js
Last active February 7, 2020 11:22
In Browser URL parser
/**
* Parse URLs in a Browser environment.
*
* Ussage:
* 1) var hostname = $url('https://duzun.me/playground', 'hostname');
*
* 2) var a = $url('https://duzun.me/playground?some=param');
* a.protocol = 'http:';
* var hrefSecured = a.href;
*/