Skip to content

Instantly share code, notes, and snippets.

View christianhg's full-sized avatar
🍔

Christian Grøngaard christianhg

🍔
View GitHub Profile
@maxrice
maxrice / us-state-names-abbrevs.php
Created May 23, 2012 18:32
US State Names & Abbreviations as PHP Arrays
<?php
/* From https://www.usps.com/send/official-abbreviations.htm */
$us_state_abbrevs_names = array(
'AL'=>'ALABAMA',
'AK'=>'ALASKA',
'AS'=>'AMERICAN SAMOA',
'AZ'=>'ARIZONA',
'AR'=>'ARKANSAS',
@robotlolita
robotlolita / loops-are-evil.md
Last active March 2, 2022 17:19
Why `xs.each(f)` should not be considered a "loop".

First and foremost, let's take a look at the following pieces of code. The first one is something you should be rather familiar with, and the second one is also a somewhat familiar idiom these days (at least in languages with higher-order functions):

// Example 1:
30 + 12

// Example 2:
xs.map(f)
@esfand
esfand / typescript_angular.adoc
Last active September 30, 2022 12:37
AngularJS with TypeScript
@mgreensmith
mgreensmith / Slack_solarized_themes
Last active May 2, 2024 18:14
Solarized themes for Slack
Solarized
#FDF6E3,#EEE8D5,#93A1A1,#FDF6E3,#EEE8D5,#657B83,#2AA198,#DC322F
Solarized Dark
#073642,#002B36,#B58900,#FDF6E3,#CB4B16,#FDF6E3,#2AA198,#DC322F
@paulirish
paulirish / what-forces-layout.md
Last active April 30, 2024 17:56
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.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent

Parens And Performance

Years ago, some smart folks that worked on JS engines realized that not all JS that's loaded into a page/app initially is needed right away. They implemented JIT to optimize this situation.

JIT means Just-In-Time, which means essentially that the engine can defer processing (parsing, compiling) certain parts of a JS program until a later time, for example when the function in question is actually needed. This deferral means the engine is freer to spend the important cycles right now on the code that's going to run right now. This is a really good thing for JS performance.

Some time later, some JS engine devs realized that they needed to get some hints from the code as to which functions would run right away, and which ones wouldn't. In technical speak, these hints are called heuristics.

So they realized that one very common pattern for knowing that a function was going to run right away is if the first character before the function keyword was a (, because that usually m

@staltz
staltz / adnetworks.txt
Created November 20, 2016 10:34
Ban these domains of ad networks
101com.com, 101order.com, 123found.com, 180hits.de, 180searchassistant.com, 1x1rank.com, 207.net, 247media.com, 24log.com, 24log.de, 24pm-affiliation.com, 2mdn.net, 2o7.net, 360yield.com, 4affiliate.net, 4d5.net, 50websads.com, 518ad.com, 51yes.com, 600z.com, 777partner.com, 77tracking.com, 7bpeople.com, 7search.com, 99count.com, a-ads.com, a-counter.kiev.ua, a.0day.kiev.ua, a.aproductmsg.com, a.collective-media.net, a.consumer.net, a.mktw.net, a.sakh.com, a.ucoz.net, a.ucoz.ru, a.xanga.com, a32.g.a.yimg.com, aaddzz.com, abacho.net, abc-ads.com, absoluteclickscom.com, abz.com, ac.rnm.ca, accounts.pkr.com.invalid, acsseo.com, actionsplash.com, actualdeals.com, acuityads.com, ad-balancer.at, ad-balancer.net, ad-center.com, ad-images.suntimes.com, ad-pay.de, ad-rotator.com, ad-server.gulasidorna.se, ad-serverparc.nl, ad-souk.com, ad-space.net, ad-tech.com, ad-up.com, ad.100.tbn.ru, ad.71i.de, ad.980x.com, ad.a8.net, ad.abcnews.com, ad.abctv.com, ad.about.com, ad.aboutit.de, ad.aboutwebservices.com, ad.abum.com,
@developit
developit / hydra-alias.md
Last active February 27, 2020 01:54
Alias to invoke Chrome Canary w/ tracing, for IRHydra

An Alias to run Chrome with tracing enabled

For Chrome Canary:

alias hydra='/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --no-sandbox --js-flags="--user-data-dir=/tmp/profile --trace-hydrogen --trace-phase=Z --trace-deopt --code-comments --hydrogen-track-positions --redirect-code-traces"'

For regular ol' Chrome:

@Rich-Harris
Rich-Harris / prepack-svelte.md
Last active May 19, 2022 11:02
Is Prepack like Svelte?

Note: I'm not involved in Prepack in any way — please correct me if I say anything incorrect below!

A few people have asked me if Prepack and Svelte are similar projects with similar goals. The answer is 'no, they're not', but let's take a moment to explore why.

What is Prepack?

Prepack describes itself as a 'partial evaluator for JavaScript'. What that means is that it will run your code in a specialised interpreter that, rather than having some effect on the world (like printing a message to the console), will track the effects that would have happened and express them more directly.

So for example if you give it this code...

@ivenmarquardt
ivenmarquardt / lazy-evaluation.js
Last active May 18, 2018 20:37
Lazy evaluation, lazy getters, eta reduction, function composition, implicit thunks through deferred type
// Lazy Getters
/* What enables Tail Recursion Modulo Cons in Javascript is a thunk in Weak Head Normal Form.
An expression in weak head normal form has been evaluated to the outermost data constructor,
but contains sub-expressions that may not have been fully evaluated. In Javascript only thunks
can prevent sub-expressions from being immediately evaluated. */
const cons = (head, tail) => ({head, tail});