Skip to content

Instantly share code, notes, and snippets.

View codepunkt's full-sized avatar

Christoph Werner codepunkt

View GitHub Profile
@remy
remy / gist:350433
Created March 31, 2010 14:58
Storage polyfill
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
@jed
jed / LICENSE.txt
Created May 20, 2011 13:27 — forked from 140bytes/LICENSE.txt
generate random UUIDs
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@peterhost
peterhost / node_debian_init.sh
Created November 25, 2010 11:41
Daemon init script for node.js based app/server (DEBIAN/UBUNTU)
#!/bin/sh
# ------------------------------------------------------------------------------
# SOME INFOS : fairly standard (debian) init script.
# Note that node doesn't create a PID file (hence --make-pidfile)
# has to be run in the background (hence --background)
# and NOT as root (hence --chuid)
#
# MORE INFOS : INIT SCRIPT http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
# INIT-INFO RULES http://wiki.debian.org/LSBInitScripts
# INSTALL/REMOVE http://www.debian-administration.org/articles/28

Partial Hydration

If you do server side rendering (SSR) you don't necessarily need to hydrate your entire page if most of your content ist static and only some parts are interactive / dynamic. That is especially true for a newspaper website, which ich what we are working on.

What you want is partial hydration, sometimes called or related to progressive hydration or lazy hydration.

There are a few implementations out there to achive this, for instance second-dehydrator

@sl4m
sl4m / gist:5091803
Created March 5, 2013 16:57 — forked from trcarden/gist:3295935
create self-signed certificate for localhost
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@Noviny
Noviny / babelTypeDescriptions.md
Last active August 12, 2022 09:46
A list of all babels types with an explanation, and a link to astexplorer with an example

The goal is to have a link to ASTexplorer to demonstrate what each type is. Types have been broken into sections if they are not core parts of javascript (JSX, type annotations, typescript types), however are otherwise in alphabetical order.

WIP - un-added types have a leading ^^^^ while I am working on them.

Important Base Parts

Knowing these will help everywhere

  • identifier A named property, such as a declared variable or object property.
  • blockStatement Anything to be run as part of resolving an expression. (Effectively anything that would go between {} brackets, whether that is in a for statement, or function expression. It will be found as the body property of the expression.
@io41
io41 / paginated_collection.js
Created February 22, 2011 10:10 — forked from zerowidth/paginated_collection.js
Pagination with Backbone.js
// includes bindings for fetching/fetched
var PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage');
typeof(options) != 'undefined' || (options = {});
this.page = 1;
typeof(this.perPage) != 'undefined' || (this.perPage = 10);
},
fetch: function(options) {
@orta
orta / eleventy-twoslash.ts
Created August 23, 2020 10:39
Eleventy Twoslash Markdown It plugin
import MarkdownIt from "markdown-it";
import { createShikiHighlighter, renderCodeToHTML, runTwoSlash, canHighlightLang } from "shiki-twoslash";
import { HighlighterOptions, Highlighter } from "shiki/dist/highlighter";
export default function markdownItShikiTwoslash(markdownit: MarkdownIt, userOptions: HighlighterOptions): void {
let highlighter:Highlighter = null!
// @ts-ignore - fixed in next release to always be a promise
createShikiHighlighter(userOptions).then(h => highlighter = h)
const oldFence = markdownit.renderer.rules.fence;
@gaearon
gaearon / ReduxMicroBoilerplate.js
Last active March 26, 2020 00:35
Super minimal React + Redux app
import React, { Component } from 'react';
import { createStore, combineReducers, applyMiddleware, bindActionCreators } from 'redux';
import { provide, connect } from 'react-redux';
import thunk from 'redux-thunk';
const AVAILABLE_SUBREDDITS = ['apple', 'pics'];
// ------------
// reducers
// ------------
@brycebaril
brycebaril / output.md
Last active February 23, 2020 22:35
process.nextTick vs setImmediate

@mafintosh asks: "Does anyone have a good code example of when to use setImmediate instead of nextTick?"

https://twitter.com/mafintosh/status/624590818125352960

The answer is "generally anywhere outside of core".

process.nextTick is barely asynchronous. Flow-wise it is asynchronous, but it will trigger before any other asynchronous events can (timers, io, etc.) and thus can starve the event loop.

In this script I show a starved event loop where I just synchronously block, use nextTick and setImmediate