Skip to content

Instantly share code, notes, and snippets.

View mnpenner's full-sized avatar
:octocat:

Mark Penner mnpenner

:octocat:
View GitHub Profile
@willurd
willurd / web-servers.md
Last active April 18, 2024 14:15
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@iso2022jp
iso2022jp / base94.c
Created November 11, 2012 09:05
base94 encoder/decoder
#include "base94.h"
void base94_encode(const unsigned char *plain, unsigned char *code) {
// high * 2^64 | low
unsigned long long value
= ((unsigned long long)plain[1] << 56) | ((unsigned long long)plain[2] << 48)
| ((unsigned long long)plain[3] << 40) | ((unsigned long long)plain[4] << 32)
@adtac
adtac / Dockerfile
Last active April 13, 2024 22:33
#!/usr/bin/env docker run
#!/usr/bin/env -S bash -c "docker run -p 8080:8080 -it --rm \$(docker build --progress plain -f \$0 . 2>&1 | tee /dev/stderr | grep -oP 'sha256:[0-9a-f]*')"
# syntax = docker/dockerfile:1.4.0
FROM node:20
WORKDIR /root
RUN npm install sqlite3
@moodysalem
moodysalem / promise-cancellable.js
Last active April 9, 2024 18:06
ES6 Cancellable Promise Wrapper
/**
* Returns a promise that has a cancelled method that will cause the callbacks not to fire when it resolves or rejects
* @param promise to wrap
* @returns new promise that will only resolve or reject if cancel is not called
*/
export default function cancellable(promise) {
var cancelled = false;
const toReturn = new Promise((resolve, reject) => {
promise.then(() => {
@XVilka
XVilka / TrueColour.md
Last active April 8, 2024 14:02
True Colour (16 million colours) support in various terminal applications and terminals

THIS GIST WAS MOVED TO TERMSTANDARD/COLORS REPOSITORY.

PLEASE ASK YOUR QUESTIONS OR ADD ANY SUGGESTIONS AS A REPOSITORY ISSUES OR PULL REQUESTS INSTEAD!

@branneman
branneman / better-nodejs-require-paths.md
Last active April 8, 2024 00:22
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@vlucas
vlucas / encryption.js
Last active April 2, 2024 14:26
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
@kitek
kitek / gist:1579117
Created January 8, 2012 17:50
NodeJS create md5 hash from string
var data = "do shash'owania";
var crypto = require('crypto');
crypto.createHash('md5').update(data).digest("hex");
@sergejmueller
sergejmueller / ttf2woff2.md
Last active March 9, 2024 13:37
WOFF 2.0 – Learn more about the next generation Web Font Format and convert TTF to WOFF2
@OlegIlyenko
OlegIlyenko / Event-stream based GraphQL subscriptions.md
Last active February 24, 2024 04:41
Event-stream based GraphQL subscriptions for real-time updates

In this gist I would like to describe an idea for GraphQL subscriptions. It was inspired by conversations about subscriptions in the GraphQL slack channel and different GH issues, like #89 and #411.

Conceptual Model

At the moment GraphQL allows 2 types of queries:

  • query
  • mutation

Reference implementation also adds the third type: subscription. It does not have any semantics yet, so here I would like to propose one possible semantics interpretation and the reasoning behind it.