Skip to content

Instantly share code, notes, and snippets.

View leobetosouza's full-sized avatar

Leonardo Alberto Souza leobetosouza

View GitHub Profile
@leobetosouza
leobetosouza / snake.html
Created April 16, 2024 22:08
Simple JS Snake Game on one file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SNAKE GAME</title>
<style>
body {
margin: 0;
const transparentize = (r, g, b, alpha) => {
const a = (1 - alpha) * 255;
const calc = x => Math.round((x - a)/alpha);
return `rgba(${calc(r)}, ${calc(g)}, ${calc(b)}, ${alpha})`;
}
@leobetosouza
leobetosouza / cache.js
Last active October 5, 2017 15:03
Simple JS Cache Persistence
window.cache = (function () {
var _data = {};
var _db = openDatabase(
'cache.db',
'1.0',
'app cache database',
5 * 1024 * 1024
)
@leobetosouza
leobetosouza / memo.htm
Last active July 7, 2017 23:44
Simple JavaScript Memo Puzzle
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memo Puzzle</title>
<style>
body {
text-align: center;
}
@leobetosouza
leobetosouza / sleepSort.js
Created April 25, 2017 17:16
JS Sleep Sort
const sleepSort = async arr => {
var res = [];
await Promise.all(arr.map(n => new Promise(resolve => setTimeout(_ => resolve(res.push(n)), n))));
console.log(res);
};
@leobetosouza
leobetosouza / gist.js
Last active December 29, 2016 15:29
Reduce to ordened tuples of group and ordened values with lodash help
[
{ordernation: 2, category : 'A'}, {ordernation: 2, category : 'B'},
{ordernation: 1, category : 'A'}, {ordernation: 1, category : 'B'},
{ordernation: 3, category : 'C'}
]
.reduce(function (acc, it) {
let tuple = acc.find(tuple => tuple[0] === it.category);
if (tuple) {
let list = tuple[1];
list.splice(_.sortedIndexBy(list, it, 'ordernation'), 0, it)
@leobetosouza
leobetosouza / gist:08359eab209a3fc790eca2219a37248b
Last active December 26, 2016 18:40
Look and Say JavaScript
function lookNsay (n) {
const o = {
last : null,
count : 0,
_res : '',
get res () {
return this._res + this.count + this.last
}
}
@leobetosouza
leobetosouza / escrevendo-celular-spec.js
Last active September 23, 2016 16:27
Translate text to phone keys
var assert = require ('assert'),
translatePhoneLetters = require('./escrevendo-celular').translatePhoneLetters;
describe('translatePhoneLetters', function() {
it('chamada vazia', function () {
assert.equal(translatePhoneLetters(), '')
})
it('vazio', function () {
var str = ''
@leobetosouza
leobetosouza / roman.js
Created August 11, 2016 04:52
Convert any number between 1 and 3999 to roman using JS
var mapa =[
[1000, { capital : 'M', condition : gt, transform : repeat }],
[900, { capital :'CM', condition : gt, transform : difference }],
[500, { capital : 'D', condition : gt, transform : difference }],
[400, { capital : 'CD', condition : gt, transform : difference }],
[100, { capital : 'C', condition : gt, transform : repeat }],
[90, { capital : 'XC', condition : gt, transform : difference }],
[50, { capital : 'L', condition : gt, transform : difference }],
[40, { capital : 'XL', condition : gt, transform : difference }],
[10, { capital : 'X', condition : gt, transform : repeat }],
Verifying that +leobetosouza is my blockchain ID. https://onename.com/leobetosouza