Skip to content

Instantly share code, notes, and snippets.

*
!package.json
!package-lock.json
!server.js
'use strict';
const {inspect} = require('util');
const readonly = value => ({
configurable: true,
value,
});
// Not to be considered a URL.
@charmander
charmander / find-webpage.py
Last active May 19, 2018 11:50
today’s hacked-together but task-appropriate refactoring aid
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import ast
import codeop
def try_get_context(source_lines, lineno, limit=10):
# does not try very hard
line = source_lines[node.lineno - 1]
app.use(session({
store: store,
secret: config.sessions.secret,
cookie: { maxage: 30 * 24 * 60 * 60 * 1000, secure: true },
resave: false,
saveUninitialized: false
}))
app.get('/loginrefresh', function (req, res) {
console.log(req.session)
@charmander
charmander / .js
Last active August 29, 2017 17:16 — forked from anonymous/javascript
exports.playlistExists = (name, playlists) => ({
index: playlists.findIndex(p => p.name.toLowerCase() === name.toLowerCase()),
});
exports.createPlaylist = name =>
exports.playlists()
.then(playlists => exports.playlistExists(name, playlists.items))
.then(response => {
if (response.index === -1) {
#!/usr/bin/env node
'use strict';
const https = require('https');
const semver = require('semver');
const readUtf8 = stream =>
new Promise((resolve, reject) => {
const parts = [];
@charmander
charmander / scan.js
Last active May 9, 2017 05:16 — forked from kaihendry/scan.js
const scanNext = lastEvaluatedKey =>
scan(lastEvaluatedKey)
.tap(data => {
console.log(++counter, data.Count, data.LastEvaluatedKey);
})
.then(data =>
data.LastEvaluatedKey ?
scanNext(data.LastEvaluatedKey) :
Promise.resolve()
);
macro selected(page)
if page === currentPage
.selected
a href: "/" selected('home')
a href: "/about" selected('about')
a href: "/contact" selected('contact')
class Query {
constructor(text, values) {
this.text = text;
this.values = values;
}
}
const sql = (parts, ...values) => {
let text = parts[0];
@charmander
charmander / utf8.js
Created March 3, 2017 05:17 — forked from pascaldekloe/utf8.js
JavaScript UTF-8 encoding and decoding with TypedArray
// Marshals a string to Uint8Array.
function encodeUTF8(s) {
var i = 0;
var bytes = new Uint8Array(s.length * 4);
for (var ci = 0; ci != s.length; ci++) {
var c = s.charCodeAt(ci);
if (c < 128) {
bytes[i++] = c;
continue;
}