Skip to content

Instantly share code, notes, and snippets.

View robzhu's full-sized avatar

Robert Zhu robzhu

View GitHub Profile
@robzhu
robzhu / Startup.cs
Last active March 23, 2022 09:51
OWIN Startup configuration for JSON serialization
using System.Collections.Generic;
using System.Web.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Owin;
using Swashbuckle.Application;
namespace Project
{
@robzhu
robzhu / Dockerfile
Created May 13, 2015 15:55
Debian/Apache Dockerfile
FROM debian
RUN apt-get update && apt-get install -y apache2
EXPOSE 80 443
CMD ["apache2ctl", "-D FOREGROUND"]
@robzhu
robzhu / Dockerfile
Last active August 29, 2015 14:23
Dockerfile for building an nginx development container
#Dockerfile for building an nginx development container
FROM debian
RUN apt-get update
RUN apt-get install curl vim git nginx -y
EXPOSE 80
WORKDIR /etc/nginx
@robzhu
robzhu / _service.md
Last active September 12, 2015 02:32 — forked from naholyr/_service.md
Sample /etc/init.d script

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@robzhu
robzhu / service.sh
Created September 12, 2015 02:43
init.d service template
#!/bin/sh
### BEGIN INIT INFO
# Provides: <NAME>
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: <DESCRIPTION>
### END INIT INFO
@robzhu
robzhu / new-service.sh
Created September 12, 2015 02:44
init.d service creation script
#!/bin/bash
SERVICE_FILE=$(tempfile)
echo "--- Download template ---"
wget -q -O "$SERVICE_FILE" 'https://gist.githubusercontent.com/robzhu/2772bc0d8cb05e45d639/raw/c6cbfe996431d9e4f9224bdec0208eb19b0e45c1/service.sh'
chmod +x "$SERVICE_FILE"
echo ""
echo "--- Customize ---"
@robzhu
robzhu / Vagrantfile
Created April 18, 2016 01:08
Vagrantfile for building a trusty64 box as a docker host
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.10.101"
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vb.cpus = 2
end
config.vm.provision "shell", inline: <<-SHELL
@robzhu
robzhu / DispatchQueue.js
Last active December 27, 2016 21:04
DispatchQueue for managing request rate against an API call
import sleep from 'sleep-promise';
class DispatchQueue {
constructor(rateLimitInSeconds) {
this.rateLimit = rateLimitInSeconds * 1000;
this.queueSize = 0;
}
async dispatch(call) {
this.queueSize++;
@robzhu
robzhu / subscribe.js
Last active July 14, 2017 18:35
Alternate createSourceEventStream implementation using wrapped promise
function createSourceEventStream(
schema: GraphQLSchema,
document: DocumentNode,
rootValue?: mixed,
contextValue?: mixed,
variableValues?: ?{[key: string]: mixed},
operationName?: ?string,
fieldResolver?: ?GraphQLFieldResolver<any, any>
): Promise<AsyncIterable<mixed>> {
return new Promise((resolve, reject) => {
@robzhu
robzhu / repro.js
Created September 8, 2017 15:55
GraphQL "type" field name repro
const {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
} = require('graphql');
const helloType = new GraphQLObjectType({
name: 'helloType',
fields: () => ({