Skip to content

Instantly share code, notes, and snippets.

View GuilhermeRossato's full-sized avatar
💼
“What I cannot build, I do not understand” - Richard Feynman

Guilherme Rossato GuilhermeRossato

💼
“What I cannot build, I do not understand” - Richard Feynman
View GitHub Profile
@GuilhermeRossato
GuilhermeRossato / parseDate.js
Last active January 21, 2018 23:54
JS - Guess what a "date" string format was and put that information in a object
/*
* parameter: a string with a possible date
* returns: false if it can't decode, otherwise an object like the following:
* {type, hour, minute, second, year, month, day}
* 'type' is the numeric index of the format that the string was guessed from.
*/
function parseDate(v) {
/*
* Every one of those options belo is a valid entry for the 'v' argument
* If some information is missing, it usually is replaced by current date info
@GuilhermeRossato
GuilhermeRossato / rec_search_file.php
Last active March 27, 2018 15:33
Search files recursively for a given extension in PHP
<?php
function search_recursively_for_extension($directory, &$array, $extension=".dat") {
//global $debug;
if (substr($directory, -1) === "/" || substr($directory, -1) === "\\") {
$directory = substr($directory, strlen($directory)-1);
}
$nodes = scandir($directory);
//$debug .= ("Reading Directory: ".$directory."\n").(($nodes === false || $nodes === NULL)?("false, ".(file_exists($directory)?"it does exist":"it doesn't even exist")."\n"):(var_export($nodes, true)."\n"));
if (is_array($nodes)) {
foreach ($nodes as $node) {
@GuilhermeRossato
GuilhermeRossato / recursive_list_files.c
Last active December 6, 2017 03:16
C - Get all files and their last modified date recursively
// A c program to search all files recursively from the executable's path and retrieve its relative filename and last modified date.
// Similar to 'ls' command on linux
/* Sample output:
This directory tree has 3 files:
2017-12-05 23:55:39 ./src/recursive_file_list.c
2017-12-05 23:52:17 ./recursive_file_list.exe
2017-12-05 23:51:17 ./tools/windows/compile.bat
*/
@GuilhermeRossato
GuilhermeRossato / minifyStyle.js
Last active September 21, 2017 19:53
Minify inner CSS string
/*
* Applicable to strings which would go inside a style property of an element, like so:
* element.setAttribute("style",minifyStyle(`margin : 0px 5px 4px 10px;`)); // This would remove 4 unnecessary spaces from the string
*/
const minifyStyle = (s, mode=0) => s.replace(/(\r\n|\t|\n|\r)/gm,"").split('').filter((char, index) => (((((mode == 1)&&(mode = 2))||true)&&(((char == ':')&&(mode = 1))||true)&&(char == ';')&&(mode = 0)||true)&&mode == 0)?(char !== ' '):((mode == 2)?((mode = 3)&&(char != ' ')):true)).join('');
minifyStyle(`margin-top: 5px;
margin: 5px 5px 5px 6px;
background-image: url(...) center center no-repeat;