Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Dumitru Uzun duzun

🎯
Focusing
View GitHub Profile
@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 / casign
Created Feb 24, 2020
Create a SSL certificate signed by your CA root certificate.
View casign
#!/usr/bin/env bash
##
# Sign a certificate using my root_ca.
#
# Note: duzun_root_ca.crt must be in the trusted root ca (see https://www.archlinux.org/news/ca-certificates-update/)
#
# @author Dumitru Uzun (DUzun.Me)
# @version 1.1.0
##
@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.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 / downlist
Last active Feb 7, 2020
Download media files from a m3u8 URL
View downlist
#!/bin/bash
# Download a file listed in a list file
# @author Dumitru Uzun (DUzun.Me)
# @version 1.0.1
_me_="$(basename "$0")"
_start_time_=$(date +%s)
referer=
_cat_=
@duzun
duzun / shiftsrt.js
Last active Feb 7, 2020
Shift time in .srt subtitles file
View shiftsrt.js
#!/bin/node
/*jshint esversion: 9*/
/**
* Time-shift video subtitles in a .srt file.
*
* Usage:
* shiftsrt.js seconds input_file|- [output_file|-]
*
* Examples:
@duzun
duzun / php_sess_to_redis.sh
Last active Jul 4, 2019
Bash script to import PHP session files into redis
View php_sess_to_redis.sh
#!/bin/bash
export REDISCLI_AUTH=my-supper-strong-password-4-redis-server
TTL=$(( 24 * 3600 ))
# cd "/var/sess"
for i in sess_*; do
ex=$(( $(date +%s) - $(stat -c %Y "$i") + $TTL ))
@duzun
duzun / fix_lib_links.sh
Created Dec 25, 2018
Fix /usr/lib/lib*.so links, in the case you `cp`ed lib folder from a backup (use `rsync -a`, not `cp`!)
View fix_lib_links.sh
@duzun
duzun / optimag
Last active Aug 11, 2018
Compresses images using on-line services.
View optimag
#!/bin/sh
# https://gist.github.com/duzun/234bd3ca69b243bb32bb
basedir=`dirname "$0"`
optimagurl=https://duzun.me/optimag.js
optimagjs=$basedir/optimag.js
case `uname` in
*CYGWIN*) optimagjs=`cygpath -w "$optimagjs"`;;
@duzun
duzun / cron_eye_safe.sh
Last active Aug 6, 2018
Install notifications every 20 min and 2 hours to rest your eyes - KDE on Linux
View cron_eye_safe.sh
#!/bin/sh
#
# Keep your eyes safe on cron
#
# @author Dumitru Uzun (DUzun.Me)
# @web https://gist.github.com/duzun/99bd0d1cba6c8ad1b5bf321c2689a257
#
_user=${USER:-$(whoami)}