Skip to content

Instantly share code, notes, and snippets.

View DBJDBJ's full-sized avatar
😬
Can't stop coding

dbj DBJDBJ

😬
Can't stop coding
View GitHub Profile
@DBJDBJ
DBJDBJ / cross_browser_cross_javascript_string_trim.js
Created March 11, 2010 14:40
Use native String.prototype.trim function wherever possible. Do not use String.trim. It is not part of ES5. Browsers are not required to implement it.
// dbjdbj@gmail.com
// Inspired also by http://github.com/dieseltravis
(function () {
var trimLeft = /^\s+/, trimRight = /\s+$/;
// Verify that \s matches non-breaking spaces (IE fails on this test)
if ( !/\s/.test( "\xA0" ) ) {
trimLeft = /^[\s\xA0]+/;
trimRight = /[\s\xA0]+$/;
}
// Use native String.prototype.trim function wherever possible
@DBJDBJ
DBJDBJ / dbj.isfunction.js
Created August 2, 2011 21:46
DBJ isFunction()
/*
(c) 2009 - 2011 by dbj.org
*/
var isFunction = (function() {
var rx = /^\s*\bfunction\b/;
return function(f) {
return rx.test(f);
}
}());
/*
@DBJDBJ
DBJDBJ / gist:4289825
Created December 15, 2012 00:12
My 2009 R+D on DOM page changes and "Mutation Events". Tested on Chrome only. And perhaps in IE too ;)
<!DOCTYPE html >
<!-- $Revision: 1 $ $Date: 22/12/09 17:10 $ $Author: Admin $ -->
<html>
<head>
<!-- Set document compatibility mode to IE8Mode -->
<!-- meta http-equiv="X-UA-Compatible" content="IE=edge" / -->
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js" onload="alert('Firebug Lite Loaded')"></script>
<title>dbj*Mutator $Revision: 1 $ $JustDate: 22/12/09 $</title>
<style type="text/css">
#pragma once
/*
Copyright 2006 - 2018 dbj@dbj.org
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http ://www.apache.org/licenses/LICENSE-2.0
@DBJDBJ
DBJDBJ / dbj.microlib.min.js
Created March 18, 2016 08:17
dbj MICROLIB minified
if("object"==typeof dbj){var msg="dbj core object must be defined only once and only in here";throw console&&console.error&&console.error(msg),"function"==typeof alert&&alert(msg),msg}!function(r,t){"function"!=typeof String.format&&(String.prototype.format=function(){var r=arguments;return this.replace(/\{(\d|\d\d)\}/g,function(e){var n=1*e.match(/\d+/)[0];return r[n]!==t?r[n]:""===r[n]?"":e})});var e={GLOBAL:function(){var t=Object.prototype.toString;Object.prototype.hasOwnProperty;"function"!=typeof window.roleof&&(r.roleof=function(r){return t.call(r).match(/\w+/g)[1]}),"function"!=typeof window.isArray&&(r.isArray=function(r){return"Array"===roleof(r)}),"function"!=typeof window.isObject&&(r.isObject=function(r){return"Object"===roleof(r)}),"function"!=typeof window.isFunction&&(r.isObject=function(r){return"Function"===roleof(r)})}(),keep_inside:function(){var r=[0,1];return function(t,e){if(e&&(r=e.sort()),t-=0,isNaN(t))throw new Error(255,"dbj.keep_inside() received NaN value.");return t>r[1]?r[1]:t<r
@DBJDBJ
DBJDBJ / dbjtree.h
Last active August 29, 2017 15:21
Binary Tree made more useful, the easy and quick way thanks to modern C++ (c) 2017 by dbj@dbj.org
// IDE ONE link: https://ideone.com/X30oXu
#pragma once
#include <iostream>
using std::wostream;
namespace dbj {
namespace tree {
using namespace std;
@DBJDBJ
DBJDBJ / dbj_win_unicode_console_config.h
Last active April 16, 2017 11:31
C++ WINDOWS UNICODE CONSOLE OUTPUT
#pragma once
/*
----------------------------------------------------------------------
ACTUALLY:
http://archives.miloush.net/michkap/archive/2008/03/18/8306597.html
It seems this is very wizard like method?
Try this simeple test and see if it crashes your console:
<pre>
#include <fcntl.h>
#include <io.h>
@DBJDBJ
DBJDBJ / convincing_MSVC_that_argv_is_an_array.cpp
Last active May 28, 2018 09:38
Convincing MSVC that argv is an array (which it is not)
#include <iostreams>
// above should be enough
// dbjdbj 23 MAY 18 added
// this is VS2017 code
// linux twin is here
// https://wandbox.org/permlink/Wm3rtZhT3jCNfSXl
/// and behaves a bit better as in it manages to
// print the ARP value (see way bellow)
@DBJDBJ
DBJDBJ / linux_demangler_for_clang_and_gcc.h
Last active August 6, 2021 08:07
C++ linux demangler for clang ang gcc
/*
(c) 2018-2021 by dbj@dbj.org -- https://dbj.org/license_dbj
usage:
auto demangled_name = dbj::demang< int (&) [42] >() ;
This is both windows and linux code.
https://godbolt.org/z/7bTxazhTv
*/
#ifndef _WIN32
@DBJDBJ
DBJDBJ / dbj_swappable_engines.h
Created June 6, 2018 20:52
Swappable Engine Factory, I think a better variation to the Factory Pattern
#pragma once
/*
Swappable Engine Factory, I think a better variation to the
Factory Pattern
Usage:
using namespace car_factory;
auto car_1 =