Skip to content

Instantly share code, notes, and snippets.

View marcosfreitas's full-sized avatar
🔥
Looking forward

Marcos Freitas marcosfreitas

🔥
Looking forward
View GitHub Profile

Cheat sheet: JavaScript Array methods

Deriving a new Array from an existing Array:

['■','●','▲'].slice(1, 3)           ['●','▲']
['■','●','■'].filter(x => x==='■')  ['■','■']
    ['▲','●'].map(x => x+x)         ['▲▲','●●']
    ['▲','●'].flatMap(x => [x,x])   ['▲','▲','●','●']
@gaearon
gaearon / modern_js.md
Last active April 18, 2024 15:01
Modern JavaScript in React Documentation

If you haven’t worked with JavaScript in the last few years, these three points should give you enough knowledge to feel comfortable reading the React documentation:

  • We define variables with let and const statements. For the purposes of the React documentation, you can consider them equivalent to var.
  • We use the class keyword to define JavaScript classes. There are two things worth remembering about them. Firstly, unlike with objects, you don't need to put commas between class method definitions. Secondly, unlike many other languages with classes, in JavaScript the value of this in a method [depends on how it is called](https://developer.mozilla.org/en-US/docs/Web/Jav
@adilsoncarvalho
adilsoncarvalho / tapi_mac.js
Last active April 9, 2021 12:53
MercadoBitcoin - Calculando o TAPI-MAC em NodeJS
const TAPI_SECRET = '1ebda7d457ece1330dff1c9e04cd62c4e02d1835968ff89d2fb2339f06f73028';
const EXPECTED_TAPI_MAC = '7f59ea8749ba596d5c23fa242a531746b918e5e61c9f6c8663a699736db503980f3a507ff7e2ef1336f7888d684a06c9a460d18290e7b738a61d03e25ffdeb76';
const MESSAGE = '/tapi/v3/?tapi_method=list_orders&tapi_nonce=1';
const crypto = require('crypto');
const hmac = crypto.createHmac('sha512', TAPI_SECRET);
hmac.update(MESSAGE);
const TAPI_MAC = hmac.digest('hex');
@BBlackwo
BBlackwo / kraken.fish
Created March 1, 2017 08:05
Open GitKraken from the terminal
## Forked from https://gist.github.com/dersam/0ec781e8fe552521945671870344147b
## Also received help from https://twitter.com/gitkraken/status/691675309725368321
## Open GitKraken using the current repo directory.
## This code is for fish shell. The same thing can be done in bash
## by creating an alias with the command below.
## `1>/dev/null` directs logs from the terminal
## `&` allows use of the same terminal instance to do other things
@wilcorrea
wilcorrea / db.sql
Last active November 10, 2016 16:18
CREATE TABLE `clientes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(500) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
@mcaskill
mcaskill / Function.Array-Group-By.php
Last active January 3, 2024 10:15
PHP : Groups an array by a given key
<?php
if (!function_exists('array_group_by')) {
/**
* Groups an array by a given key.
*
* Groups an array into arrays by a given key, or set of keys, shared between all array members.
*
* Based on {@author Jake Zatecky}'s {@link https://github.com/jakezatecky/array_group_by array_group_by()} function.
* This variant allows $key to be closures.
@guimadaleno
guimadaleno / brazilStates.html
Last active June 8, 2019 15:22
Select com os estados do Brasil - Select with Brazilian states
<select>
<option value="">Selecione</option>
<option value="AC">Acre</option>
<option value="AL">Alagoas</option>
<option value="AP">Amapá</option>
<option value="AM">Amazonas</option>
<option value="BA">Bahia</option>
<option value="CE">Ceará</option>
<option value="DF">Distrito Federal</option>
<option value="ES">Espirito Santo</option>
@isGabe
isGabe / wordpress-force-login.php
Created June 21, 2013 16:10
WordPress: force log in to view any page, with redirect to requested URL#snippet #WordPress
<?php
/*
* Password protect a WordPress site, with a redirect to the requested URL after successful login
*
* Based on:
* http://wordpress.stackexchange.com/a/64999
* http://kovshenin.com/2012/current-url-in-wordpress/
*
**/
@babrath
babrath / fb_delete_allgroupmembers.js
Last active December 18, 2015 07:00 — forked from adriaanm/fb_delete_allgroupmembers.js
Some javascript code that allows you to automatically delete all members from a facebook group.
// first go to https://www.facebook.com/groups/XXXX/members/
// then paste this in the javascript console
deleteAll = [];
deleteAll.elms = [];
deleteAll.canClick = function (el) {
return (typeof el != 'undefined') && (typeof el.click != 'undefined');
}
deleteAll.load = function() {