Skip to content

Instantly share code, notes, and snippets.

View mfellner's full-sized avatar
🤖

Maximilian Fellner mfellner

🤖
View GitHub Profile
@mfellner
mfellner / server.js
Created July 18, 2019 07:07
Node.js static file server.
/* eslint-env node */
const http = require('http');
const fs = require('fs');
const path = require('path');
const url = require('url');
const { exec } = require('child_process');
const { promisify } = require('util');
const readFile = promisify(fs.readFile);
@mfellner
mfellner / graphql.ts
Created July 8, 2019 20:42
Using Apollo Server in Next.js 9 with API route in pages/api/graphql.ts
import { ApolloServer, gql } from 'apollo-server-micro';
const typeDefs = gql`
type Query {
sayHello: String
}
`;
const resolvers = {
Query: {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mfellner
mfellner / generators.js
Created April 6, 2017 17:08
Playing around with combinations of generators.
'use strict';
const items = [
{ id: 'a', group: 'x', count: 20 },
{ id: 'b', group: 'x', count: 10 },
{ id: 'c', group: 'x', count: 40 },
{ id: 'c', group: 'y', count: 40 },
{ id: 'c', group: 'y', count: 10 },
{ id: 'c', group: 'y', count: 30 },
{ id: 'c', group: 'z', count: 20 },
@mfellner
mfellner / koa-router-rx.js
Created December 4, 2016 23:52
koa-router-rx.js
// @flow
import Koa from 'koa'
import Router from 'koa-router'
import { Observable, Subject } from 'rxjs/Rx'
type Epic = (observable: Observable) => Observable
const epic1 = observable =>
observable.map(({ctx}) => {
@mfellner
mfellner / Promise.first.js
Created April 19, 2016 16:08
Return the first resolved promise result or the last rejected error
function promiseFirst(promises) {
function tryResolve([x, ...xs], resolve, reject) {
if (xs.length > 0)
x.then(resolve).catch(_ => tryResolve(xs, resolve, reject))
else
x.then(resolve).catch(reject)
}
return new Promise((resolve, reject) =>
tryResolve(promises, resolve, reject)
)
@mfellner
mfellner / autoformatted.py
Created March 30, 2016 14:48
Example of formatting code (JavaScript is slightly unidiomatic)
def fn_foo(data_one, data_two):
for element_x in select_element(data_one, lambda key, value, parent: key ==
'type' and value == 'example' and 'flip' in parent and 'flop' in parent):
for element_y in select_element(data_two, lambda key, value, parent: key ==
'flip' and value == element_y['flip']):
element_x['flop'] = element_y['flop']
@mfellner
mfellner / downgrade.sh
Created March 9, 2016 10:14
How To Downgrade Docker
docker-machine create \
--driver virtualbox \
--virtualbox-boot2docker-url https://github.com/boot2docker/boot2docker/releases/download/v1.9.1/boot2docker.iso \
docker-191
docker-machine start docker-191
eval $(docker-machine env docker-191)
brew switch docker 1.9.1_1
@mfellner
mfellner / spring-boot-swagger.xml
Created February 26, 2016 13:25
swagger-codegen-maven-plugin with spring boot
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- ... -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@mfellner
mfellner / edx-enumerate.js
Last active November 8, 2015 15:07
Enumerate answer choices on edx.org
// ==UserScript==
// @name edx-enumerate
// @source https://gist.github.com/mfellner/194b7d70b9d1a682cf37
// @downloadURL https://gist.github.com/194b7d70b9d1a682cf37.git
// @version 0.1.0
// @description Enumerate answer choices
// @author mfellner
// @include *://courses.edx.org/courses/*courseware*
// @run-at document-idle
// @grant none