Skip to content

Instantly share code, notes, and snippets.

View Zegnat's full-sized avatar

Martijn van der Ven Zegnat

View GitHub Profile
@Zegnat
Zegnat / fote.svg
Last active December 17, 2015 12:19
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Zegnat
Zegnat / Bcrypt.php
Last active December 19, 2015 09:49
Simple PHP 5.3+ Bcrypt class
<?php
/*
Originally by Marco Arment <me@marco.org>.
Edited by Martijn van der Ven <martijn@zegnat.net>.
This code is released in the public domain.
THERE IS ABSOLUTELY NO WARRANTY.
This class is aimed at PHP versions over 5.3 and below 5.5.
@Zegnat
Zegnat / slow_compare.php
Created July 5, 2013 19:43
For secure and slow string comparisons. This helps against timing attacks on secret strings.
<?php
function slow_compare($str1, $str2, $length = null) {
$out = ($str1_len = strlen($str1 .= chr(0))) - ($str2_len = strlen($str2 .= chr(0)));
if (!is_int($length)) $length = $str1_len;
for ($i = 0; $i < $length; $i++)
$out |= ord($str1[$i % $str1_len]) ^ ord($str2[$i % $str2_len]);
return 0 === $out;
}
@Zegnat
Zegnat / gaunt.js
Last active December 20, 2015 20:39
A Gaunt <http://tinysubversions.com/gaunt/> parser in JavaScript passing JavaScript Lint, JSLint, and JSHint. No regular expression, only one ternary operator, loads of string manipulation.
var gaunt = function (data) {
'use strict';
var input = String(data), map = {9: '0', 32: '1'}, result = '', output = '', i, j;
for (i = 0, j = input.length; i < j; i += 1) {
result += map[input.charCodeAt(i)] || '';
}
for (i = 0, j = result.length; i < j; i += 8) {
output += String.fromCharCode(parseInt(result.substr(i, 8), 2));
}
return output;
@Zegnat
Zegnat / kick-it.html
Last active December 21, 2015 16:28 — forked from 4rn0/kick-it.html
<a href="http://causeyoucantyouwontandyoudontstop.com/" class="kick-it">Kick it!</a>
@Zegnat
Zegnat / .htaccess
Last active April 5, 2017 00:34
This emulates https://github.com/lazd/mdn.io/ in a 2 line .htaccess file. Compatible with any Apache server with mod_alias enabled.
RedirectMatch 303 /(.+)$ https://duckduckgo.com/?q=!+site:developer.mozilla.org+$1
Redirect 303 / https://developer.mozilla.org/en-US/docs/JavaScript
/**
* Create an array containing every possible way to write a given string in mixed-case.
*
* @param {String} str - A string to find every case-combination for.
* @return {Array} Every possible case-combination.
*/
function mixedCase(str) {
'use strict';
str = str.toLowerCase();
var length = str.length,
@Zegnat
Zegnat / zegnat.sugar.js
Created January 23, 2014 10:31
Some extensions to Sugar.
Number.extend({
'sign': function() {
// http://stackoverflow.com/a/21294663/3225372
return typeof this === 'number' ? this ? this < 0 ? -1 : 1 : this === this ? this : NaN : NaN;
},
'isPositive': function() {
return this.sign() === 1;
},
'isNegative': function() {
return this.sign() === -1;
@Zegnat
Zegnat / gist:9482902
Created March 11, 2014 10:11
Blocklist (Adblock Plus filter syntax)
! http://blog.ghost.org/viewcounter/
*/view.gif?page=/*$image
* {
box-sizing: inherit;
overflow: inherit;
}
html {
box-sizing: border-box;
overflow: auto;
}