Skip to content

Instantly share code, notes, and snippets.

View elstr's full-sized avatar
🍕
Working from home

Eleonora Lester elstr

🍕
Working from home
  • Buenos Aires
View GitHub Profile
@elstr
elstr / getMap.js
Created June 10, 2019 22:53
Get map from gmaps fro specific lat lng
/**
* input: lat, lng
* output: map from gmaps
* @param {Float} lat
* @param {Float} lng
*/
export const getMap = (lat, lng) =>
`https://maps.googleapis.com/maps/api/staticmap?center=${lat},${lng}&zoom=14&size=350x350&markers=color:blue|${lat},${lng}&key=${
window.modern_tribe_config.cafe_locator.api_key
}`
@elstr
elstr / isEmpty.js
Created June 10, 2019 22:53
Check if object is empty
/**
* input: object | undefined | null
* output: if object is empty returns true
* @param {object} obj
*/
export const isEmpty = obj => obj && !Object.getOwnPropertyNames(obj).length
@elstr
elstr / typescript-hoc.tsx
Created June 4, 2019 19:17
Typescript HOC
import React from "react"
import { ThemeProvider } from "emotion-theming"
import { theme, LsMuiThemeProvider } from "./index"
const withThemeHOC = <P extends object>(Component: React.ComponentType<P>) =>
class withThemeComponent extends React.Component<P & any> {
render() {
return (
<LsMuiThemeProvider>
<ThemeProvider theme={theme}>
<Component {...this.props as P} />
@elstr
elstr / relations-explained.png
Last active May 22, 2019 18:54
explain-entity-relation
relations-explained.png
@elstr
elstr / avoidSwitch.js
Created May 22, 2019 15:24
Avoid switch statement
// Switch case
switch (measureErrorTypeSelected) {
case ERROR_MARGIN:
return (
selectedErrorColumnIndex.length > 0 && !!measureErrorLevelSelected
)
case CONFIDENCE_INTERVAL:
return (
selectedErrorColumnIndex.length === 2 &&
!!measureErrorLevelSelected &&
@elstr
elstr / simplifyIteration.js
Last active May 22, 2019 15:24
Simplify double iteration problem
// o(n)^2
var numJewelsInStones = function(J, S) {
let myJewels = 0;
// Jewels
for (var i = 0; i < J.length; i++) {
// Stones
for (var j = 0; j < S.length; j++) { // Nested!
if (J[i] === S[j]) {
myJewels++;
}
@elstr
elstr / bash
Created May 7, 2019 13:08
Fix MAC terminal cd desk + tab doesn't work (to go to Desktop)
echo "set completion-ignore-case On" >> ~/.inputrc
const URL = 'http://swapi.co/api/people/1';
fetch(URL)
.then((data) => data.json())
.then((json) => {
this.setState(json);
});
@elstr
elstr / filteredLocations.js
Last active January 16, 2019 21:29
Clear formatteLocations for demo
const filtradas = formattedLocations.filter(
f =>
f.description !== "Custom Locale" &&
!f.description.includes("New Custom Location") &&
!f.description.includes("New custom locale") &&
!f.description.includes("test") &&
!f.description.includes("force") &&
!f.description.includes("my") &&
f.description !== "accept-any" &&
f.description !== "Add new custom location..." &&
@elstr
elstr / custom-button.jsx
Last active August 8, 2018 02:50
Custom react button component
import React from "react"
export const Button = props => {
const {
onClick,
className,
style,
label,
} = props;