Skip to content

Instantly share code, notes, and snippets.

# It's best to run this in a local notebook as two separate code blocks
#
#
# First, manually initialize the Ray cluster
#
import ray
if ray.is_initialized():
ray.shutdown()
@baughmann
baughmann / JanusGraph_Management_Example.kt
Created December 8, 2022 21:34
JanusGraph Management in Kotllin (Java)
// Portions of this example assume that:
// 1. You are using [ConfiguredGraphFactory](https://docs.janusgraph.org/operations/configured-graph-factory/) to manage multiple graphs in JanusGraph
// 2. For the above, that you have already added a default graph template using `ConfiguredGraphFactory.createTemplateConfiguration()`.
// connect to a JanusGraph instance running on localhost
val cluster = Cluster.build("localhost").create()
val session = cluster.connect<Client.SessionedClient>()
// get a list of graph names (List<Result> which needs to be acted upon differently than a List<String>)
val graphNames = client.submit("ConfiguredGraphFactory.getGraphNames()").all().get()
@baughmann
baughmann / Map.tsx
Created March 21, 2021 23:46
A basic implementation of using the Google Maps JS API with a DrawingManager in React with TypeScript without relying on one of the amazing (but poorly maintained) libraries.
import { useEffect, useState } from "react";
interface IMapProps {
// so that the parent can get a reference to the google maps instance
onMapLoaded?: (next: google.maps.Map) => void;
// so that the parent can get a reference to
onDrawingManagerLoaded?: (next: google.maps.drawing.DrawingManager) => void;
className?: string;
}
# parameters
nc: 2 # number of classes
depth_multiple: 0.33 # model depth multiple
width_multiple: 0.50 # layer channel multiple
# anchors
anchors:
- [10,13, 16,30, 33,23] # P3/8
- [30,61, 62,45, 59,119] # P4/16
- [116,90, 156,198, 373,326] # P5/32
@baughmann
baughmann / BytesToSize.ts
Created December 13, 2020 23:27
Typescript: Convert bytes to human friendly string
const bytesToSize = (bytes: number) => {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return '0 Byte';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)).toString());
return Math.round(bytes / Math.pow(1024, i)) + ' ' + sizes[i];
}
@baughmann
baughmann / CustomMinioClient.scala
Last active December 8, 2022 21:36
Vert.X Web Streaming Multipart File Data to MinIO / S3
// Basically, this allows you to easily stream a Multipart file upload request to MinIO, rather than save a file locally on the server
// or reading the full file into memory.
//
// While it was created with MinIO in mind, you'll notice that `createMultipartUpload()`, `uploadPart()` and `completeMultipartUpload()`
// are all available inside Amazon's S3 Java SDK. that means you can easily swap this over to use the S3 API instead
package server
import com.google.common.collect.HashMultimap
@baughmann
baughmann / SortableList.tsx
Last active December 8, 2019 17:15
react-native Drag-and-Drop Sortable Horizontal List
/**
* @author Nick Baughman
* @description SortableList is a drag-and-drop horizonal list component that allows for animated re-ordering of a list of elements.
* @todo This component *WILL* require customization! You cannot just copy and paste! See the "TODOs"...
*/
import React, {useState, useEffect} from 'react';
import {
LayoutRectangle,
StyleSheet,
using System;
using System.DirectoryServices.AccountManagement;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http.Features;
@baughmann
baughmann / Startup.cs
Last active July 12, 2019 18:50
Application Startup
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Couchbase.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;