Skip to content

Instantly share code, notes, and snippets.

View emanuel-sanabria-developer's full-sized avatar

Emanuel Sanabria emanuel-sanabria-developer

View GitHub Profile
// 1 - Palindrome
const palindrome =
"A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal-Panama!";
const nonPalindrome = "levels, manaini";
const isPalindrome = (str: string) => {
const letters = str.replace(/\W/g, "").toLocaleLowerCase();
return (
letters ===
letters
.split("")
@emanuel-sanabria-developer
emanuel-sanabria-developer / uniq
Created June 20, 2019 10:46
simple uniq array implementation
export const unique = array => {
if (!array.length || array.length === 1) {
return array;
}
return array.reduce(
(uniqArray, current) =>
!uniqArray.includes(current) ? uniqArray.concat(current) : uniqArray,
[]
);
@emanuel-sanabria-developer
emanuel-sanabria-developer / bem-generator
Last active June 12, 2019 09:24
bem className generator
export default (block) => {
return (element, modifiers) => {
let className = block;
if (element) {
className = `${block}_${element}`;
}
if (modifiers) {
for (const modifier of Object.keys(modifiers)) {
{
"auto_close_tags": false,
"bold_folder_labels": true,
"color_scheme": "Packages/User/SublimeLinter/Monokai (SL).tmTheme",
"copy_with_empty_selection": false,
"default_line_ending": "windows",
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"find_selected_text": true,
"font_face": "Hack",
@emanuel-sanabria-developer
emanuel-sanabria-developer / what-forces-layout.md
Created September 30, 2015 00:31 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
function ObserverList() {
this.list = [];
};
ObserverList.prototype.add = function(obj) {
this.list.push(obj);
};
ObserverList.prototype.removeAt = function( index ){
this.list.splice( index, 1 );
function shadeColor($color, $percent) {
$num = base_convert(substr($color, 1), 16, 10);
$amt = round(2.55 * $percent);
$r = ($num >> 16) + $amt;
$b = ($num >> 8 & 0x00ff) + $amt;
$g = ($num & 0x0000ff) + $amt;
return '#'.substr(base_convert(0x1000000 + ($r<255?$r<1?0:$r:255)*0x10000 + ($b<255?$b<1?0:$b:255)*0x100 + ($g<255?$g<1?0:$g:255), 10, 16), 1);
}
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// some code..
}
/*
* Useful function for random integer between [min, max].
*/
function randomBetween(min, max) {
return ~~(Math.random() * (max - min + 1) + min);
}
/*
* Request new frame by Paul Irish.
* 60 FPS.
*/
window.requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||