Skip to content

Instantly share code, notes, and snippets.

View kljensen's full-sized avatar
😵‍💫
0101010101

Kyle L. Jensen kljensen

😵‍💫
0101010101
View GitHub Profile
@mcroach
mcroach / storing-image-assets-in-repo.md
Last active May 28, 2024 16:00
Using an 'assets' branch to store images in your repo

Storing image assets in your repo and referencing in markdown

Create an assets branch and make the initial commit

git checkout --orphan assets
git reset --hard
cp /path/to/cat.png .
git add .
git commit -m 'Added cat picture'
git push -u origin assets
fzf-history-uniq() {
selected=$(
history 0 \
| awk '{
match($0, /^ *([0-9]+) *(.*)$/, r);
num=r[1]; cmd=r[2];
if(s[cmd]=="") { print cmd; s[cmd]=1; } }' \
| fzf --tac )
BUFFER="$selected"
zle end-of-line
@koreyou
koreyou / bm25.py
Created November 1, 2019 05:26
Implementation of OKapi BM25 with sklearn's TfidfVectorizer
""" Implementation of OKapi BM25 with sklearn's TfidfVectorizer
Distributed as CC-0 (https://creativecommons.org/publicdomain/zero/1.0/)
"""
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from scipy import sparse
class BM25(object):
@jgoday
jgoday / main.rs
Created October 23, 2019 10:06
Postgres async notifications with tokio_postgres
#![feature(poll_map)]
use futures::{stream, StreamExt};
use futures::{FutureExt, TryStreamExt};
use std::env;
use tokio::sync::mpsc;
use tokio_postgres::{connect, NoTls};
#[tokio::main]
async fn main() {
let connection_parameters = env::var("DBURL").unwrap();
@amirasaran
amirasaran / smtp_server.py
Last active March 20, 2024 12:00
Python3 SMTP (smtpd) Mail Server with authentication sample + smtpd TLS support
import asynchat
import base64
import ssl
import asyncore
from smtpd import SMTPServer as BaseSMTPServer, SMTPChannel as BaseSMTPChannel, DEBUGSTREAM
def decode_b64(data):
"""Wrapper for b64decode, without having to struggle with bytestrings."""
@gene1wood
gene1wood / change-github-collaborators-permissions.md
Last active December 2, 2022 11:08
How to edit or modify a GitHub user's permissions on a repository through the API

The GitHub API is inconsistent for this endpoint. Normally to edit or modify a resource, the REST API uses the PATCH verb.

For the https://developer.github.com/v3/repos/collaborators/ endpoint however, to edit or modify a user's permissions, there is no PATCH verb. Instead you must make a PUT call defining the new permissions.

The documentation confusingly describes this as "Add user as a collaborator" when the user you're modifying already is a collaborator, you just want to change their permissions.

Here is an example call to change a user with push permissions to pull permissions

@omaraboumrad
omaraboumrad / splitlogs.py
Created October 6, 2017 14:18
View docker-compose services logs in split tmux panes
# Requires pyyaml
import os
import yaml
run = os.system
new_window = lambda cmd: run('tmux new-window -n "logs" "{}"'.format(cmd))
split_vertical = lambda cmd: run('tmux split-window "{}"'.format(cmd))
split_horizontal = lambda cmd: run('tmux split-window -h "{}"'.format(cmd))
even_vertical = lambda: run('tmux select-layout even-vertical')
@northox
northox / iked.conf
Last active September 10, 2021 17:42
OpenBSD's OpenIKEd roadwarrior VPN config for Ipad and such
ikev2 "inet" passive ipcomp esp \
from 0.0.0.0/0 to 10.0.1.0/24 \
from 10.0.0.0/24 to 10.0.1.0/24 \
local egress peer any \
srcid egress \
psk "strong-password" \
config protected-subnet 0.0.0.0/0 \
config address 10.0.1.0/24 \
config name-server 10.0.0.1 \
tag IKED
@syedrakib
syedrakib / RSA_example.py
Last active June 21, 2024 19:48
An example of asymmetric encryption in python using a public/private keypair - utilizes RSA from PyCrypto library
# Inspired from http://coding4streetcred.com/blog/post/Asymmetric-Encryption-Revisited-(in-PyCrypto)
# PyCrypto docs available at https://www.dlitz.net/software/pycrypto/api/2.6/
from Crypto import Random
from Crypto.PublicKey import RSA
import base64
def generate_keys():
# RSA modulus length must be a multiple of 256 and >= 1024
modulus_length = 256*4 # use larger value in production