Skip to content

Instantly share code, notes, and snippets.

@kix2mix2
kix2mix2 / kcng.py
Created January 27, 2020 16:53
K-Nearest Center of Gravity Graph (KNCG)
def get_kncg(df, K=4):
# df is a pandas dataframe with mandatory columns ['x','y']
graph = get_knntree(df, 1)
for node_a, row in df.iterrows():
if node_a % KK_prints == 0:
print(K)
node_a_coord = list(row[:2])
ncns = []
@gboone
gboone / midpoint
Created November 28, 2015 23:47
How to find a geographic midpoint in js
function setLatLng(dataset) {
var lat = dataset.lat
var lng = dataset.lng
return new L.LatLng(lat, lng)
}
function latLngRadians(dataset) {
return _.map(dataset, function(item) {
var latRad = item.lat*(Math.PI/180)
var lngRad = item.lng*(Math.PI/180)
@paulodeleo
paulodeleo / .tmux.conf
Last active July 15, 2022 10:16
Tmux configuration to enable mouse scroll and mouse panel select, taken from: http://brainscraps.wikia.com/wiki/Extreme_Multitasking_with_tmux_and_PuTTY
# Make mouse useful in copy mode
setw -g mode-mouse on
# Allow mouse to select which pane to use
set -g mouse-select-pane on
# Allow mouse dragging to resize panes
set -g mouse-resize-pane on
# Allow mouse to select windows
@thatrand0mnpc
thatrand0mnpc / custom_traceback_example.py
Last active August 1, 2022 21:22
Python custom traceback
import linecache
import re
import sys
from types import TracebackType
from typing import Any, Dict, List, Optional
PACKAGE_PATH_PATTERN = r'.*/lib/python.*/site-packages/.*'
class TracebackLogger:
@leommoore
leommoore / mongodb_ssl_with_letsencrypt.md
Last active August 16, 2022 17:35
MongoDB 3.2.x SSL with Letsencrypt

MongoDB 3.2.x SSL with Letsencrypt

Letsencrypt is an initative which aims to increase the use of encryption for websites. It basically allows people to apply for free certificates provided that they prove the they control the requested domain. We will look at the what is needed to secure your MongoDB installation. For more details on setting up a MongoDB server see MongoDB 3.2.x.

Set the hostname

We sould to set the hostname to match the name of the certificate we are going to optain.

sudo hostname mongo0.example.com

Then update the hostname file to set the server name permanently.

@pankaj28843
pankaj28843 / set_outer_border_for_range_xlsx.py
Last active September 1, 2022 21:48
A simple hack - set outer border for a range using xlsxwriter, a Python library
from __future__ import absolute_import
try:
import cStringIO as StringIO
except ImportError:
import StringIO
# Standard Library
import re
import string
@xeoncross
xeoncross / ngrams.go
Last active September 27, 2022 09:28
Simple golang ngrams, bigrams, trigrams, and just plain word pair counter from any given slice of strings.
package main
import (
"fmt"
"math"
"strings"
"unicode"
)
// SplitOnNonLetters splits a string on non-letter runes
@abimaelmartell
abimaelmartell / default_gateway.go
Created October 19, 2016 18:52
Get default gateway by parsing RIB information using the net/route package. BSD Only.
package main
import (
"fmt"
"golang.org/x/net/route"
)
var defaultRoute = [4]byte{0, 0, 0, 0}
func main() {
@jftuga
jftuga / bufWrite.go
Created September 9, 2019 09:18
demonstrates how to either write to STDOUT or to a buffer in golang
// demonstrates how to either write to STDOUT or to a buffer
package main
import (
"bufio"
"fmt"
"os"
)
@jerieljan
jerieljan / btt-screenshot.sh
Created May 22, 2021 13:32
Screenshot OCR with BetterTouchTool on MacOS
#!/usr/bin/env bash
# Usage:
# - Install `tesseract` with `brew install tesseract`
# - In BetterTouchTool, create a trigger of your choice.
# (I recommend a Keyboard Shortcut with Cmd+Shift 6)
# - Add an Execute Shell Script / Task action
# - Paste this script.
# NOTE: You'll need to authorize BTT to the Screen Recording permission in Security and Privacy at System Preferences