This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.""" |
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
NewerOlder