Skip to content

Instantly share code, notes, and snippets.

💚
What should I write here?

Philippe Rémy philipperemy

💚
What should I write here?
View GitHub Profile
View find_k_largest_elements_in_2d_array.py
import numpy as np
# FIND LARGEST K ELEMENTS IN A 2D ARRAY IN NUMPY
def find_k_largest_elements_in_2d_array(arr: np.array, k=1):
assert len(arr.shape) == 2
h, w = arr.shape
top_indices = np.flip(arr.flatten().argsort()[-k:])
return np.divmod(top_indices, w)
View sample.py
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
matplotlib.use('MACOSX')
img_h, img_w = 250, 500
img = np.zeros((img_h, img_w))
View keras_multi_gpu.py
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.applications import Xception
import numpy as np
num_samples = 1000
height = 224
width = 224
num_classes = 1000
@philipperemy
philipperemy / selenium_download_file.py
Created Apr 9, 2020
Chromedriver headless download file
View selenium_download_file.py
def new_chrome_browser(headless=True, download_path=os.path.dirname(os.path.abspath(__file__))):
"""Helper function that creates a new Selenium browser"""
options = webdriver.ChromeOptions()
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36'
if headless:
options.add_argument('headless')
options.add_argument('--window-size=1280x1024')
options.add_argument('--disable-gpu')
# options.add_argument(f'user-agent={user_agent}')
if download_path is not None:
View get_tinder_token.py
import json
import requests
CODE_REQUEST_URL = "https://graph.accountkit.com/v1.2/start_login?access_token=AA%7C464891386855067%7Cd1891abb4b0bcdfa0580d9b839f4a522&credentials_type=phone_number&fb_app_events_enabled=1&fields=privacy_policy%2Cterms_of_service&locale=fr_FR&phone_number=#placeholder&response_type=token&sdk=ios"
CODE_VALIDATE_URL = "https://graph.accountkit.com/v1.2/confirm_login?access_token=AA%7C464891386855067%7Cd1891abb4b0bcdfa0580d9b839f4a522&confirmation_code=#confirmation_code&credentials_type=phone_number&fb_app_events_enabled=1&fields=privacy_policy%2Cterms_of_service&locale=fr_FR&login_request_code=#request_code&phone_number=#phone_number&response_type=token&sdk=ios"
TOKEN_URL = "https://api.gotinder.com/v2/auth/login/accountkit"
HEADERS = {
@philipperemy
philipperemy / r-deps.sh
Created Oct 15, 2019
R package manager (kind of) - Find and install all dependencies of your R project.
View r-deps.sh
set -e
PACKAGES="$(find . -type f -iname "*.R" -exec cat {} + | grep "^library" | sed 's/library(//g' | cut -d ')' -f 1 | sed -e 's/^"//' -e 's/"$//' | sort -u | xargs)"
for package in $PACKAGES;
do
echo "Installing package: ${package}..."
rscript -e "install.packages('${package}', repos='https://cran.rstudio.com')"
done
@philipperemy
philipperemy / extract.sh
Last active Jun 22, 2018
Mac OS - extract handshakes from CAP files of airport command
View extract.sh
# On Mac OSX
# Will run AIRODUMP scan of all BSSIDs
# sudo airport -s
# Will run AIRODUMP sniff on channel 11
# sudo airport en0 sniff 11
# Atm, I can't find how to sniff on all channels at the same time.
if [ $# -eq 0 ]
View cpu-burner.py
#!/usr/bin/env python
"""
Produces load on all available CPU cores
"""
from multiprocessing import Pool
from multiprocessing import cpu_count
def f(x):
while True:
@philipperemy
philipperemy / install.sh
Created Dec 23, 2017
Install Neural Style Transfer
View install.sh
# Ubuntu:14.04 - 64 bits
# MINIMUM IS 8GB OF RAM.
curl -sk https://raw.githubusercontent.com/torch/ezinstall/master/install-deps | bash
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; ./install.sh
. ~/.bashrc # or: . ~/.zshrc
luarocks install nn
luarocks install nngraph
View count_stars.js
var https = require('https'),
user = process.argv[2],
opts = parseOpts(process.argv.slice(3))
request('/users/' + user, function (res) {
if (!res.public_repos) {
console.log(res.message)
return
}
var pages = Math.ceil(res.public_repos / 100),
You can’t perform that action at this time.