Skip to content

Instantly share code, notes, and snippets.

@cron13
cron13 / BKDRHash.js
Created Oct 18, 2019
numeric hash from string. BKDRHash
View BKDRHash.js
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 Oct 15, 2019
parse laravel dot notation errors response
View gist:17232ba8091ba3d98efa6db76937c608
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 Aug 19, 2019
spatie/image-optimizer + spatie/laravel-glide
View glide_imageoptimizer.php
<?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;
}
View 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!");
}
You can’t perform that action at this time.