Skip to content

Instantly share code, notes, and snippets.

@kylemcdonald
kylemcdonald / function-calling.ipynb
Created June 14, 2023 01:10
Example of OpenAI function calling API to extract data from LAPD newsroom articles.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kepano
kepano / obsidian-web-clipper.js
Last active May 3, 2024 07:21
Obsidian Web Clipper Bookmarklet to save articles and pages from the web (for Safari, Chrome, Firefox, and mobile browsers)
javascript: Promise.all([import('https://unpkg.com/turndown@6.0.0?module'), import('https://unpkg.com/@tehshrike/readability@0.2.0'), ]).then(async ([{
default: Turndown
}, {
default: Readability
}]) => {
/* Optional vault name */
const vault = "";
/* Optional folder name such as "Clippings/" */
@webb
webb / simple-cli-parser.bash
Created October 2, 2020 15:18
A simple CLI parser in Bash
#!/usr/bin/env bash
print_help () { echo "Option -f \${file}: Set file"; exit 0; }
fail () { echo "Error: $*" >&2; exit 1; }
unset file
OPTIND=1
while getopts :f:h-: option
do case $option in
h ) print_help;;
@smic
smic / BorderlessWindow.swift
Last active July 7, 2023 20:19
Extension to create borderless windows in SwiftUI
import SwiftUI
extension CGRect {
fileprivate func point(anchor: UnitPoint) -> CGPoint {
var point = self.origin
point.x += self.size.width * anchor.x
#if os(macOS)
point.y += self.size.height * (1 - anchor.y)
#else
point.y += self.size.height * anchor.y
@steinuil
steinuil / Nuget2Nix.fsx
Last active May 23, 2023 21:39
Code for the .NET packaging post
open System
open System.IO
open System.Net
open System.Text.Json
open System.Collections.Generic
open System.Security.Cryptography
/// Taken from hash.cc in the nix codebase
/// https://github.com/NixOS/nix/blob/a7540294cfae82c098e8691cd5212a9184add574/src/libutil/hash.cc
module Base32 =
@mkatychev
mkatychev / diffignore.sh
Last active October 23, 2019 20:12
Parse A .ignore file for diffing git
#!/usr/bin/env bash
# https://github.com/ggreer/the_silver_searcher/wiki/Advanced-Usage#ignore
# git diff master -- $(diffignore.sh)
DIFFI=''
test -f ".diffignore" || cp ./scripts/.diffignore.base ./.diffignore || exit 1
while read -r ignore;do
@hallettj
hallettj / Makefile
Last active December 10, 2023 13:32
Makefile for transpiling with Babel & Flow in a Node app, or in a client- or server-side shared library
# Makefile for transpiling with Babel in a Node app, or in a client- or
# server-side shared library.
.PHONY: all clean
# Install `babel-cli` in a project to get the transpiler.
babel := node_modules/.bin/babel
# Identify modules to be transpiled by recursively searching the `src/`
# directory.
@tejacques
tejacques / HOCBaseRender.tsx
Last active May 2, 2022 13:05
React Higher Order Components in TypeScript
import * as React from 'react';
import { Component } from 'react';
export default function HOCBaseRender<Props, State, ComponentState>(
Comp: new() => Component<Props & State, ComponentState>) {
return class HOCBase extends Component<Props, State> {
render() {
return <Comp {...this.props} {...this.state}/>;
}
}
@ccampanale
ccampanale / vaultsealmanager.sh
Created December 10, 2015 19:31
Bash shell script to check seal status for local vault server and attempt to unseal using keys secured in vault secret store. Supports HA Vault clusters with TLS with unseal keys stored as secrets in vault (see code). Relies on registered service vault.service.consul, in place DNS configuration, and a single unsealed vault instance in your clust…
#!/bin/bash
export vault=/usr/local/bin/vault
export VAULT_TOKEN=$(cat /root/.vault-token)
vault_cacert='-ca-cert=/path/to/your/ca.pem'
local_vault="-address=https://$(hostname -f):8200"
unsealed_vault="-address=https://$(getent hosts $(dig +short vault.service.consul | tail -n 1) | awk '{ print $2 }'):8200"
leader_vault="-address=https://$($vault status $vault_cacert $unsealed_vault 2> /dev/null | grep Leader | awk '{ print $2 }' | sed 's/^http\(\|s\):\/\///g'):8200"
vault_read="$vault read $vault_cacert $leader_vault"
vault_unseal="$vault unseal $vault_cacert $local_vault"
@tristanfisher
tristanfisher / Ansible-Vault how-to.md
Last active April 3, 2024 13:55
A short tutorial on how to use Vault in your Ansible workflow. Ansible-vault allows you to more safely store sensitive information in a source code repository or on disk.

Working with ansible-vault


I've been using a lot of Ansible lately and while almost everything has been great, finding a clean way to implement ansible-vault wasn't immediately apparent.

What I decided on was the following: put your secret information into a vars file, reference that vars file from your task, and encrypt the whole vars file using ansible-vault encrypt.

Let's use an example: You're writing an Ansible role and want to encrypt the spoiler for the movie Aliens.