Skip to content

Instantly share code, notes, and snippets.

View apisurfer's full-sized avatar
🚴

Luka Vidaković apisurfer

🚴
View GitHub Profile
@apisurfer
apisurfer / bf.c
Created June 25, 2013 15:05
Simple brute force for string matching in C
/**
This is a simple proof of concept of a brute force algorithm for string matching with
given set of characters.
The way this works is that the algorithm counts from first to last possible combination of
given characters. Instead of counting(incrementing) in number base 10 we use
a new base which is derived from your set of possible characters (we count in symbols).
So if your characters list contains 27 characters the program actually counts in a 27 base
number system.
Author: Luka Vidaković
@apisurfer
apisurfer / bf.php
Created June 25, 2013 15:06
Simple brute force or string matching in PHP
<?php
/**
This is a simple proof of concept of a brute force algorithm for string matching with
given set of characters.
The way this works is that the algorithm counts from first to last possible combination of
given characters. Instead of counting(incrementing) in number base 10 we use
a new base which is derived from your set of possible characters (we count in symbols).
So if your characters list contains 27 characters the program actually counts in a 27 base
number system.
// As heard on "Chroma Zone" talk by Lea Verou
// Explanation @ http://www.w3.org/TR/2014/NOTE-WCAG20-TECHS-20140311/G18
// @color - [r,g,b]
function luminance (color) {
var rgb = color.map(function(c){
c /= 255; // to 0-1 range
return c < .03928 ?
c / 12.92 :
Math.pow((c+.055)/1.055, 2.4);
@apisurfer
apisurfer / bf2.php
Created March 12, 2015 16:17
Simple hack based on previous script that allows setting the starting string. It's also quite likely not the ideal and fastest solution
// Set max string length and charset for generating combinations
$maxLength = 3;
$charSet = 'abcdph';
$size = strlen($charSet);
function initBase ($init, $set) {
$initBase = str_split(strrev($init));
$positions = array();
foreach ($initBase as $letter) {
if ( strpos($set, $letter ) === false) {
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
@apisurfer
apisurfer / try-catch-wrap.js
Created June 4, 2015 15:18
Unify catching of exception
// dependencies: underscore beceause of "_.each, _.keys" could be Array.forEach etc.
/**
* Wrap function inside try catch; unified try/catch
* @param f {function} function to wrap
* @param info {object} information to be passed in case of failure
* @return {function} new function which contains old one engulfed inside try/catch
*/
function tryCatchWrap (f, info) {
var args = arguments;
@apisurfer
apisurfer / ajax-jquery-lambda.js
Created July 27, 2015 13:50
Example of lambda functions usage to create flexible ajax utility module
var _ = require('lodash');
var $ = require('jquery');
var apis = {
main: '/api/v1/',
tracker: '/tracking/v1/',
};
/**
* Default data sent with every request;
@apisurfer
apisurfer / is-console-opened.js
Last active October 13, 2015 20:58
Write text line by line when user opens console
function isConsoleOpened() {
var threshold = 160;
return (window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) ||
window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold;
}
function decode(imageURL) {
"use strict"
function createShadowCanvas(width, height) {
var canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
return canvas
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Execute script from image</title>
<meta name="author" content="popc0rn - Luka Vidakovic">
</head>
<body>
<div id="x"></div>