This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A pure function that retrieves the day of the week of a given date. | |
* Does not check if the date exists (i.e. 2019/02/31 yields a weekday, but doesn't exists). | |
* | |
* @param {number} y The year as a number with 4 digits | |
* @param {number} m The month as a number between 0 and 11 (january to december) | |
* @param {number} d The day as a number between 0 and 31 | |
* @return {number} The number of the weekday, between 0 (monday) to 6 (sunday) | |
*/ | |
function weekdayByDate(y, m, d) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Output example at the bottom of this gist | |
*/ | |
function get_formatted_debug_backtrace() { | |
$content = debug_backtrace(); | |
$ret = []; | |
foreach($file_paths AS $file_path) { | |
$var = $file_path; | |
$ret[] = "File: ".$var['file'].": ".$var['line']."\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Credits: | |
// Windows Capture and Save: Michael Ftsch | |
// Linux Capture and Save: None | |
// | |
#ifdef _WIN32 | |
#include <windows.h> | |
inline int GetFilePointer(HANDLE FileHandle) { | |
return SetFilePointer(FileHandle, 0, 0, FILE_CURRENT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class OrderedList: | |
"""A self organizing list of (key, object) pairs ordering by the key""" | |
def __init__(self): | |
self.data = [] | |
self.tests = 0 | |
def __len__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$error_was_already_triggered = false; | |
function process_error_handler($errno, $errstr, $errfile, $errline) { | |
global $error_was_already_triggered; | |
$error_is_marked_as_ignored = (error_reporting() == 0); | |
if ($error_is_marked_as_ignored || $error_was_already_triggered) { | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Description: | |
* C program for windowsto write to a file in 4096-byte blocks to a new file until it reaches 16777216 bytes (16MB) | |
* | |
* Supported OS: | |
* Windows and Linux | |
* | |
* Recomendations: | |
* Disable linux disk cache: | |
* sudo /sbin/sysctl -w vm.drop_caches=3 |
OlderNewer