Skip to content

Instantly share code, notes, and snippets.

@lucgiffon
lucgiffon / generate_dandom_point.py
Created March 8, 2023 08:47
Generate random element in geoseries polygon Python
import random
from shapely.geometry import Point
def generate_random(number: int, polygon: gpd.GeoSeries):
"""
Select random point in polygon based on an inscribed circle of the polygon.
Parameters
----------
@lucgiffon
lucgiffon / gist:662b1440412d2737d6598144acb8e1e1
Created December 14, 2022 09:39
Pretty Format /usr/bin/time (source: Emmanuel Quemener ENS de Lyon CBP)
export TIME='TIME Command being timed: "%C"
TIME User time (seconds): %U
TIME System time (seconds): %S
TIME Elapsed (wall clock) time : %e
TIME Percent of CPU this job got: %P
TIME Average shared text size (kbytes): %X
TIME Average unshared data size (kbytes): %D
TIME Average stack size (kbytes): %p
TIME Average total size (kbytes): %K
TIME Maximum resident set size (kbytes): %M
@lucgiffon
lucgiffon / visibility_startpage_ads.js
Created December 18, 2021 16:50
Tampermonkey script to make ads more visible on startpage
// ==UserScript==
// @name Ads visibility on startpage
// @description Background-color is added to ads on the startpage site so they are made more visible.
// @version 0.1
// @author You
// @match https://www.startpage.com/*
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle("#adBlock > * { background-color: #e6e6ff; }");
@lucgiffon
lucgiffon / disable_reddit_comments.js
Last active December 22, 2021 16:53
Tampermonkey script to disable comments on various websites
// ==UserScript==
// @name Disable comments
// @description Make reddit comments invisible.
// @version 0.1
// @author You
// @grant GM_addStyle
// @match https://*.reddit.com/*
// @match https://*.youtube.com/*
// @match https://www.lefigaro.fr/*
// @match https://www.linkedin.com/*
@lucgiffon
lucgiffon / testgpu.py
Created September 30, 2019 13:02
Verify if tensorflow is capable of using a GPU
"""https://stackoverflow.com/a/43703735/4803860"""
import tensorflow as tf
with tf.device('/gpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
with tf.Session() as sess:
print (sess.run(c))
@lucgiffon
lucgiffon / cowsayfortune.sh
Created January 22, 2018 09:09
Cowsay tell fortune
if [ -x /usr/games/fortune -a -x /usr/games/cowsay ]; then
fortune -a | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n1)
fi
@lucgiffon
lucgiffon / np_to_tfrecords.py
Created December 20, 2017 16:10 — forked from swyoon/np_to_tfrecords.py
From numpy ndarray to tfrecords
import numpy as np
import tensorflow as tf
__author__ = "Sangwoong Yoon"
def np_to_tfrecords(X, Y, file_path_prefix, verbose=True):
"""
Converts a Numpy array (or two Numpy arrays) into a tfrecord file.
For supervised learning, feed training inputs to X and training labels to Y.
For unsupervised learning, only feed training inputs to X, and feed None to Y.
@lucgiffon
lucgiffon / mnist.py
Created November 29, 2017 17:38 — forked from akesling/mnist.py
import os
import struct
import numpy as np
"""
Loosely inspired by http://abel.ee.ucla.edu/cvxopt/_downloads/mnist.py
which is GPL licensed.
"""
def read(dataset = "training", path = "."):
'''
Implementation of Fastfood (Le, Sarlos, and Smola, ICML 2013).
Primarily by @esc (Valentin Haenel) and felixmaximilian
from https://github.com/scikit-learn/scikit-learn/pull/3665.
Modified by @dougalsutherland.
FHT implementation was "inspired by" https://github.com/nbarbey/fht.
'''
@lucgiffon
lucgiffon / gist:f874c43a0c25ff89ac17611c41cefbb0
Created June 29, 2017 08:42 — forked from lttlrck/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote