Skip to content

Instantly share code, notes, and snippets.

View thomedes's full-sized avatar

Toni Homedes i Saun thomedes

  • Tarragona, Spain
View GitHub Profile
@thomedes
thomedes / is_assoc_array.php
Last active December 19, 2015 19:48
php: Check if an array is associative or plain
<? php
function is_assoc_array($a) {
return (is_array($a)
&& (array_keys($a) !== range(0, count($a) - 1)));
}
function is_plain_array($a) {
return is_array($a) && !is_assoc_array($a);
}
@thomedes
thomedes / Windows-UTC-Time.reg
Created July 28, 2013 07:14
Windows 7 hack to have BIOS clock (RTC) in UTC. Useful for dual-booting Windows / Linux. Don't give me any credit for it. I just googled for the solution and pasted it here for my own convenience.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
"RealTimeIsUniversal"=dword:00000001
@thomedes
thomedes / README.md
Last active November 6, 2019 23:12
Full system backup excludes
@thomedes
thomedes / ini.sed
Last active August 17, 2023 20:41
sed one-liners to deal with .ini / .conf files
# List all [sections] of a .INI file
sed -n 's/^[ \t]*\[\(.*\)\].*/\1/p'
# Read KEY from [SECTION]
sed -n '/^[ \t]*\[SECTION\]/,/\[/s/^[ \t]*KEY[ \t]*=[ \t]*//p'
# Read all values from SECTION in a clean KEY=VALUE form
@thomedes
thomedes / README.md
Last active June 29, 2021 16:20
Compare string versions in bash

version_cmp()

Simple function to (properly) compare version strings in bash

The problem

You can not do alphabetic comparison:

@thomedes
thomedes / ini.sed
Last active December 21, 2015 06:08
sed one-liners to deal with .ini / .conf files
#
# Get all sections from .INI file
#
sed -n 's/^[ \t]*\[\(.*\)\].*/\1/p' /etc/samba/smb.conf
#
# Get all values of given section in a clean key=value form
#
section=global; sed -n '/^[ \t]*\['"$section"'\]/,/^[ \]t*\[/s/^[ \t]*\([^;#\[][^ \t]*\)[ \t]*=[ \t]*\(.*\)/\1=\2/p' /etc/samba/smb.conf
#
# Get a specific value for a given key and section
@thomedes
thomedes / cif.sql
Last active January 3, 2016 00:19
Calculo de la letra del DNI con MySQL
DELIMITER $$
DROP FUNCTION IF EXISTS `cif_letra` $$
CREATE FUNCTION `cif_letra` (`p_cif` INT UNSIGNED) RETURNS CHAR(1)
-- ----------------------------------------------------------------------------
-- Calcula la letra que corresponde al núm. de CIF dado
-- ----------------------------------------------------------------------------
DETERMINISTIC
NO SQL
@thomedes
thomedes / print_r.js
Last active August 29, 2015 13:57
Javascript PHP's print_r()
//-----------------------------------------------------------------------------
//
// print_r(expression[, _return = false ])
//
// PHP's print_r() implemented in javascript
//
// Usage:
// alert(print_r([111, {a: 33, b: 44}], true))
//
// if _return is true will return string
@thomedes
thomedes / browser-x-load.js
Last active August 29, 2015 13:57
Load any file in the browser
///////////////////////////////////////////////////////////////////////////////
//
// browser_x_loader(tag_name, element_type, callbak[, end_callback])
//
// Load files in the browser
//
// Usage:
//
// <script type="text/x-toni-template" src="tmpl/default.tmpl"></script>
// <script type="text/x-toni-template" src="tmpl/login.tmpl"></script>
@thomedes
thomedes / figlet_demo.sh
Created February 15, 2017 12:38 — forked from pestilence669/figlet_demo.sh
Show a message using all available fonts for figlet
#!/bin/bash
# vim: set ts=4 sw=4 noet fileencoding=utf-8:
fontDir=`figlet -I2`
if [[ $# -eq 0 ]]; then
echo "usage: $(basename $0) [message] -- print given message for every available font in figlet"
exit 0
fi