Skip to content

Instantly share code, notes, and snippets.

Avatar

Luke SNAW Luke-SNAW

View GitHub Profile
@Luke-SNAW
Luke-SNAW / next.config.js
Last active Feb 8, 2022
[next.js .env for client] #nextjs
View next.config.js
// Next.js comes with built-in support for environment variables.
// https://nextjs.org/docs/basic-features/environment-variables
module.exports = {
env: {
LOCAL_API_ENDPOINT: process.env.LOCAL_API_ENDPOINT,
},
}
@Luke-SNAW
Luke-SNAW / google-translate-element.vue
Last active Jan 27, 2022
[google translate element] #google #plugin
View google-translate-element.vue
<template>
<div id="google_translate_element" />
</template>
<script>
import { Policy } from 'cockatiel'
import { includeJsOnce, injectStyles } from '@/utils'
export function initTranslate() {
includeJsOnce({
View N+1-query-problem.md

The N+1 query problem is a common performance antipattern. It looks like this:

$cats = load_cats();
foreach ($cats as $cat) {
  $cats_hats = load_hats_for_cat($cat);
  // ...
}
@Luke-SNAW
Luke-SNAW / closure.md
Last active Feb 10, 2022
[Javascript as language] #collections #javascript
View closure.md

Closure

  • Closures: A closure is a function having access to the parent scope, even after the parent function has closed.
  • Closures: A function bundled together with its lexical environment forms a closure.

Advantages and Disadvantages of Closures

Advantages

  • Closures help in data encapsulation, i.e, with closures, you can store data in a separate scope and share it only where necessary.
  • Modern JavaScript libraries (like React) heavily rely on closures for rendering components on state or prop change.
@Luke-SNAW
Luke-SNAW / reply.md
Created Dec 23, 2021
[You Can't Buy Integration - Hacker News] https://news.ycombinator.com/item?id=29478375 #SE
View reply.md

Business logic happens line by line between interfaces. Coding may be all ifs and for loops, but when it comes to implementing a new feature, having chosen carefully where to draw the line between, say, your model and your view can be the difference between a 10 line patch and a complete rewrite.

If you don’t have a culture of code review then maybe the rewrite will fly, bugs and all, through to production. If however you have the ability to reason logically about the salient changes diff by prescient diff — where by definition each prescient diff represents nothing but the salient changes — then you at least stand a fighting chance of version N+1 having fewer bugs than version N while also moving your business forwards.