Skip to content

Instantly share code, notes, and snippets.

View sgraaf's full-sized avatar

Steven van de Graaf sgraaf

View GitHub Profile
@sgraaf
sgraaf / http_user_agent_functions.php
Last active August 6, 2017 22:09
A collection of three useful HTTP_USER_AGENT functions for the client IP, OS and Browser
// function to get the client ip address
function get_ip() {
$ipaddress = '';
if ($_SERVER['HTTP_CLIENT_IP'])
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if($_SERVER['HTTP_FORWARDED_FOR'])
@sgraaf
sgraaf / Bandcamp auto-renamer
Last active December 4, 2017 21:07
A simple script that auto-renames my chosen files and folders (after having downloaded them from bandcamp) to standardize them for my music library
import os
import mutagen
import sys
# function to find nth occurence of needle in haystack
def find_nth(haystack, needle, n):
start = haystack.find(needle)
while start >= 0 and n > 1:
start = haystack.find(needle, start+len(needle))
n -= 1
import java.util.Comparator;
import java.util.Random;
import java.util.Properties;
import java.util.Arrays;
public class FitnessComparator implements Comparator<double[]>{
@Override
public int compare(double[] entry1, double[] entry2) {
{
"_brand": "Mammut",
"_color_nos": [
"4072",
"50134"
],
"_colors": [
"Olive",
"Poseidon"
],
@sgraaf
sgraaf / transformers_vs_tokenizers.csv
Last active January 19, 2020 19:05
Tokenizers timing experiments: Transformers vs Tokenizers
implementation mean execution time
transformers 6min 42s
tokenizers 45.6s
@sgraaf
sgraaf / multithreaded.csv
Last active January 20, 2020 16:58
Tokenizers timing experiments: Multithreaded performance
implementation mean execution time
submit 1min 8s
map 1min 9s
encode_batch 10.6s
@sgraaf
sgraaf / Tokenizers_timing_experiment.ipynb
Last active January 20, 2020 17:01
Tokenizers timing experiments: Jupyter Notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sgraaf
sgraaf / tokenize_data.py
Created February 3, 2020 19:27
Simple python script to tokenize a English-language text data (sentences)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from pathlib import Path
from tokenizers import BertWordPieceTokenizer
def main():
in_file = Path(sys.argv[1])
@sgraaf
sgraaf / ReplacePositionedImage.gs
Last active July 6, 2020 09:25
Google Apps Script to replace a PositionedImage
/**
* Replace a PositionedImage by its ID.
*
* @param {Paragraph|ListItem} anchor The element (Paragraph or ListItem) to which the PositionedImage is anchored.
* @param {Number} positionedImageId The ID of the PositionedImage.
* @param {Blob} image The image used to replace the "old" PositionedImage with.
*/
function ReplacePositionedImage( anchor, positionedImageId, image ) {
// get the positioned image by its ID
var positionedImage = anchor.getPositionedImage(positionedImageId);
from typing import Tuple
def quadkey_to_xy(quadkey: str) -> Tuple[int, int]:
x, y = (0, 0)
level = len(quadkey)
for i in range(level):
bit = level - i
mask = 1 << (bit - 1)
if quadkey[level - bit] == '1':
x |= mask