Skip to content

Instantly share code, notes, and snippets.

View SparK-Cruz's full-sized avatar

Cruz SparK-Cruz

  • Brasil
View GitHub Profile
@SparK-Cruz
SparK-Cruz / locale.js
Created February 4, 2020 21:06
Locale detector and organizer for using with i18n property of vue root object using the vue-i18n plugin
import en from './en';
import pt from './pt';
import es from './es';
const Locale = {
sharedMessages: {
en,
pt,
es
}
@SparK-Cruz
SparK-Cruz / c13date.js
Last active April 17, 2021 22:13
C13Date Object
const monthNames = [
'Capricornus',
'Aquarius',
'Pisces',
'Aries',
'Taurus',
'Gemini',
'Cancer',
'Leo',
'Virgo',
@SparK-Cruz
SparK-Cruz / chain.js
Created November 28, 2020 19:45
Allows you to chain calls for void methods in third party objects
exports.chain = function (subject) {
const proxy = new Proxy(subject, {
get(target, name, receiver) {
const member = Reflect.get(target, name, receiver);
if (typeof member === 'function') {
return function () {
const value = member.apply(subject, arguments);
if (typeof value !== 'undefined')
return value;
@SparK-Cruz
SparK-Cruz / atena.js
Created January 21, 2021 02:02
Yet another browser AJAX lib
(function () {
function prmze() {
let thenCallback = null;
let catchCallback = null;
let child = null;
return {
ready: false,
then: function (callback) {
this.ready = true;
@SparK-Cruz
SparK-Cruz / otp.js
Last active March 5, 2021 01:42
Lib/function for One Time Padding strings
(() => {
const OTP = (() => {
function xorStrings(a, b) {
let c = "";
for (let i = 0; i < a.length; i++)
c += String.fromCharCode(a.charCodeAt(i) ^ b.charCodeAt(i));
return c;
}
@SparK-Cruz
SparK-Cruz / rng.ts
Created March 9, 2021 12:45
Seedable Pseudo-Random Number Generator for TypeScript
export namespace RNG {
let seq = 1;
export function random(seed ?:number) {
if (typeof seed != 'undefined') {
seq = seed;
}
let x = Math.sin(seq++) * 10000;
return x - Math.floor(x);
}
}
@SparK-Cruz
SparK-Cruz / scope.js
Last active July 26, 2022 14:14
Deferrence in JavaScript
(function(){
module.exports = function scope(block) {
const deferred = [];
const defer = function(callback, args) {
deferred.unshift({target: this, callback, args});
}
try {
return block(defer);
} finally {
@SparK-Cruz
SparK-Cruz / index.js
Created July 14, 2021 12:56
Most Visited Sequence
const SEPARATOR = ':::';
module.exports = (function() {
const cls = function() {
this.userVisits = {};
};
const parseSequences = function(userVisits, length) {
const sequences = {};
const size = length - 1;
@SparK-Cruz
SparK-Cruz / array_delete.php
Created September 3, 2021 19:08
Ruby's array#delete for PHP
<?php
function array_delete(&$array, $key) {
if (!isset($array[$key])) {
return null;
}
$value = $array[$key];
unset($array[$key]);
return $value;
}
@SparK-Cruz
SparK-Cruz / unchain.js
Last active July 26, 2022 14:08
Lib for chaining any method by using the ._. operator
exports.unchain = function unchain(subject) {
const proxy = new Proxy(subject, {
get(target, name, receiver) {
if (name === '_') {
return new Proxy(subject, {
get(target, name, receiver) {
const member = Reflect.get(target, name, receiver);
if (typeof member === 'function') {
return function () {