Skip to content

Instantly share code, notes, and snippets.

View colllin's full-sized avatar

Collin Kindrom colllin

View GitHub Profile
@colllin
colllin / rustworkx-suggestions.md
Last active February 12, 2024 18:36
rustworkx issues / rough edges / room for improvement
  • serialization/deserialization symmetry
    • in general need more formatting options OR go to/from a major interchange format and recommend a separate library for every other kind of format in/out.
    • But need to support at least one text-based in/out so that we can easily print to inspect a graph
  • Why does rx.node_link_json require str values in the node and edge payloads, when JSON supports several other data types? This makes deserialization awkward and error-prone, so for now I'm just converting the nodes to {'json': json.dumps(node_payload)}.
  • no node_index_map()? So you have this clunky interface where you can get either the indices or the data but not both
  • subgraph() resets node indices 😱🤯
  • add_nodes_from() should just be called add_nodes(), same for add_edges_from()
  • compose() accepts an edge map which prevents having multiple edges from one node in the main graph to multiple nodes in the added fragment. Instead, it should accept an edge list in the same format used by
@colllin
colllin / dotdict.py
Created August 2, 2023 16:15
dotdict.py — Simple dot-notation access for python dicts.
# Copied from: https://stackoverflow.com/a/23689767
class dotdict(dict):
"""dot.notation access to dictionary attributes"""
__getattr__ = dict.get
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
@colllin
colllin / Readme.md
Last active February 9, 2021 23:24
FaunaDB Clear all GraphQL metadata

From Leo via slack on Jan 3rd, 2020 in #graphql channel:

This is the script you should run in order to delete all of the GraphQL metadata for the current DB (it won't delete any actual data):

// Remove GraphQL metadata from Collections, Functions, and Indexes
Foreach(Paginate(Collections(), {size:10000}), Lambda('ref', Update(Var('ref'), {data: {gql: null}})))
Foreach(Paginate(Functions(), {size:10000}), Lambda('ref', Update(Var('ref'), {data: {gql: null}})))
Foreach(Paginate(Indexes(), {size:10000}), Lambda('ref', Update(Var('ref'), {data: {gql: null}})))
@colllin
colllin / flatten_action.py
Created August 19, 2020 20:48
OpenAI Gym FlattenAction wrapper
import gym
class FlattenAction(gym.ActionWrapper):
"""Action wrapper that flattens the action."""
def __init__(self, env):
super(FlattenAction, self).__init__(env)
self.action_space = gym.spaces.utils.flatten_space(self.env.action_space)
def action(self, action):
return gym.spaces.utils.unflatten(self.env.action_space, action)
> CreateIndex({
    name: 'users_by_messageSentAt_desc',
    source: Collection('messages'),
    values: [
        {field: ['data','sentAt'], reverse: true},
        {field: ['data','fromUser']}
    ]
})
@colllin
colllin / query-mailgun-emails-by-custom-vars.js
Created January 3, 2020 19:16
Query Mailgun emails by custom variables / custom data
const util = require('util');
const _ = require('lodash');
const mailgun = require("mailgun-js");
async function queryByCustomData(data) {
let mg = mailgun({apiKey: process.env.MAILGUN_API_KEY});
let asyncGet = util.promisify(_.bind(mg.get, mg));
let response = await asyncGet(`/YOUR_MAIL_DOMAIN/events`, {
"user-variables": JSON.stringify(data),
});
@colllin
colllin / mount-ec2-volume.md
Last active February 17, 2023 19:36
Mount an EC2 volume
  • Create & attach volume in AWS console (must be in same availability zone).
  • From your ec2 instance, list attached volumes:
    sudo fdisk -l
    
  • Find the disk in the list and copy it's identifier to your clipboard, e.g. /dev/nvme1n1.
  • If it's a brand new volume, you probably need to format it:
    Don't do this to a volume with data on it, or else it won't have data on it anymore. You can skip this step and come back to it if you get an error about wrong fs type when trying to mount the disk.
@colllin
colllin / Readme.md
Last active February 21, 2024 14:55
FaunaDB User Token Expiration (for ABAC)

Auth0 + FaunaDB ABAC integration: How to expire Fauna user secrets.

Fauna doesn't (yet?) provide guaranteed expiration/TTL for ABAC tokens, so we need to implement it ourselves if we care about it.

What's in the box?

3 javascript functions, each of which can be imported into your project or run from the command-line using node path/to/script.js arg1 arg2 ... argN:

  1. deploy-schema.js: a javascript function for creating supporting collections and indexes in your Fauna database.
@colllin
colllin / Readme.md
Last active August 11, 2020 03:03
Auth0 + FaunaDB integration strategy

Goal

Solutions

At the very least, we need two pieces of functionality:

  1. Create a user document in Fauna to represent each Auth0 user.
  2. Exchange an Auth0 JWT for a FaunaDB user secret.
@colllin
colllin / Find Learning Rate.ipynb
Last active June 4, 2023 11:00
Learning Rate Finder in PyTorch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.