Skip to content

Instantly share code, notes, and snippets.

View felippenardi's full-sized avatar

Felippe Nardi felippenardi

View GitHub Profile
@jonkemp
jonkemp / do-not-use-switch.md
Last active April 10, 2024 14:44
'Don’t use switch' excerpted from 'Programming JavaScript Applications' by Eric Elliott, https://www.oreilly.com/library/view/programming-javascript-applications/9781491950289/

Don't Use switch

JavaScript has pretty normal control-flow statements that use blocks delineated by curly braces. There is an exception to this: the switch ... case statement. The strange thing about switch ... case is that you must include the keyword break at the end of each case to prevent control from falling through to the next case. Fall through is a trick that allows you to let more than one case be executed. Control will fall through automatically to the next case unless you explicitly tell it not to with break. However, like the optional semicolons and curly braces, it's possible to forget break when you really should have used it. When that happens, the bug is difficult to find because the code looks correct. For that reason, the break statement should never be left off of a case, even by design.

With that said, JavaScript has an elegant object-literal syntax and first-class functions, which makes it simple to create a keyed method lookup. The object you create for your method lookup is call

@swalkinshaw
swalkinshaw / tutorial.md
Last active November 13, 2023 08:40
Designing a GraphQL API
@jaydenseric
jaydenseric / zeit-now-g-suite-setup.md
Created March 20, 2017 04:46
Zeit Now G Suite setup

Run each of the following lines, replacing yourdomain.com and codehere with your details:

now dns add yourdomain.com @ TXT google-site-verification=codehere
now dns add yourdomain.com @ MX ASPMX.L.GOOGLE.COM 1
now dns add yourdomain.com @ MX ALT1.ASPMX.L.GOOGLE.COM 5
now dns add yourdomain.com @ MX ALT2.ASPMX.L.GOOGLE.COM 5
now dns add yourdomain.com @ MX ALT3.ASPMX.L.GOOGLE.COM 10
now dns add yourdomain.com @ MX ALT4.ASPMX.L.GOOGLE.COM 10
@staltz
staltz / comment.md
Created March 15, 2017 15:27
Nested Pick<T, K> in TypeScript 2.2

TypeScript supports Pick to allow you to get a "subset" object type of a given type, but there is no built-in Pick for deeper nested fields.

If you have a function that takes a large object as argument, but you don't use all of its fields, you can use Pick, Pick2, Pick3, etc to narrow down the input type to be only just what you need. This will make it easier to test your function, because when mocking the input object, you don't need to pass all fields of the "large" object.

@theankitgaurav
theankitgaurav / functionalArrayMethods.md
Created November 4, 2016 16:37
JavaScript Map, Filter, Reduce methods Cheatsheet

map()

Use it when: You want to translate/map all elements in an array to another set of values.

Example: convert Fahrenheit temps to Celsius.

var fahrenheit = [0, 32, 45, 50, 75, 80, 99, 120];

var celcius = fahrenheit.map(function(elem) {
@javierarques
javierarques / protractorAPICheatsheet.md
Last active January 31, 2023 08:51
Protractor API Cheatsheet
@Jermolene
Jermolene / hack
Created March 3, 2015 19:13
Word counting hack for TiddlyWiki 5.1.7
var tag="mytag";r="";$tw.wiki.each(function(t){if(t.hasTag(tag)){r=r+" "+(t.fields.text||"")}});r.trim().replace(/\s+/gi," ").split(" ").length
@drocamor
drocamor / keybase.md
Last active January 31, 2017 22:49
keybase.md

Keybase proof

I hereby claim:

  • I am drocamor on github.
  • I am drocamor (https://keybase.io/drocamor) on keybase.
  • I have a public key ASAeaNEjXiG_J2c8hv_9BPvEFmZS42ml7b4HRu0Cl9Vc9go

To claim this, I am signing this object:

@mixin same($values...){
$length: length($values);
$value: nth($values, $length);
@for $i from 1 to $length{
#{nth($values, $i)}: $value;
}
}
//Usage:
@alcidesqueiroz
alcidesqueiroz / same-value.scss
Last active July 29, 2019 09:20
Sass: Mixin to assign the same value to multiple properties at once
@mixin same($values...) {
$length: length($values);
$value: nth($values, $length);
@for $i from 1 to $length {
#{nth($values, $i)}: $value;
}
}
// Usage: