Skip to content

Instantly share code, notes, and snippets.

View jamesgarfield's full-sized avatar

James Garfield jamesgarfield

View GitHub Profile
@jamesgarfield
jamesgarfield / execAndSelectOut.go
Last active September 8, 2020 23:19
Example of InlineSQLArgs
func (dqb *QueryBox) ExecAndSelect(ctx context.Context, output interface{}, ds DS, params interface{}, tmplName ...string) error {
if dqb.ReadTmplBox == nil {
return errors.WithStack(errNoBoxFound)
}
panicWhenNotSlice(output)
query, vals, err := execDefaultTemplates(dqb.ReadTmplBox, params, tmplName...)
if err != nil {
return err
}
import _ from 'lodash';
export function replacementReducer(actionType, defaultVal) {
if (defaultVal === undefined) {
throw new Error(
`No default value passed to replacementReducer for action type ${actionType}`
);
}
return (state = defaultVal, action = {}) => {
@jamesgarfield
jamesgarfield / identity.regex
Created February 13, 2015 16:17
Identity function regex (pcre)
function\((.*)\)\s*\{\s*return \1;?\s*\}
close enough anyhow
package main
//go:generate goast write collections.go
type Item string
type Items []*Item
package main
func (c Items) Len() int {
return len(c)
}
func (c Items) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
}
func (c Items) All(fn func(*Item) bool) bool {
for _, v := range c {
package main
type Collection []interface{}
func (c Collection) Len() int {
return len(c)
}
func (c Collection) Swap(i, j int) {
c[i], c[j] = c[j], c[i]

Keybase proof

I hereby claim:

  • I am jamesgarfield on github.
  • I am jamesgarfield (https://keybase.io/jamesgarfield) on keybase.
  • I have a public key whose fingerprint is 8061 54F5 6139 53C4 E06C 12F6 88CB AF38 066F 1354

To claim this, I am signing this object:

import subprocess
import os
class WindowsUser:
def __init__(self, name, session, state, idle):
self.name = name
self.session = session
self.state = state
self.idle = idle
package main
import (
"fmt"
)
const NCPU = 16
func main() {
sum := Concurrent(1000)