Skip to content

Instantly share code, notes, and snippets.

@cron13
cron13 / BKDRHash.js
Created October 18, 2019 09:32
numeric hash from string. BKDRHash
var BKDRHash = function(str) {
var seed = 131;
var seed2 = 137;
var hash = 0;
// make hash more sensitive for short string like 'a', 'b', 'c'
str += 'x';
// Note: Number.MAX_SAFE_INTEGER equals 9007199254740991
var MAX_SAFE_INTEGER = parseInt(9007199254740991 / seed2);
for(var i = 0; i < str.length; i++) {
if(hash > MAX_SAFE_INTEGER) {
@cron13
cron13 / gist:17232ba8091ba3d98efa6db76937c608
Created October 15, 2019 08:13
parse laravel dot notation errors response
computed: {
parsedErrors() {
const parseDotNotation = function(str, val, obj) {
let currentObj = obj,
keys = str.split('.'),
i, l = Math.max(1, keys.length - 1),
key
for (i = 0; i < l; ++i) {
key = keys[i]
@cron13
cron13 / glide_imageoptimizer.php
Last active August 19, 2019 13:06
spatie/image-optimizer + spatie/laravel-glide
<?php
class Awesome extends League\Flysystem\Adapter\Local {
public function write($path, $contents, League\Flysystem\Config $config) {
$location = $this->applyPathPrefix($path);
$this->ensureDirectory(dirname($location));
if (($size = file_put_contents($location, $contents, $this->writeFlags)) === false) {
return false;
}
@cron13
cron13 / m.js
Created December 14, 2017 11:14 — forked from cazala/m.js
var libUrl = null;
var scriptTag = Array.prototype.slice
.call(document.getElementsByTagName("script"))
.filter(x => /\?proxy?/.test(x.src));
if (scriptTag.length > 0) {
libUrl = scriptTag[0].src.split("m.js")[0];
} else {
throw new Error("missing '?proxy' query parameter in your proxy url!");
}