Skip to content

Instantly share code, notes, and snippets.

Avatar
🏐
Focusing

ORES ORESoftware

🏐
Focusing
View GitHub Profile
@ORESoftware
ORESoftware / async.md
Created Apr 13, 2020
async-await and outer scope changes
View async.md

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 Mar 31, 2020
alex ubuntu /etc/os-release info
View os-release.md

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 Mar 2, 2020
streaming an http response
View chucked-response.md

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 Feb 24, 2020
Our root.jsx file, which is not the entry point, the entry point is the parent of this file
View root.jsx
import {Provider} from "react-redux";
import {
Router,
Route,
browserHistory,
} from "react-router"
@ORESoftware
ORESoftware / index.jsx
Created Feb 23, 2020
Our index.jsx file
View index.jsx
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 Feb 23, 2020
Webpack middleware for loading incremental build from memory
View app.js
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 Feb 23, 2020
re-use node.js process to
View shell.sh
cm_env_exp() {
rm -rf /tmp/srv-input
mkfifo /tmp/srv-input
rm -rf /tmp/srv-output
mkfifo /tmp/srv-output
(
@ORESoftware
ORESoftware / init.md
Created Feb 11, 2020
initializing vars in Golang
View init.md

In this simple golang example it appears that we don't need to initialize the wg variable. Why do we do this:

var wg sync.WaitGroup
func main() {
        // do some stuff
        wg.Wait()  //     // blocks/waits for waitgroup
}
@ORESoftware
ORESoftware / private.md
Last active Feb 8, 2020
reading private struct field
View private.md

Currently I am getting this error when I attempt to read a private value of a struct using the reflect package:

panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

So, yeah want to read the private value of a struct:

type Foo struct {
 thisIsPrivate string