Skip to content

Instantly share code, notes, and snippets.

View grundmanise's full-sized avatar
🔮
It's magic

Edgar grundmanise

🔮
It's magic
View GitHub Profile
@authenticsebastian
authenticsebastian / monthsLater.js
Last active February 12, 2018 11:23
Calculating how many months have passed since given date
const monthsLater = (date, months) =>
[
(dateArg) => new Date(dateArg),
(dateObj) => dateObj.setMonth(dateObj.getMonth() + months),
(timestamp) => new Date(timestamp),
String
].reduce(
(value, fn) => fn(value),
date
);
@heygrady
heygrady / mapDispatchToProps.md
Last active September 16, 2023 19:19
Redux containers: mapDispatchToProps

Redux containers: mapDispatchToProps

This document details some tips and tricks for creating redux containers. Specifically, this document is looking at the mapDispatchToProps argument of the connect function from [react-redux][react-redux]. There are many ways to write the same thing in redux. This gist covers the various forms that mapDispatchToProps can take.

@bendc
bendc / raf-boilerplate.js
Created August 28, 2017 13:52
rAF tutorial: boilerplate code
"use strict";
// animation utils
// ===============
const trackTime = id => {
const [entry] = performance.getEntriesByName(id);
if (!entry) {
performance.mark(id);
@fgilio
fgilio / axios-catch-error.js
Last active April 11, 2024 19:02
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@chourobin
chourobin / 0-bridging-react-native-cheatsheet.md
Last active April 11, 2024 15:02
React Native Bridging Cheatsheet
@krazov
krazov / fibonacci-eventlooped.js
Last active February 8, 2018 15:24
Some fun with `setImmediate`
function fibonacciProcessed(x) {
return new Promise(resolve => {
const calculation = function (resolveFn, n = 0, a = 0, b = 1) {
if (n > 1) {
setImmediate(() => {
calculation(resolveFn, n - 1, b, a + b);
});
}
// else
@gbitaudeau
gbitaudeau / Int+Extenstion.swift
Created March 3, 2017 09:44
iOS solution to convert large numbers to smaller format. See : http://stackoverflow.com/a/35504720/1661338
extension Int {
func formatUsingAbbrevation () -> String {
let numFormatter = NSNumberFormatter()
typealias Abbrevation = (threshold:Double, divisor:Double, suffix:String)
let abbreviations:[Abbrevation] = [(0, 1, ""),
(1000.0, 1000.0, "K"),
(100_000.0, 1_000_000.0, "M"),
(100_000_000.0, 1_000_000_000.0, "B")]
@nitely
nitely / sqrt.js
Last active May 2, 2023 18:37
Square root (sqrt) in JavaScript using a binary search
/*
sqrt(8)
(0 + 8) / 2 = 4
4 * 4 = 16
(0 + 4) / 2 = 2
2 * 2 = 4
(2 + 4) / 2 = 3
3 * 3 = 9
@bendc
bendc / easing.css
Created September 23, 2016 04:12
Easing CSS variables
:root {
--ease-in-quad: cubic-bezier(.55, .085, .68, .53);
--ease-in-cubic: cubic-bezier(.550, .055, .675, .19);
--ease-in-quart: cubic-bezier(.895, .03, .685, .22);
--ease-in-quint: cubic-bezier(.755, .05, .855, .06);
--ease-in-expo: cubic-bezier(.95, .05, .795, .035);
--ease-in-circ: cubic-bezier(.6, .04, .98, .335);
--ease-out-quad: cubic-bezier(.25, .46, .45, .94);
--ease-out-cubic: cubic-bezier(.215, .61, .355, 1);
@Rich-Harris
Rich-Harris / imperative-v-declarative-imports.md
Last active April 19, 2024 07:49
Why imperative imports are slower than declarative imports

Why imperative imports are slower than declarative imports

A lot of people misunderstood Top-level await is a footgun, including me. I thought the primary danger was that people would be able to put things like AJAX requests in their top-level await expressions, and that this was terrible because await strongly encourages sequential operations even though a lot of the asynchronous activity we're talking about should actually happen concurrently.

But that's not the worst of it. Imperative module loading is intrinsically bad for app startup performance, in ways that are quite subtle.

Consider an app like this:

// main.js