Skip to content

Instantly share code, notes, and snippets.

@prutya
prutya / sst.config.ts
Last active October 21, 2024 09:11
Deploy a Next.js app to a Hetzner VPS using SST and Docker (Part of my SST guide https://www.prudkohliad.com/articles/deploy-next-js-to-vps-using-sst-2024-08-11). See full repo at https://github.com/prutya/next-self-hosted
/// <reference path="./.sst/platform/config.d.ts" />
import { resolve as pathResolve } from "node:path";
import { writeFileSync as fsWriteFileSync } from "node:fs";
import { asset as pulumiAsset, all as pulumiAll } from "@pulumi/pulumi";
// Specify HCLOUD_TOKEN and CLOUDFLARE_API_TOKEN before running
// Permissions for CLOUDFLARE_API_TOKEN:
// - Account Settings:Read
// - Zone Settings:Edit
@safareli
safareli / type-guard-composition.ts
Last active January 14, 2022 14:16
Composing TypeScript type guards
/**
* Type representing a guard function accepting Input and some other arguments
* while refining type of input as `Output`
*/
export type TypeGuard<
Input,
Output extends Input,
Args extends unknown[] = []
> = (value: Input, ...args: Args) => value is Output;
@lujanfernaud
lujanfernaud / problem_solving_for_developers.md
Last active October 31, 2024 21:40
Problem Solving for Developers

Motivation

  • expression-oriented programming one of the great advances of FP
  • expressions plug together like legos, making more malleable programming experience in-the-small

Examples

Write in an expression-oriented style, scoping variables as locally as possible:

@staltz
staltz / streamio.js
Created October 3, 2016 13:22
Playful Haskell Stream I/O with ES6 Generators
function *main() {
const confirmRequest = {
type: 'confirm',
value: 'Are you sure?',
};
const confirmResponse = yield confirmRequest;
if (confirmResponse === true) {
const consoleRequest = {
type: 'console',
@cpsubrian
cpsubrian / README.md
Last active March 27, 2023 13:34
React decorators for redux/react-router/immutable 'smart' components.

This is my typical decorator stack for a 'smart component' used as the component for react-router route. Note some code is missing here but this should give you the idea.

Example usage:

StateDetailsScene.js

import React from 'react'
import _ from 'lodash'
import route from 'core/decorators/route'
@alkrauss48
alkrauss48 / gulpfile.js
Last active February 17, 2020 12:45
Base gulpfile config for babel, browserify, and uglify - with sourcemaps and livereload
var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var livereload = require('gulp-livereload');
@chantastic
chantastic / on-jsx.markdown
Last active November 10, 2024 13:39
JSX, a year in

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I led the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can't

@antoniocapelo
antoniocapelo / bearerHttpInterceptor
Created February 13, 2015 21:14
AngularJS HTTP Interceptor for Bearer Token Auth Requests
app.factory('BearerAuthInterceptor', function ($window, $q) {
return {
request: function(config) {
config.headers = config.headers || {};
if ($window.localStorage.getItem('token')) {
// may also use sessionStorage
config.headers.Authorization = 'Bearer ' + $window.localStorage.getItem('token');
}
return config || $q.when(config);
},