Skip to content

Instantly share code, notes, and snippets.

View graciano's full-sized avatar

Graciano graciano

View GitHub Profile
@graciano
graciano / main.rs
Last active September 13, 2019 22:10
rust book exercise
use std::collections::HashMap;
fn mean(arr: &Vec<usize>) -> usize {
let sum = arr.iter().fold(0, |sum, el| sum + el);
sum / arr.len()
}
fn median(arr: &Vec<usize>) -> usize {
let half_position = arr.len() / 2;
let mut input_sorted = arr.clone();
@graciano
graciano / humanReadable.js
Created July 22, 2019 17:21
human readable time code wars
const quotientFunctions = {
year: time => Math.floor(time / (365 * 24 * 60 * 60)),
day: time => Math.floor((time / (24 * 60 * 60)) % 365),
hour: time => Math.floor((time / (60 * 60)) % 24),
minute: time => Math.floor((time / 60) % 60),
second: time => Math.floor(time % 60),
};
const pluralize = ({
str,
quotient
@graciano
graciano / jsfuck.js
Last active May 31, 2019 17:40
js fuck example
[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+
@graciano
graciano / example-fetch.js
Created March 23, 2019 21:09
quick example of fetch api with swapi
let apiResponse = await fetch('https://swapi.co/api/people/1')
let swCharacterObject = await apiResponse.json()
console.log(swCharacterObject.name)
@graciano
graciano / cyber-shuffle.js
Last active March 20, 2019 04:42
efeito misturando caracteres de um elemento html
const CYBER_MIN_DURATION = 30;
const CYBER_MAX_DURATION = 70;
const CYBER_CHARS = [...`10!@#$%*()£¢¬{[]}^<>.;:?/|\\-_=+§`];
const random = max => parseInt(Math.random() * max);
const randomRange = (a, b) => a + random(b - a);
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const randomElem = arr => arr[random((arr.length - 1))];
const range = num => [...Array(num).keys()];
const changeCharFromPos = (text, char, pos) => text.substring(0, pos) + char
@graciano
graciano / s3ListDir.js
Created February 20, 2019 19:01
list files from given folder in s3
const { S3 } = require('aws-sdk');
const { promisify } = require('util');
const main = async () => {
const s3 = new S3();
const s3ListPromise = async params => promisify(s3.listObjectsV2).bind(s3)(params);
const listObjects = async (Bucket, Prefix) => s3ListPromise({
Bucket,
@graciano
graciano / zIndex-bookmarklet.js
Created June 20, 2018 14:50 — forked from paulirish/zIndex-bookmarklet.js
find all elements with a z-index and indicate what they are.
// find all elements with a z-index and indicate what they are.
// uses css outline which is not supported in IE <8
function contrast(color){ return '#' +
(Number('0x'+color.substr(1)).toString(10) > 0xffffff/2 ? '000000' : 'ffffff');
}
jQuery('*')
.filter(function(){ return $(this).css('zIndex') !== 'auto'; })
.each(function(){
@graciano
graciano / Publishable.rb
Created June 11, 2018 22:40
module for 'moderatable' models in rails
module Concerns
module Models
module Publishable
extend ActiveSupport::Concern
included do
REJECTED = -1
PENDING = 0
PUBLISHED = 1
@graciano
graciano / UsageExample.vue
Last active May 30, 2018 18:30
js util functions
<template>
<section>
<h1>{{title}}</h1>
<ul>
<li v-for="elem in list" :key="elem.id">
{{ elem.name }}
</li>
</section>
</template>
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->