Skip to content

Instantly share code, notes, and snippets.

View enjoylife's full-sized avatar
📖

Matthew Clemens enjoylife

📖
View GitHub Profile
@enjoylife
enjoylife / rename.sh
Created March 21, 2024 12:06
Rename all files recursively (Git aware)
#!/bin/bash
# Get the substring to replace and the replacement string
read -p "Enter substring to replace: " old_string
read -p "Enter replacement string: " new_string
# Function to rename files recursively
rename_files () {
for filename in *; do
# Check if filename contains the old string
@enjoylife
enjoylife / Scan.py
Created April 3, 2012 05:56
Python implementation of SCAN: A Structural Clustering Algorithm for Networks
# -*- coding: utf-8 -*-
"""
SCAN: A Structural Clustering Algorithm for Networks
As described in http://ualr.edu/nxyuruk/publications/kdd07.pdf
"""
from collections import deque
import numpy as np
from scipy.sparse import csr_matrix
@enjoylife
enjoylife / timeconv.h
Created December 27, 2012 00:15
convert timespec structures to timeval and vice versa.
#ifndef TIMEVAL_TO_TIMESPEC
#define TIMEVAL_TO_TIMESPEC(tv, ts) \
do { \
(ts)->tv_sec = (tv)->tv_sec; \
(ts)->tv_nsec = (tv)->tv_usec * 1000; \
} while (0)
#endif
#ifndef TIMESPEC_TO_TIMEVAL
#define TIMESPEC_TO_TIMEVAL(tv, ts) \
do { \
@enjoylife
enjoylife / gist:1337872
Created November 3, 2011 21:42
testing of Flask and Neo4j
import os
import jpype
from neo4j import GraphDatabase
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash
app = Flask(__name__)
app.config.from_object(__name__)
app.config['ADMIN'] ='Matthew'
app.config['DATABASE']='/tmp/graphtest'
@enjoylife
enjoylife / machine.js
Last active August 29, 2022 05:57
Generated by XState Viz: https://xstate.js.org/viz
// Immer
// ...
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).immer={})}(this,function(e){"use strict";var r,t="undefined"!=typeof Symbol?Symbol("immer-nothing"):((r={})["immer-nothing"]=!0,r),n="undefined"!=typeof Symbol&&Symbol.for?Symbol.for("immer-draftable"):"__$immer_draftable",o="undefined"!=typeof Symbol&&Symbol.for?Symbol.for("immer-state"):"__$immer_state";function i(e){return!!e&&!!e[o]}function a(e){return!!e&&(function(e){if(!e||"object"!=typeof e)return!1;if(Array.isArray(e))return!0;var r=Object.getPrototypeOf(e);return!r||r===Object.prototype}(e)||!!e[n]||!!e.constructor[n])}var f=Object.assign||function(e,r){for(var t in r)l(r,t)&&(e[t]=r[t]);return e},s="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames;function c(e,r){
@enjoylife
enjoylife / IslandCounting.js
Last active July 18, 2021 09:37
Given a matrix of 0s and 1s, where 0 represents water and 1 represents land, count the number of islands. Two pieces of land are connected if they are vertically or horizontally touching. Two pieces of land that are diagonal from each other are not touching.
// our simple example to play with
let island = [
[1, 1, 0, 0, 0],
[0, 1, 0, 0, 1],
[1, 0, 0, 1, 1],
[0, 0, 0, 0, 0],
[1, 0, 1, 0, 1]
];
@enjoylife
enjoylife / convert.sh
Created January 22, 2021 18:15
input to gif
ffmpeg -i my-movie.mov -ss 00:00:00 -filter_complex "[0:v] fps=12,scale=1024:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" output.gif
func withTimeout(ctx context.Context, f func(context.Context) error) error {
c := make(chan error, 1)
go func() { c <- f(ctx) }()
select {
case <-ctx.Done():
return ctx.Err()
case err := <-c:
return err
}
@enjoylife
enjoylife / template.sh
Last active June 23, 2020 21:02
A stereotypical bash template with simple example patterns. Useful when creating scripts....
#!/bin/bash
# Exit immediately for non zero status
set -e
# Check unset variables
set -u
# Print commands
set -x
# Prevent acciedently running as root
@enjoylife
enjoylife / triangulation.py
Created June 10, 2020 22:59 — forked from davegreenwood/triangulation.py
Triangulate image points to world points comparing openCV to pure python.
from __future__ import print_function
import numpy as np
import cv2
import time
np.set_printoptions(formatter={'float': '{: 0.3f}'.format})
def triangulate_nviews(P, ip):
"""