Skip to content

Instantly share code, notes, and snippets.

View MarcelRobitaille's full-sized avatar

Marcel Robitaille MarcelRobitaille

View GitHub Profile
@IamPhytan
IamPhytan / ode_example_sympy.py
Last active February 11, 2020 12:32
ODE Examples in Sympy
import sympy as sym
import numpy as np
import matplotlib.pyplot as plt
sym.init_printing()
# Integral calculation constants
a = 0
b = 20
h = 0.4
@the-bass
the-bass / rename_state_dict_keys.py
Last active January 1, 2024 08:28
Rename the parameters of a PyTorch module's saved state dict. Last tested with PyTorch 1.0.1.
import torch
from collections import OrderedDict
def rename_state_dict_keys(source, key_transformation, target=None):
"""
source -> Path to the saved state dict.
key_transformation -> Function that accepts the old key names of the state
dict as the only argument and returns the new key name.
target (optional) -> Path at which the new state dict should be saved
@islander
islander / fsck_qcow2.md
Last active May 10, 2024 01:50
Recover a qcow2 image using fsck

Recover a qcow2 image using fsck

Load network block device module:

# modprobe nbd max_part=8

Poweroff machine:

# virsh destroy virtual-machine

@fyrebase
fyrebase / .svgo.yml
Created October 1, 2016 10:34
Convert dimensions to viewBox - SVGO Plugin
plugins:
...
- convertDimensions
...
@joepie91
joepie91 / .md
Last active May 7, 2024 09:12
Running a Node.js application using nvm as a systemd service

Read this first!

Hi there! Since this post was originally written, nvm has gained some new tools, and some people have suggested alternative (and potentially better) approaches for modern systems. Make sure to have a look at the comments to this article, before following this guide!


The original article

Trickier than it seems.

@mdsrosa
mdsrosa / dijkstra.py
Created November 21, 2015 04:36
Modified Python implementation of Dijkstra's Algorithm (https://gist.github.com/econchick/4666413)
from collections import defaultdict, deque
class Graph(object):
def __init__(self):
self.nodes = set()
self.edges = defaultdict(list)
self.distances = {}
def add_node(self, value):
@hellpanderrr
hellpanderrr / vector_intersection.md
Last active April 2, 2023 18:45
Python find intersection of two vectors using matplotlib and numpy
from numpy import dot,array,empty_like
from matplotlib.path import Path

def make_path(x1,y1,x2,y2):
    return Path([[x1,y1],[x1,y2],[x2,y2],[x2,y1]])

def perp( a ) :
    b = empty_like(a)
 b[0] = -a[1]
@stevermeister
stevermeister / git pre-push hook
Created March 12, 2015 15:52
git pre-push hook to run tests
#!/bin/sh
# check for how many uncommitted changes we have
# stash changes
# run grunt task
# restore stashed files if anything was stashed
# exit with error if grunt fails
NAME=$(git branch | grep '*' | sed 's/* //')
@leehsueh
leehsueh / boolparser.py
Created October 16, 2011 09:07
Python Boolean Expression Parser/Evaluator
"""
Grammar:
========
Expression --> AndTerm { OR AndTerm}+
AndTerm --> Condition { AND Condition}+
Condition --> Terminal (>,<,>=,<=,==) Terminal | (Expression)
Terminal --> Number or String or Variable
Usage:
======