Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Dumitru Uzun duzun

🎯
Focusing
View GitHub Profile
@duzun
duzun / async_css.html
Last active Aug 29, 2015
Easiest and most natural way to load CSS asynchronously without blocking HTML rendering! Tested on https://limitlesslane.com/ https://casadelux.ru/ and other projects by DUzun.ME
View async_css.html
<html>
<head>
<!-- The <script> switches rel="prefetch" to rel="stylesheet" at proper time, et voila, magic happens :-) -->
<link rel="prefetch" type="text/css" href="https://cdn.limitlesslane.com/css/mini/async_lib.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.limitlesslane.com/css/mini/lib.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.limitlesslane.com/css/mini/app.css" />
<link rel="prefetch" type="text/css" href="https://cdn.limitlesslane.com/css/mini/async_app.css" />
<script>
;(function(w,d){
@duzun
duzun / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@duzun
duzun / isUTF8.php
Last active Mar 13, 2020
Check whether a string can be interpreted as a valid UTF-8 or if it has any non-ASCII UTF-8 bytes
View isUTF8.php
<?php
/**
* Check whether string $str can be interpreted as a valid UTF-8.
*
* @param (string) $str A string to check for UTF-8
* @param (bool) $hasNonASCII_UTF8 If true, get non-ASCII bytes count in $str.
*
* @return (bool|int) if $str is not a valid UTF-8 string -> false
* if $str is a valid UTF-8 string,
* when $hasNonASCII_UTF8 == false -> true,
@duzun
duzun / jq.fn.getAttributes.js
Last active Aug 29, 2015
jQuery.fn.getAttributes
View jq.fn.getAttributes.js
/*
source: http://stackoverflow.com/questions/2048720/get-all-attributes-from-a-html-element-with-javascript-jquery/16935800#16935800
*/
(function($) {
$.fn.getAttributes = function () {
var elem = this,
attr = {};
if(elem && elem.length) $.each(elem.get(0).attributes, function(v,n) {
n = n.nodeName||n.name;
@duzun
duzun / jq.fn.findAll.js
Last active Aug 29, 2015
findAll() jQuery plugin - a combination of filter, closest and find in one call
View jq.fn.findAll.js
/**
* Find selector in this and descendants of this.
* if up == true, search parents as well.
*
*/
;(function (global) {
var $ = global.jQuery || global.Zepto;
$.fn.findAll = function findAll(selector, up) {
@duzun
duzun / jq.fn.$each.js
Last active Aug 29, 2015
4-10 times faster jQuery.fn.each() replacement
View jq.fn.$each.js
/**
* 4-10 times faster .each replacement
* use it carefully, as it overrides jQuery context of element on each iteration
*
* function clb(DOM, idx, $DOM, DOM) {};
* $DOM == $(DOM), is the same object throughout iteration
*
*/
;(function (global) {
@duzun
duzun / url.js
Last active Feb 7, 2020
In Browser URL parser
View url.js
/**
* 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;
*/
@duzun
duzun / jq.fn.disEnAble.js
Last active Aug 29, 2015
A small jQuery plugin to enable/disable any form element, and any generic element (with 'disabled' class)
View jq.fn.disEnAble.js
/**
* 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 / jq.fn.counto.js
Created Nov 12, 2014
Nice count to number
View jq.fn.counto.js
/// 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.outerHTML.js
Created Nov 12, 2014
Gets outerHTML of an element
View jq.fn.outerHTML.js
/**
* Gets outerHTML of an element
*/
;(function (global) {
var $ = global.jQuery || global.Zepto;
$.fn.outerHTML = function fouterHTML() {
$t = $(this);
if ('outerHTML' in $t[0]) {