Skip to content

Instantly share code, notes, and snippets.

View mfellner's full-sized avatar
🤖

Maximilian Fellner mfellner

🤖
View GitHub Profile
@mfellner
mfellner / rsync-sshfs.sh
Created June 9, 2013 15:42
Sync a local and a remote directory with rsync over sshfs (e.g. when you only have sftp access). Note the defer_permissions option and the -c (checksum) flag. Tested on OS X with rsync 2.6.9 and sshfs 2.4.0 (fuse4x 0.9.2).
#!/bin/bash
SSH_USER="user@sftp.domain.com" # your sftp credentials
SSH_KEY="~/.ssh/id_rsa" # your ssh private key
DOCUMENT_ROOT="/www/vhosts/mywebsite.com/htdocs" # directory on the remote server
LOCAL_DIR="~/mywebsite.com/public" # directory on your local machine
REMOTE_DIR="_remote_dir" # temporary mount point
mkdir -p $REMOTE_DIR
sshfs $SSH_USER:$DOCUMENT_ROOT $REMOTE_DIR -o workaround=rename -o defer_permissions -o IdentityFile=$SSH_KEY
@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: {
@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 / main.es6
Last active August 3, 2017 04:32
Playing with RxJS Observables and ES6
const Rx = require('Rx');
require('babel/register');
const Observables = require('./observables.es6');
// Define a very simple, router-like object
class Router {
constructor() {
this.routes = {};
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / 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']