Skip to content

Instantly share code, notes, and snippets.

View lambdaofgod's full-sized avatar
🤗
opensource

Jakub Bartczuk lambdaofgod

🤗
opensource
View GitHub Profile
@lambdaofgod
lambdaofgod / nocode.tpl
Last active October 23, 2016 12:08
Jupyter nbconvert template for hiding code cells
{% add --template=nocode.tpl to nbconvert command %}
{%- extends 'full.tpl' -%}
{% block input_group %}
{%- endblock input_group %}
@lambdaofgod
lambdaofgod / Breeze.md
Last active January 23, 2017 18:54
Breeze in Ammonite REPL (or Scala Jupyter kernel)
import $ivy.`org.slf4j:slf4j-api:1.7.21`
import $ivy.`org.scalanlp:breeze_2.11:0.12`
import $ivy.`org.scalanlp:breeze-natives_2.11:0.12`
@lambdaofgod
lambdaofgod / gamma.py
Last active April 13, 2024 15:18
Gamma coding in Python
from bitarray import bitarray
# see https://nlp.stanford.edu/IR-book/html/htmledition/gamma-codes-1.html
def gamma_code(n):
binary_n = format(n, 'b')
binary_offset = binary_n[1::]
unary_length = bitarray(True for i in range(len(binary_offset))) + bitarray([False])
return bitarray(unary_length), bitarray(binary_offset)
@lambdaofgod
lambdaofgod / colab_dataloading.py
Created February 17, 2018 11:37
Colab - fetching data from Google Drive
from toolz import compose
from google.colab import auth
from googleapiclient.discovery import build
import io
from googleapiclient.http import MediaIoBaseDownload
import pickle
"""
Load (pickled) data files from Google Drive
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
pip install gensim seaborn wordcloud rank_bm25
pip install git+https://github.com/lambdaofgod/mlutil
@lambdaofgod
lambdaofgod / download_images.py
Last active September 18, 2019 12:59
Download images given links in csv file
import fire
import tqdm
from concurrent.futures import ProcessPoolExecutor
import pandas as pd
import skimage.io
import os
from PIL import Image
import requests
from io import BytesIO
import mlutil.parallel
@lambdaofgod
lambdaofgod / load_image_from_url.py
Last active March 5, 2024 19:06
Load image from url with requests using headers (this circumvents failing skimage.io.imread)
import requests
from PIL import Image
from io import BytesIO
import numpy as np
headers = {
'user-agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
}
df = read.table('CH01PR20.txt', header=FALSE)
x = df[,2]
y = df[,1]
n = dim(df)[1]
plot(x, y)
@lambdaofgod
lambdaofgod / get_everything_from_index.py
Created November 4, 2019 15:36
get all records from elasticsearch index
from elasticsearch_dsl import Search
def get_everything_from_index(es, index):
search_results = Search(index=index).using(es).scan()
for hit in search_results:
yield hit.to_dict()