Skip to content

Instantly share code, notes, and snippets.

@tj
tj / update.js
Last active Dec 2, 2020
shouldComponentUpdate utility
View update.js
let rows = {}
export default function(props = [], state = []) {
return function(target) {
const proto = Object.create(target.prototype)
proto.shouldComponentUpdate = function(newProps, newState) {
let id = (this._update_id = this._update_id || Math.random())
@tj
tj / app.js
Created Aug 31, 2012
users online with redis
View app.js
var express = require('express');
var redis = require('redis');
var db = redis.createClient();
var app = express();
// track users online (replace UA string with user id)
app.use(function(req, res, next){
var ua = req.headers['user-agent'];
@tj
tj / git aliases.sh
Last active Nov 27, 2020
Some helpful git aliases
View git aliases.sh
alias gd="git diff"
alias gc="git clone"
alias ga="git add"
alias gbd="git branch -D"
alias gst="git status"
alias gca="git commit -a -m"
alias gpt="git push --tags"
alias gp="git push"
alias gpr="git pull-request"
alias grh="git reset --hard"
View enums.go
type User enum {
Authenticated struct {
Name string
}
Anonymous struct {}
}
// and/or
type Authenticated struct {
View search.css
input[type="search"]::-webkit-search-cancel-button {
--size: 11px;
--background: #7F7F7F;
--icon: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI3IiBoZWlnaHQ9IjciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjZmZmIiBzdHJva2Utd2lkdGg9IjMiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgY2xhc3M9ImZlYXRoZXIgZmVhdGhlci14Ij48cGF0aCBkPSJNMTggNkw2IDE4TTYgNmwxMiAxMiIvPjwvc3ZnPgo=");
-webkit-appearance: none;
height: var(--size);
width: var(--size);
border-radius: 50%;
background: var(--background) var(--icon) 50% 50% no-repeat;
}
@tj
tj / colors.css
Created Dec 9, 2016
open-color css modules
View colors.css
/* Gray */
@value gray-0: #f8f9fa;
@value gray-1: #f1f3f5;
@value gray-2: #e9ecef;
@value gray-3: #dee2e6;
@value gray-4: #ced4da;
@value gray-5: #adb5bd;
@value gray-6: #868e96;
@value gray-7: #495057;
View search.css
input[type="search"]::-webkit-search-cancel-button {
--size: 11px;
--background: #7F7F7F;
--icon: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI3IiBoZWlnaHQ9IjciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjZmZmIiBzdHJva2Utd2lkdGg9IjMiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgY2xhc3M9ImZlYXRoZXIgZmVhdGhlci14Ij48cGF0aCBkPSJNMTggNkw2IDE4TTYgNmwxMiAxMiIvPjwvc3ZnPgo=");
-webkit-appearance: none;
height: var(--size);
width: var(--size);
border-radius: var(--size);
background: var(--background) var(--icon) 50% 50% no-repeat;
}
@tj
tj / lambda.md
Last active May 29, 2020
Lambda proposal
View lambda.md

The goal is for the next version of Up to provide all of the runtimes which Lambda already supports. Up lets users write regular HTTP servers, using any framework they prefer. Up works by translating Lambda events to and from HTTP requests, using a Go proxy inside of the Lambda.

Currently Lambda imposes limitations which prevent this from working well with all runtimes, since the Go proxy needs to be the handler, while the runtime files/interpreters still need to be present.

I see two solutions to this problem, the first is to expose the existing runtimes as layers, allowing the proxy to live in a "provided" runtime, but still reference the others for their files. The second is to allow layers to act as the entrypoint/bootstrap, while still allowing the user to select an existing runtime as they normally would, just giving precedence to the layer.

Thanks!

View person.ajs
// Alternative JavaScript Syntax
Person = :(name, address) { @name!, @address! }
Person::inspect = :{ <: "{@name} lives at {@address}" }
tj := Person('TJ', '314 Bessborough ave')
bob := Person('Bob', 'Some place')
[tj, bob].each(:(person){ print(person.inspect()) })
View error
if foo
if bar
something
else
something_else
else
baz
You can’t perform that action at this time.