Skip to content

Instantly share code, notes, and snippets.

View dmh2000's full-sized avatar

david h dmh2000

View GitHub Profile
@dmh2000
dmh2000 / main.go
Last active February 22, 2024 18:19
Is this idiomatic Go for handling nested goroutines with context
package main
import (
"context"
"errors"
"fmt"
"time"
)
/*
@dmh2000
dmh2000 / team.go
Created July 16, 2021 04:15
Lists of resolvers in graph-gophers/graphql-go - funny behavior because pointers
// when you get a list of objects to resolve, you create a slice of resolvers for each
// element in the list of objects. But be careful how you structure your loops because
// there are a log of pointers to pointers etc
func (*rootResolver) TeamsByNickname(args struct{ Nickname string }) *[]*teamResolver {
// assume teams = slice of objects from a database
// create a list of resolvers : the right way
// this is ok because it gives a pointer to elements of the slice
@dmh2000
dmh2000 / Dockerfile
Last active February 24, 2020 23:42
Sample Dockerfile with setup for development using Debian
# base linux with version
FROM debian:10.2
# apt setup
RUN apt-get update
# unversioned tools
RUN apt-get install -y git
RUN apt-get install -y curl
RUN apt-get install -y bash-completion
@dmh2000
dmh2000 / async-tty.cpp
Created May 24, 2019 00:44
this demonstrates that ReadIOCompletion::GetOverlappedResult can return 0 bytes even though it appears it shouldn't
/*
build with visual studio 2019 (2017/15 should work too), x64 debug build
*/
#include <Windows.h>
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <cassert>
struct Baton {
@dmh2000
dmh2000 / bcrypt-promise.js
Last active May 18, 2021 09:58
Using bcrypt with promises to hash a password and then verify it
const bcrypt = require("bcrypt");
// use this library in case your version of node doesn't support Promise
// const Promise = require("promise");
let password = "hello";
let stored_hash = "";
// first generate a random salt
function genSalt(password) {
return new Promise((resolve, reject) => {
#include <cstdio>
#include <cstdlib>
#include <cstring>
struct X {
private:
size_t m_len;
char *m_data;
public:
X() : m_len(0),m_data(nullptr) {
@dmh2000
dmh2000 / db.txt
Last active November 8, 2015 16:11
database stuff
SQL VS NOSQL == CAP vs ACID
NOSQL:
CAP : consistency, availability,partition tolerance (Brewer)
distributed
horizontal scale
unstructured
use for maybe data
asynchronous
transactions might seem to work but fail later
@dmh2000
dmh2000 / index.html
Last active November 7, 2015 00:14
browser promise chain
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<script>
$.get("http://cdn.jsdelivr.net/ramda/0.18.0/ramda.min.js",
@dmh2000
dmh2000 / jo.js
Created November 4, 2015 01:18
javascript objects : create, clone, get/set
"use strict";
var util = require('util');
var clone = require('clone');
function inspect(o) {
console.log(util.inspect(o));
}
function clone1(o) {
var n = {};
@dmh2000
dmh2000 / loop.js
Last active September 17, 2020 12:43
javascript loop with async callback handling
"use strict";
// =================================================
// a common question that pops up is
// 'why do my async functions use the final value of my loop variable instead of the one they are called with'?
// its because they refer directly to the loop variable and its last value
// the solutions are various ways to bind the loop variable in a new scope
//
// this gist shows different ways to handle a loop that spawns an async function that depends on the loop index
// =================================================