Skip to content

Instantly share code, notes, and snippets.

@KLicheR
KLicheR / csmap.bash
Created April 10, 2017 20:50
Generate a SHA256 checksum map of a directory and allow to compare it with another directory
#!/bin/bash
version="1.0.0"
print_help() {
echo "Usage: csmap [dir]"
echo ""
echo "This command generated a \"csmap.txt\" file containing a SHA256 checksum of"
echo "each file of a directory recursively. If a \"csmap.txt\" file exists,"
echo "it generates a temporary \"csmap.compare.txt\" file, do the mapping and"
echo "compare it with the \"csmap.txt\" file."
@KLicheR
KLicheR / hg_diff_to_zip.sh
Created June 11, 2014 21:24
Get mercurial lastest modified files and put them in a zip
hg st --rev TAG --rev default -n | xargs zip to_push.zip
@KLicheR
KLicheR / regex.md
Created August 15, 2013 19:09
Snippets for common tasks to do with regex.

Tested with Sublime Text 2

All but this

\n\s*<category domain="((?!post_tag).)*" nicename=".*">.*</category>

An entire XML/HTML tag - Multiline

\n\s*((?!)[\s\S])*

@KLicheR
KLicheR / getTime.php
Last active December 17, 2015 15:19
Get different time properties for a certain amount of seconds and help to format these properties like the PHP "date" function.
<?php
class TotalTime
{
public function __construct($seconds)
{
$this->total_seconds = (int) $seconds;
$this->_getTime();
}
/**
@KLicheR
KLicheR / toUTCWeekMilliseconds.js
Last active December 17, 2015 10:28
Get time components.
/**
* Get the number of milliseconds since Sunday at 00:00:00 [UTC].
*/
Date.prototype.toUTCWeekMilliseconds = function() {
return (this.getUTCDay()*24*60*60*1000) // Days
+ (this.getUTCHours()*60*60*1000) // Hours
+ (this.getUTCMinutes()*60*1000) // Minutes
+ (this.getUTCSeconds()*1000) // Seconds
+ this.getUTCMilliseconds(); // Milliseconds
}
@KLicheR
KLicheR / addLeadingZero.js
Created May 16, 2013 19:57
Function to add leading zero to a int.
function addLeadingZero(value) {
if (value < 10 && value >= 0) {
return('0'+value);
}
else if (value < 0 && value > -10) {
return('-0'+Math.abs(value));
}
return value;
}
@KLicheR
KLicheR / bash_profile
Created March 27, 2013 14:11
bash_profile file inspired by the one found in the DrupalPro project.
alias ll='ls -la'
# search in files and directories
search () { grep -rHinC0 "$*" .; }
# DEFINE COLORS
# MAKES IT EASIER TO CHANGE SHELL COLORS
# Reset
Color_Off="\[\033[0m\]" # Text Reset
@KLicheR
KLicheR / sessauth.pl
Last active December 11, 2015 20:49
Perl script wrote by Dameon D. Welch (PhoneBoy, http://phoneboy.com/) in 1998 describe as this: "A non-graphical Session Authentication Agent for FireWall-1 3.x"
#!/usr/bin/perl
# sessauth.pl: A non-graphical Session Authentication Agent for
# FireWall-1 3.x
#
# Author: Dameon D. Welch ([email protected])
# Version: 1.0
# Date: 12 August 1998
#
# This program is designed to listen on port 261 for session authentication
@KLicheR
KLicheR / db-far.php
Last active August 23, 2023 23:04
PHP script that perform a find and replace in a database dump (tested with MySQL) with adjustments of the PHP serialize founded.
#!/usr/bin/php
<?php
/**
* PHP script that perform a find and replace in a database dump (tested with
* MySQL) with adjustments of the PHP serialize founded.
*
* Don't forget to escape your "special characters":
* "a$b" -> "a\$b"
* "a"b" -> "a\"b"
* "a`b" -> "a\`b"