Skip to content

Instantly share code, notes, and snippets.

@NaWer
NaWer / daemon.py
Created October 8, 2019 19:22 — forked from dtuominen/daemon.py
'''
***
Modified generic daemon class
***
Author: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
www.boxedice.com
License: http://creativecommons.org/licenses/by-sa/3.0/
@NaWer
NaWer / commands.md
Last active February 26, 2018 09:12
Ubuntu 16.04 - grub & busybox restoration

Grub

Conversion qwerty azerty

( 9
) 0
--- ---
/ !
--- ---
@NaWer
NaWer / delete_duplicate.sql
Created September 2, 2014 12:35
Delete duplicate row on a MySQL table
# Source : http://stackoverflow.com/questions/3311903/remove-duplicate-rows-in-mysql
ALTER IGNORE TABLE my_table_name ADD UNIQUE INDEX my_index_name (my_column_1, my_column_2, my_column_3, ... );
@NaWer
NaWer / BIG_SEC_TO_TIME.sql
Last active February 8, 2023 08:49
SEC_TO_TIME and TIME_TO_SEC is constrained to the range of the TIME data type (-838:59:59 to 838:59:59). This MySQL function overtakes this limit.
DROP FUNCTION IF EXISTS BIG_SEC_TO_TIME;
DELIMITER $$
CREATE FUNCTION BIG_SEC_TO_TIME(SECS BIGINT)
RETURNS TEXT
READS SQL DATA
DETERMINISTIC
BEGIN
DECLARE HEURES TEXT;
DECLARE MINUTES CHAR(5);
DECLARE SECONDES CHAR(5);
@NaWer
NaWer / duration8601.php
Last active April 7, 2022 13:58
Convert duration in second to duration in ISO8601
<?php
/*
* Convert duration in second to duration in ISO8601
* http://www.w3schools.com/Schema/schema_dtypes_date.asp#Duration Data Type
* http://en.wikipedia.org/wiki/ISO_8601#Durations
*
* @param integer $duration in second seconde
* @return string duration in ISO8601
*
* >= PHP 5.3 : use DateInterval <http://www.php.net/manual/en/dateinterval.construct.php>
@NaWer
NaWer / getAttribute.php
Last active December 31, 2015 14:49
Get the Value of Attributes in HTML tags using PHP
<?php
/*
* Return the value of an attribute in HTML tag
*/
function getAttribute($attrib, $tag)
{
$re = '/' . preg_quote($attrib) . '=([\'"])?((?(1).+?|[^\s>]+))(?(1)\1)/is';
if (preg_match($re, $tag, $match))
return urldecode($match[2]);
return false;
@NaWer
NaWer / lettersToDigits.js
Last active December 27, 2015 13:59
Convert letters to digits using "old" phone keybord
var _in = 'erwan123';
var _out = [];
var map = ['0 ','1','2abc','3def','4ghi','5jkl','6mno','7pqrs','8tuv','9wxyz'];
for(var i = 0; i < _in.length; i++)
{
for (var j = 0; j < map.length; j++)
{
if (map[j] && map[j].indexOf(_in[i]) > -1)
{
@NaWer
NaWer / lolcat.rb
Created October 30, 2012 08:57
Fetch a random lolcat url.
require 'open-uri'
def random_lolcat
open("http://icanhascheezburger.com/?random").read.match(/"http:\/\/icanhascheezburger\.files\.wordpress\.com\/[^"]+/)[0][1..-1]
end