Skip to content

Instantly share code, notes, and snippets.

View ankr's full-sized avatar
🎯
Focusing

Andreas ankr

🎯
Focusing
View GitHub Profile
@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) {
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 / 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]) {
@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 / 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 / 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