Skip to content

Instantly share code, notes, and snippets.

View ORESoftware's full-sized avatar
🏐
Focusing

Alexander Mills ORESoftware

🏐
Focusing
View GitHub Profile
@ORESoftware
ORESoftware / build-and-run.sh
Last active April 30, 2020 04:27
Build and run docker image/container
#!/usr/bin/env bash
# the nice thing about this script is it will remove
# existing containers in the background
# while the new image is being built
set -eo pipefail
cd "$(dirname "$BASH_SOURCE")"
(
@ORESoftware
ORESoftware / golang.Dockerfile
Last active May 11, 2020 19:23
How to create an optimized dockerfile for go services
FROM golang:1.13 as base_img
ADD ./netrc /root/.netrc
ENV GO111MODULE='on'
ENV GOPROXY='direct'
ENV GOSUMDB='off'
RUN mkdir -p /tmp/go-api
package common
import (
"cloud.google.com/go/compute/metadata"
"encoding/json"
"errors"
"fmt"
"github.com/acme/go-api/config/proj"
jwtgo "github.com/acme/jwt-go"
"golang.org/x/oauth2"
@ORESoftware
ORESoftware / async.md
Created April 13, 2020 19:54
async-await and outer scope changes

This problem:

let mightChange = {id:1}

const doWork = async v => {
  const result1 = await doSomethingWith(mightChange);
  const result2 = await doAnotherThingWith(mightChange);   // mightChange.id might be mutated
 return doSomething(result2)
@ORESoftware
ORESoftware / os-release.md
Created March 31, 2020 01:58
alex ubuntu /etc/os-release info

well here is the output of cat /etc/os-release:

oleg@xps:~$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
@ORESoftware
ORESoftware / chucked-response.md
Last active March 2, 2020 10:32
streaming an http response

If you copy this file and transpile with tsc, you will see that the headers get buffered, but the body is streamed line-by-line, where a new line of JSON arrives to the client every second. But is there a way to stream headers too, not just the body?

import * as http from 'http';


const server = http.createServer((req,res) => {
@ORESoftware
ORESoftware / root.jsx
Last active February 24, 2020 01:50
Our root.jsx file, which is not the entry point, the entry point is the parent of this file
import {Provider} from "react-redux";
import {
Router,
Route,
browserHistory,
} from "react-router"
@ORESoftware
ORESoftware / index.jsx
Created February 23, 2020 22:49
Our index.jsx file
import Root from './root.jsx'
ReactDOM.render(
<Root/>,
document.getElementById('app')
);
if (module.hot) {
// this is necessary for HMR, the only thing we need for the whole app which is nice
module.hot.accept('./root.jsx', () => {
@ORESoftware
ORESoftware / app.js
Created February 23, 2020 22:47
Webpack middleware for loading incremental build from memory
if (!ignoreWebpack && !inProduction)
const webpack = require('webpack');
const webpackMiddleware = require('webpack-dev-middleware');
const WebpackDashboardPlugin = require('webpack-dashboard/plugin');
const config = require('./webpack.config.dev');
const compiler = webpack(config);
app.use(require("webpack-hot-middleware")(compiler));
@ORESoftware
ORESoftware / shell.sh
Created February 23, 2020 02:05
re-use node.js process to
cm_env_exp() {
rm -rf /tmp/srv-input
mkfifo /tmp/srv-input
rm -rf /tmp/srv-output
mkfifo /tmp/srv-output
(