Skip to content

Instantly share code, notes, and snippets.

View lubien's full-sized avatar
💭
🔥🦩 LiveView is my new JS framework

Lubien lubien

💭
🔥🦩 LiveView is my new JS framework
View GitHub Profile
@adtac
adtac / Dockerfile
Last active March 29, 2024 01:18
#!/usr/bin/env docker run
#!/usr/bin/env -S bash -c "docker run -p 8080:8080 -it --rm \$(docker build --progress plain -f \$0 . 2>&1 | tee /dev/stderr | grep -oP 'sha256:[0-9a-f]*')"
# syntax = docker/dockerfile:1.4.0
FROM node:20
WORKDIR /root
RUN npm install sqlite3
export default {
data () {
return {
xsMobileMedia: window.matchMedia('(max-width: 576px)'),
mobileMedia: window.matchMedia('(max-width: 1023px)'),
isXsMobile: false,
isMobile: false,
}
},
methods: {
@mrosata
mrosata / la-ramda.js
Last active January 15, 2023 01:47
A subset of the Ramda library written using arrow functions, "lamda-ramda". The purpose of this is fun and to use in environments where importing 3rd party libs isn't allowed. Feel free to add to this.
const R = new LaRamda()
/**
* A subset of custom implementations of functions from
* the Ramda library. (all in Lamda form)
* - thanks to @xgrommx for uniq, intersection, where, evolve,
* applySpec, defaultTo, both, either, cond, zipWith
*/
function LaRamda () {
const I = x => x

Recuperar todos os números de um array

Recupera todos arrays e retorna somente um com o valores.

No primeiro método há uma recursividade.

No segundo método, uma conversão para string, split e finalmente converte para um array final de números

Acho que pode ser útil também.

"use strict";
const digits = num => num.toString().split("").map(Number);
const invertNumber = number => digits(number).reverse();
const toNumber = list => Number(list.join(""));
const invertDigit = number => toNumber(invertNumber(number));
const sumList = list => list.reduce((pre, curr) => pre + curr);
const sumDigits = number => sumList(digits(number));
/* OBMEP 2015 - 2ª Fase - Data */
function sum_digit(number) {
var result = 0;
while (number) {
result += number % 10;
number = Math.floor(number / 10);
}
return result;
}
const matrix = [[2,4,6,8],[12,14,16,18],[20,24,28,32],[32,34,36,38],[42,44,46,48]];
const exp = matrix[0];
const arrNumbers = matrix.slice(1);
const props = [
(number, _i) => (number * exp[_i]),
(number, _i) => (number / exp[_i]),
(number, _i) => (number - exp[_i]),
(number, _i) => (number + exp[_i])
];
const op = (arr, _i) => arr.map(_a => props[_i](_a, _i));
@Woodsphreaker
Woodsphreaker / negatives.js
Last active March 18, 2017 17:20
Count Negative Integers in Matrix
"use strict";
const arr = [[-1, 3, 4, 1], [2, 2, 4, 9], [4, 5, -7, 9]];
const flatten = [].concat(...arr);
const find = () => flatten.filter(_a => _a < 0).length;
console.log(find()) //2
/*
* Count Negative Integers in Matrix
*/
M = [
[ -1, 3, 4, 1],
[ 2, 2, 4, 9],
[ 4, 5, -7, 9]
]
@anabastos
anabastos / criaArrayPrimos.js
Last active January 7, 2020 00:16
Dado um número aleatório, retornar todos os números PRIMOS entre 0 e o número escolhido
const criaArrayPrimos = x =>
criaArray(x)
.slice(2)
.filter(checaFatores)
const criaArray = tamanho => Array.from({ length: tamanho }, (el, index) => index)
const checaFatores = n =>
criaArray(maiorDivisor(n))
.slice(2)