Skip to content

Instantly share code, notes, and snippets.

View kimbo's full-sized avatar

Kimball Leavitt kimbo

View GitHub Profile
@kimbo
kimbo / scrape-doh-providers.py
Last active March 10, 2024 20:49
Scrape DoH provider URLs from cURL's wiki page (see https://raw.githubusercontent.com/wiki/curl/curl/DNS-over-HTTPS)
#!/usr/bin/env python
#
# Scrape Doh provider URLs from Curl's DNS-over-HTTPS wiki (https://raw.githubusercontent.com/wiki/curl/curl/DNS-over-HTTPS).
#
# Example usage: ./scrape_doh_providers.py '"{} - {}".format(o["url"], o["name"])'
#
import argparse
import re
import urllib.request
@kimbo
kimbo / upload.py
Created September 29, 2019 03:50
simple s3 file upload script
import argparse
import os
import sys
import threading
import boto3
from botocore.exceptions import ClientError
def get_buckets():
@kimbo
kimbo / readfile.py
Last active May 2, 2019 16:40
Use tqdm while reading a file (without reading the entire file into memory)
import subprocess
import tqdm
import os
import argparse
def get_line_count(file):
abs_path = os.path.abspath(file)
completed_process = subprocess.run(args=['wc', '-l', abs_path], check=True, encoding='utf-8',
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
nc towel.blinkenlights.nl 23
@kimbo
kimbo / itoa.c
Created February 6, 2019 21:22
Convert an int to a char * pointer
/*
* itoa - convert an int to a str with the given base.
* My own implementation with LOTS of explanation
*
*/
char *itoa(int val, int base) {
// make sure base is supported
if (base < 2 || base > 16) {
return NULL;
@kimbo
kimbo / stdev.py
Created October 25, 2018 22:17
Standard deviation functions
from math import sqrt
test_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
pstd_dev = lambda data: sqrt(sum([((sum(data) / len(data)) - x)**2 for x in data]) / len(data))
std_dev = lambda data: sqrt(sum([((sum(data) / len(data)) - x)**2 for x in data]) / (len(data) - 1))
print(pstd_dev(test_data))
print(std_dev(test_data))
@kimbo
kimbo / file_perms.txt
Created October 16, 2018 19:54
Linux File Permissions Reference
- Found this on http://www.december.com/unix/ref/chmod.html -
File permissions
Use the chmod command to set file permissions.
The chmod command uses a three-digit code as an argument.
The three digits of the chmod code set permissions for these groups in this order:
Owner (you)
Group (a group of other users that you set up)
@kimbo
kimbo / url_params.js
Last active October 2, 2018 21:29
Get url query string params in javascript
// using URLSearchParams
// https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
let urlParams = new URLSearchParams(window.location.search);
let something = url_params.get('something');
// other way (also works with window.location.hash)
let urlParams = {};
window.location.search.substr(1).split('&').forEach((param) => {
let x = param.split('=');
urlParams[x[0]] = x[1];
@kimbo
kimbo / template_filters.py
Last active October 8, 2018 12:22
Simple django template filters to add attributes to Django form fields
from django import template
register = template.Library()
@register.simple_tag()
def render(field, attrs, val=None):
"""
Renders a form field as a widget with the attributes you specify (separated by commas)
Example usage: {% render field 'class="form-control is-invalid", required' field.value %}
"""
for attr in attrs.split(', '):
@kimbo
kimbo / git_count.sh
Created September 9, 2018 17:09
Get number of lines committed by a given person in a repo.
git log --author="<author_name>" --pretty=tformat: --numstat | awk '{print $1}' | grep "^[0-9]" | paste -sd+ | bc