Skip to content

Instantly share code, notes, and snippets.

View chand1012's full-sized avatar

Chandler chand1012

View GitHub Profile
@chand1012
chand1012 / workerskv-deno.ts
Created March 5, 2023 14:59
Use Cloudflare Workers with Deno
const endpoint = (key: string) => {
const accountID = Deno.env.get("WORKERS_KV_ACCOUNT_ID");
const namespaceID = Deno.env.get("WORKERS_KV_NAMESPACE_ID");
return `https://api.cloudflare.com/client/v4/accounts/${accountID}/storage/kv/namespaces/${namespaceID}/values/${key}`
};
export const set = async (key: string, value: string, ttl: number = 0, expiration: number = 0) => {
const { success, result, errors } = await fetch(`https://api.cloudflare.com/client/v4/accounts/${Deno.env.get("WORKERS_KV_ACCOUNT_ID")}/storage/kv/namespaces/${Deno.env.get("WORKERS_KV_NAMESPACE_ID")}/bulk`, {
method: "PUT",
@chand1012
chand1012 / workerskv.py
Created March 5, 2023 14:57
Script to use Cloudflare Workers with Python via Requests
import os
import requests
def endpoint(key):
accountID = os.getenv("WORKERS_KV_ACCOUNT_ID")
namespaceID = os.getenv("WORKERS_KV_NAMESPACE_ID")
return f"https://api.cloudflare.com/client/v4/accounts/{accountID}/storage/kv/namespaces/{namespaceID}/values/{key}"
def set(key, value, ttl=0, expiration=0):
headers = {
@chand1012
chand1012 / workerskv.ts
Created March 5, 2023 14:37
Use cloudflare workers anywhere you can use Fetch
// info https://giuseppegurgone.com/vercel-cloudflare-kv
// api docs https://developers.cloudflare.com/api/operations/workers-kv-namespace-write-multiple-key-value-pairs
const endpoint = (key: string) => {
const accountID = process.env.WORKERS_KV_ACCOUNT_ID;
const namespaceID = process.env.WORKERS_KV_NAMESPACE_ID;
return `https://api.cloudflare.com/client/v4/accounts/${accountID}/storage/kv/namespaces/${namespaceID}/values/${key}`
};
export const set = async (key: string, value: string, ttl: number = 0, expiration: number = 0) => {
@chand1012
chand1012 / CONTRIBUTING.md
Created December 23, 2022 04:26
The CONTRIBUTING.md file that I use.

Contributing

Please note we have a code of conduct, please follow it in all your interactions with the project.

Branches, Issues, & Pull Requests

Branch Names

Branch names should be

import os
import json
from pymongo import MongoClient
import pymysql
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
///////////////////////////////////////////////////
/// PlutoT6 MP Server Configuration file //
///////////////////////////////////////////////////
// This config best view with Notepad++ OR //
// Other *nix compatible editors of your choice. //
///////////////////////////////////////////////////
// 0.1 Basic version //
// 0.2 Added map list and map rotation //
// 0.3 Added Colors and B3/Log/RCon section //
// 0.4 Added gametype to map list and rotation //
@chand1012
chand1012 / post_body.py
Created October 11, 2021 20:39
POSTs a JSON file as a request body to the specified URL
import requests
import json
import sys
# first argument is the url
# second argument is the file name
url = sys.argv[1]
file_name = sys.argv[2]
@chand1012
chand1012 / md5_ipv4_collisions.go
Last active October 9, 2021 15:54
Tests to see if there are any MD5 collisions within the valid public IPv4 range. Will eat all your RAM.
package main
import (
"crypto/md5"
"encoding/hex"
"fmt"
)
// get the md5 hash of a string
func getMd5Hash(text string) string {
@chand1012
chand1012 / nearNeighbor.js
Created October 2, 2021 05:33
TSP tsp nearest neighbor algorithm. Gets the shortest path between all nodes, starting at the specified index (default 0), and orders them.
// needed for the algorithm
// cartesian distance formula
export const Distance = (x1, y1, x2, y2) => {
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
};
// tsp nearest neighbor algorithm
// gets the shortest path between all nodes
// starting at the index of start_index
// orders the nodes based on this path
@chand1012
chand1012 / ProfileCard.jsx
Created September 6, 2021 04:35
Simple profile card written with Geist UI React. License: https://chand1012.mit-license.org/
import React from "react";
import { Card, Grid, Link, Text, Avatar } from "@geist-ui/react";
const ProfileCard = ({
displayName,
username,
imageUrl,
description,
profileLink,
size,