Skip to content

Instantly share code, notes, and snippets.

View mannuelf's full-sized avatar
👾

Mannuel Ferreira mannuelf

👾
View GitHub Profile
const numbers = [
[10, 11],
[90, 8],
[20, 2],
[80, 3],
[180, -22],
[30, -92],
];
const sorted = _.sortBy(numbers, (row) => row[1]);
const rectangular = (state) => {
return {
area: () => {
return state.height * state.width;
}
};
};
const openable = (state) => {
return {
# editorconfig.org
root = false
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
@mannuelf
mannuelf / useEffect-cleanup.js
Created March 27, 2020 06:04
React Hooks clean up function after running useEffect
import React, { useState, useEffect } from 'react'
export default function WindowSize() {
const [[windowWidth, windowHeight], setWindowSize] = useState([window.innerWidth, window.innerHeight])
const [visible, setVisible] = useState(false)
useEffect(() => {
let timeoutId
const handleResize = () => {
setWindowSize([window.innerWidth, window.innerHeight])
setVisible(true)
@mannuelf
mannuelf / change-author.sh
Created May 12, 2019 20:15
Changing author info
git filter-branch --env-filter '
WRONG_EMAIL="wrong@example.com"
NEW_NAME="New Name Value"
NEW_EMAIL="correct@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
@mannuelf
mannuelf / new_gist_file_0
Last active January 18, 2018 21:00
update urls in database mysql
UPDATE wp_options SET option_value = replace(option_value, 'Existing URL', 'New URL') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'Existing URL', 'New URL');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'Existing URL','New URL');
UPDATE wp_usermeta SET meta_value = replace(meta_value, 'Existing URL','New URL');
UPDATE wp_links SET link_url = replace(link_url, 'Existing URL','New URL');
dropzone.on("addedfile", function(origFile) {
var MAX_WIDTH = 800;
var MAX_HEIGHT = 600;
var reader = new FileReader();
// Convert file to img
reader.addEventListener("load", function(event) {
@mannuelf
mannuelf / some.js
Created January 10, 2017 20:32
In Progress Network Requests: Given an array of network objects representing network requests, assign the boolean 'true' to the variable 'inProgress' if any network request has a 'status' of 'pending'.
var requests = [
{ url: '/photos', status: 'complete' },
{ url: '/albums', status: 'pending' },
{ url: '/users', status: 'failed' }
];
var inProgress = requests.some(function(status) {
return status != 'pending';
});
@mannuelf
mannuelf / find-specific.js
Created January 1, 2017 21:36
find a specific post or thing in an array
const posts = [
{ id: 1, title: 'New Post'},
{ id: 2, title: 'Old Post'},
];
const comment = { postId: 1, content: 'what great reading' };
function postForComment(posts, comment) {
return posts.find(function(post) {
return post.id === comment.postId;
function Car(model) {
this.model = model;
}
var cars = [
new Car('Ferrari'),
new Car('McLaren'),
new Car('Porsche')
];