Skip to content

Instantly share code, notes, and snippets.

View ankr's full-sized avatar
🎯
Focusing

Andreas ankr

🎯
Focusing
View GitHub Profile
@ankr
ankr / Javascript_Boolean_Type_Conversion
Last active December 15, 2015 02:59
Javascript boolean type conversion. Source, Douglas Crockford.
'' == '0' // false
0 == '' // true
0 == '0' // true
false == 'false' // false
false == '0' // true
false == undefined // false
false == null // false
null == undefined // true
" \t\r\n" == 0 // true
@ankr
ankr / bitwise_examples.php
Last active December 25, 2015 05:19
I found this one the web somewhere, I have no idea where unfortunately.
<?php
/*
* Ignore the top section,
* it is just formatting to make output clearer.
*/
$format = '(%1$2d = %1$04b) = (%2$2d = %2$04b)'
. ' %3$s (%4$2d = %4$04b)' . "\n";
echo <<<EOH
@ankr
ankr / Convert_SVN_to_GIT.md
Last active December 25, 2015 16:29
Convert SVN repo to GIT repo

1. Create local SVN checkout

mkdir svn-repo
svn checkout svn://example.org svn-repo/

2. Create an authors list

Will create a list of all the contributers of the SVN repo.

@ankr
ankr / levenshtein.js
Last active December 28, 2015 06:39
Javascript implementation of "Levenshtein Distance" algorithm.
// levenshtein('boo', 'bar') => 2
var levenshtein = function (a, b, al, bl) {
var c = 1;
al = typeof al === 'undefined' ? a.length : al;
bl = typeof bl === 'undefined' ? b.length : bl;
if (!al) return bl;
if (!bl) return al;
if (a[al - 1] === b[bl - 1]) {
function greet() {
return brainfuck('[-]>[-]<>++++++++++[<++++++++++>-]<++++.---.>+++[<+++>-]<--..+++.>+++++++++[<--------->-]<++.>+++++++++[<+++++++++>-]<++++++.>+++[<--->-]<+.+++.>++[<-->-]<--.>+++[<--->-]<+.>++++++++[<-------->-]<---.');
}
function brainfuck (i) {
var d = [], o = [], p = 0, c = 0, l = i.length;
while (c !== l) {
!d[p] && (d[p] = 0);
switch (i[c]) {
case '<' : p--; break;
@ankr
ankr / calculate.js
Last active December 31, 2015 00:19
function calc(expression) {
var divmultest = /[\/\*]+/;
var divmulreplace = /(\-?[\d\.]+)\s*(\/|\*)\s*(\-?[\d\.]+)/g;
var addsubtest = /\d+\s*[\+\-]+/;
var addsubreplace = /(\-?[\d\.]+)\s*(\+|\-)\s*(\-?[\d\.]+)/g;
var parens = /\(([^\(\)]+)\)/g;
var evaluate = function (e) {
while (divmultest.test(e)) {
e = e.replace(divmulreplace, function (m, x, o, y) {
@ankr
ankr / .editorconfig
Last active December 3, 2020 12:50
Base editorconfig for new projects
# Base editorconfig for new projects
root = true
[*]
end_of_line = lf
indent_style = space
tab_width = 4
charset = utf-8
trim_trailing_whitespace = true
@ankr
ankr / debug.php
Created June 13, 2014 08:03 — forked from kimegede/debug.php
<?php
function debug($data) {
$bt = debug_backtrace();
$bt = array_shift($bt);
$data = print_r($data, true);
$html = <<<HTML
<div class="debug-output">
%s
@ankr
ankr / gist:f85bbaf5c2fc88e60470
Last active August 29, 2015 14:03
No `git add .`
git() {
if [[ $1 == 'add' ]] && [[ $2 == '.' ]]; then
echo "No no no no ... NO!!"
else
command git "$@"
fi
}

ASCII TABLE

Dec Hex Oct Binary Char Description
0000 0000 0000 00000000 NUL Null Character
0001 0001 0001 00000001 SOH Start of Header
0002 0002 0002 00000010 STX Start of Text
0003 0003 0003 00000011 ETX End of Text
0004 0004 0004 00000100 EOT End of Transmission
0005 0005 0005 00000101 ENQ Enquiry