Skip to content

Instantly share code, notes, and snippets.


Operations Research Engineering Software+ ORESoftware

Block or report user

Report or block ORESoftware

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ORESoftware / resize-base64.js
Last active Sep 18, 2019
resizing an image on the front-end before sending to a server
View resize-base64.js
// Using this code, we can retrieve an image from a user's filesystem, resize the image, and then upload the image
// to a server using AJAX. Because we use base64 encoding, we can just include the image data as just another string value
// in a JSON payload.
// So we can use AJAX to send the file to a server, which is convenient.
// We have one line of relevant html
// get file in the first place => <input type="file" custom-on-change="onAcqImageFileChange" class="form-control">
ORESoftware /
Created Dec 16, 2018
Simple use cases for Node.js domain module

First run this code:

const exec = () => {
   setTimeout(() => {
      throw 'nothing can catch this, except domains';
ORESoftware / cluster.log
Last active Sep 10, 2019
docker-compose logs for mongodb cluster
View cluster.log
Attaching to rydell-mongo-config-03, rydell-mongo-config-02, rydell-mongo-config-01, rydell-shard-03-node-a, rydell-shard-01-node-a, rydell-shard-02-node-a, rydell-router-02, rydell-router-01, rydell-shard-03-node-b, rydell-shard-01-node-b, rydell-shard-02-node-b, rydell-shard-02-node-c, rydell-shard-03-node-c, rydell-shard-01-node-c
rydell-mongo-config-02 | 2019-09-10T02:57:20.550+0000 I STORAGE [main] Max cache overflow file size custom option: 0
rydell-mongo-config-02 | 2019-09-10T02:57:20.552+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
rydell-mongo-config-02 | 2019-09-10T02:57:20.555+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/configdb 64-bit host=c569f8378ff2
rydell-mongo-config-02 | 2019-09-10T02:57:20.555+0000 I CONTROL [initandlisten] db version v4.0.12
rydell-mongo-config-02 | 2019-09-10T02:57:20.555+0000 I CONTROL [initandlisten] git version:
ORESoftware /
Last active Aug 26, 2019
Stdout/stderr for writing between procs can be faulty if extra stdio is included

Here is some node.js code:

#!/usr/bin/env node

const fs = require('fs');

const header = '#!/usr/bin/env bash\n\n';
try {
  const bytes = fs.writeSync(3, header, 0);
ORESoftware / domain-middleware.js
Last active Aug 17, 2019
Using Node.js domains in production
View domain-middleware.js
const d = Domain.create(); // create a new domain for this request
res.once('finish', function () {
ORESoftware / spread.js
Created Jun 25, 2019
spread operator to merge / mixin objects
View spread.js
const a = {
a: {
b: {
c: 4,
d: 'str'
ORESoftware /
Created Jun 5, 2019
JQ does not make it easy to sanitize strings for JSON inclusion
hist='sed '0,1d' "$HOME/my_bash_history" | wc -l' ### <<< we have some double quotes to escape
data="$( jq -nc --arg str "$hist" '{"attr": $str}' )"
echo "data: $data"
hist="$(echo "$data" | jq -r '.attr')"
echo "hist: $hist" # damnit it's back to where it was before
ORESoftware /
Last active May 28, 2019
Cleanup docker artifacts/items

Clean up docker images/containers/volumes/networks

#!/usr/bin/env bash

set +e;
ORESoftware /
Created May 21, 2019
push event payload from Bitbucket API

Here is a sample push payload from bitbucket API:

    "push": {
      "changes": [
          "forced": false,
          "old": {
ORESoftware /
Created May 18, 2019
Removing old unneeded commits - saving disk space and making git clones faster

Say my git repo has 5,000 commits, how can I remove the first 4,000 commits that are quite old and no longer needed, in order to save disk space?

by Sebass van Boxel, Solutions Engineer at GitHub (2018-present)

First of all, I would try less destructive ways to clean up disk space in your git project. If you're collaborating on a repository with others, it's considered a bad practice to rewrite published history. If you’ve already decided that this is what you want to do, please skip the first part. One of the great powers of Git is that it preserves all history. Often you only realize that you really needed that history when it isn’t there anymore. For new people that join your project, it can be of great value to know what happened for what reason, by “removing” those old commits, they'll lose that context. My advice, before anything else, would be to run Git’s built-in housekeeping task:

You can’t perform that action at this time.