This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- drop function if exists base64_encode; | |
create function base64_encode(_data blob) | |
returns text | |
begin | |
declare _alphabet char(64) default 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | |
declare _lim int unsigned default length(_data); | |
declare _i int unsigned default 0; | |
declare _chk3 char(6) default ''; | |
declare _chk3int int default 0; | |
declare _enc text default ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validateLuhn(value) { | |
if (!/^\d+$/.test(value)) | |
return false; | |
value = (value + '').split('').reverse(); | |
var sum = 0, d, i; | |
for (i = 0; i < value.length; i++) { | |
d = +value[i]; | |
if (i % 2) { | |
d = (d *= 2) > 9 ? d - 9 : d; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IAB1 | Arts & Entertainment | |
---|---|---|
IAB1-1 | Books & Literature | |
IAB1-2 | Celebrity Fan/Gossip | |
IAB1-3 | Fine Art | |
IAB1-4 | Humor | |
IAB1-5 | Movies | |
IAB1-6 | Music | |
IAB1-7 | Television | |
IAB2 | Automotive | |
IAB2-1 | Auto Parts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create function find_in_set_delim(_item text, _set longtext, _delim varchar(4)) | |
returns boolean deterministic | |
return locate(concat(_delim, _item, _delim), concat(_delim, _set, _delim)) > 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create function geo_distance(_lat1 double, _lng1 double, _lat2 double, _lng2 double) | |
returns int deterministic | |
comment "Returns distance in meters" | |
return 12756274 * asin(sqrt( -- 2 * R; R = 6378137 m | |
0.5 - cos((_lat2 - _lat1) * 0.017453292519943295) / 2 -- 0.017453292519943295 = Math.PI / 180 | |
+ cos(_lat1 * 0.017453292519943295) * cos(_lat2 * 0.017453292519943295) | |
* (1 - cos((_lng2 - _lng1) * 0.017453292519943295)) / 2 | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomString(len) { | |
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
var res = ''; | |
while (len-- > 0) { | |
res += chars[Math.round(Math.random() * chars.length) % chars.length]; | |
} | |
return res; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- drop function if exists createTableLog; | |
create function createTableLog(tableName varchar(128), logDatabaseName varchar(128), logTableName varchar(128)) | |
returns text | |
begin | |
set logDatabaseName := if(logDatabaseName != '', logDatabaseName, database()); | |
select | |
concat('`', group_concat(column_name separator '`, `'), '`'), | |
concat('NEW.`', group_concat(column_name separator '`, NEW.`'), '`'), | |
concat('OLD.`', group_concat(column_name separator '`, OLD.`'), '`') | |
into @names, @newNames, @oldNames |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.enableChaining = function (obj) { | |
if (!obj || typeof obj !== 'object') | |
throw new TypeError("Argument obj is not an Object"); | |
var names = {}; | |
var protos = []; | |
var cur = obj; | |
var descr; | |
while (cur && protos.indexOf(cur) < 0) { | |
descr = Object.getOwnPropertyDescriptors(cur); | |
for (var k in descr) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var generateSvgAvatar = (function () { | |
return function (seed, raw) { | |
var rands = hash320('' + seed); | |
var randsHex = rands.map(function (v) { | |
return ('00' + v.toString(16)).slice(-2); | |
}).join(''); | |
rands = rands.concat(rands); | |
var globalRotation = 360 * rands[rands[0] % 20] / 0xff; | |
var particles = []; | |
var n = 20; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // I don't know why anybody may need it | |
class Promise { | |
protected $resolvers = []; | |
protected $catchers = []; | |
protected $value = null; | |
protected $error = null; | |
protected $status = 'idle'; | |
public function __construct($run, $manualStart = false) { |
OlderNewer