Skip to content

Instantly share code, notes, and snippets.

Avatar

Jordan Last lastmjs

View GitHub Profile
@gane5h
gane5h / dsr-deposit-volumes.sql
Created Jan 22, 2020
Week-on-week DSR deposit volumes
View dsr-deposit-volumes.sql
select
date_trunc('week', act_at) as act_at_week,
sum(amount / 1e18) as volume
from (
select
e.block_signed_at as act_at,
'0x' || encode(e.tx_hash, 'hex') as tx_hash,
live.hex_to_int(encode(e.topics[4], 'hex')) as amount,
'DSR_DEPOSIT' as act
from live.block_log_events e
@treshugart
treshugart / server-side-rendering-web-components.md
Last active Apr 19, 2019
Server-side rendering web components in Electron
View server-side-rendering-web-components.md

To render a component:

electron server.js --html "<x-app></x-app>" --scripts ./entry-point

Where --html is the HTML that you want to render and --scripts is the entry point that will be loaded prior to rendering the HTML. The entry point should contain all your component definitions that you need for the HTML to be rendered.

View nodejs-secure-web-server-with-websockets.js
'use strict';
const Fs = require('fs');
const Https = require('https');
const WebSocketServer = require('ws').Server;
const httpsServer = Https.createServer({
key: Fs.readFileSync(process.env.KEY),
cert: Fs.readFileSync(process.env.CERT)
});
const wss = new WebSocketServer({
@JanMiksovsky
JanMiksovsky / realTemplate.html
Created Oct 2, 2015
Create a Polymer element using a real <template>, not a <dom-module>
View realTemplate.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="import" href="../components/polymer/polymer.html">
<template id="test-element">
Hello, <content></content>.
</template>
@foxxyz
foxxyz / nginx.conf
Last active Aug 26, 2020
Serve current directory via nginx
View nginx.conf
# Extremely basic development setup to serve the current directory at http://localhost:9001
# Start nginx in this directory with `nginx -p . -c nginx.conf`
# Stop nginx with `nginx -p . -s stop`
events {}
http {
# Serve files with correct mimetypes on OSX
# location may have to be adjusted depending on your OS and nginx install
include /usr/local/etc/nginx/mime.types;
@mikelehen
mikelehen / generate-pushid.js
Created Feb 11, 2015
JavaScript code for generating Firebase Push IDs
View generate-pushid.js
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@leonderijke
leonderijke / svgfixer.js
Last active Mar 24, 2020
Fixes references to inline SVG elements when the <base> tag is in use.
View svgfixer.js
/**
* SVG Fixer
*
* Fixes references to inline SVG elements when the <base> tag is in use.
* Firefox won't display SVG icons referenced with
* `<svg><use xlink:href="#id-of-icon-def"></use></svg>` when the <base> tag is on the page.
*
* More info:
* - http://stackoverflow.com/a/18265336/796152
* - http://www.w3.org/TR/SVG/linking.html
@branneman
branneman / better-nodejs-require-paths.md
Last active Sep 20, 2020
Better local require() paths for Node.js
View better-nodejs-require-paths.md

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

You can’t perform that action at this time.