Skip to content

Instantly share code, notes, and snippets.

View luan0ap's full-sized avatar
👁️‍🗨️
Looking for a job

Luan AP luan0ap

👁️‍🗨️
Looking for a job
View GitHub Profile
@luan0ap
luan0ap / search.js
Created November 30, 2017 11:39
Search for itens in a table
/*Filtragem do conteúdo*/
/*function filterItemsTable(e, table) {
return () => {
function tableGetRows(table) {
Array.prototype.forEach.call(table.rows, (filter));
}
tableGetRows(table)
@luan0ap
luan0ap / Loading polyfill
Created January 5, 2018 14:45
Loading polyfill only when needed
const browserSupportsAllFeatures = () => window.Promise && window.fetch && window.Symbol
const loadScript = (src = '', done) => {
var js = document.createElement('script')
js.src = src
document.head.appendChild(js)
return done()
}
@luan0ap
luan0ap / xml.js
Created January 18, 2018 10:19
Create XML with objects javascript
var XML_CHARACTER_MAP = {
'&': '&',
'"': '"',
"'": ''',
'<': '&lt;',
'>': '&gt;'
};
function escapeForXML(string) {
@luan0ap
luan0ap / function-as-conditional.js
Created January 31, 2018 10:11
Use functions as conditional
const conditional = () => ({
conditionOne: 'result',
conditionTwo: 'result'
})
conditional()['condition']
@luan0ap
luan0ap / function-as-conditional.js
Last active January 31, 2018 10:12
Use functions as conditional
const conditional = () => ({
conditionOne: 'result',
conditionTwo: 'result'
})
conditional()['conditionOne'] || 'default value'
const condition = true;
const App = () => (
<div>
<h1>This is always visible</h1>
{
condition && (
<div>
<h2>Show me</h2>
<p>Description</p>
@luan0ap
luan0ap / pipe.js
Created June 5, 2018 18:29
ordenate execution functions
export const pipe = (...fns) => initial => fns.reduce((acc, fn) => fn(acc), initial)
const memoize = (fn) => {
let cache = {}, key;
return (...args) => {
key = JSON.stringify(args);
return cache[key] || (cache[key] = fn.call(null, ...args));
}
};
@luan0ap
luan0ap / array-max.js
Last active July 3, 2018 17:54
Given an array of integers and a number k, where 1 <= k <= length of the array, compute the maximum values of each subarray of length k.
const max = arr => Math.max(...arr)
const calc = len => (len / 2 + 1)
const floor = num => Math.floor(num)
const add = arr => item => arr.push(item)
const slice = arr => start => end => arr.slice(start, end)
@luan0ap
luan0ap / debounce.js
Created July 6, 2018 20:46
Implement a job scheduler which takes in a function f and an integer n, and calls f after n milliseconds.
const debounce = (fn = () => {}, wait = 1000) => (...args) => {
const delayed = () => fn.apply(this, args)
return setTimeout(delayed, wait)
}