Skip to content

Instantly share code, notes, and snippets.

@nonsleepr
nonsleepr / officepy_repl.py
Created September 6, 2023 16:10
OfficePy REPL
import requests
from io import BytesIO
import sys
import json
OFFICEPY_HOST = "service-preview-p1-eastus2.officepy.microsoftusercontent.com"
USER_AGENT = "Microsoft Office/16.0 (Windows NT 10.0; Microsoft Excel 16.0.16827; Pro)"
GREEN = '\033[32m'

Keybase proof

I hereby claim:

  • I am nonsleepr on github.

  • I am nonsleepr (https://keybase.io/nonsleepr) on keybase.

  • I have a public key ASD2K73fCmJ6Ruf8af6CwpPQKYiBD3vk2tdhKIG1qydczgo

@nonsleepr
nonsleepr / demo.py
Created July 5, 2018 21:13
Multiplexer for trio: my take on python-trio/trio#467
import trio
from multiplexer import Multiplexer
async def reader(mx, key, timeout=100):
print(f'Waiting for "{key}"...')
try:
with trio.fail_after(timeout):
value = await mx[key]
print(f'Got value "{value}" for key {key}')
@nonsleepr
nonsleepr / Makefile
Created March 27, 2015 15:40
Makefile to download Kaggle's datasets
# Requires presence of credentials.txt file containing login/password in the following format:
# UserName=my_username&Password=my_password
COMPETITION=diabetic-retinopathy-detection
all: download_files
session.cookie: credentials.txt
curl -o /dev/null -c session.cookie https://www.kaggle.com/account/login
curl -o /dev/null -c session.cookie -b session.cookie -L -d @credentials.txt https://www.kaggle.com/account/login
@nonsleepr
nonsleepr / tokenizer.R
Created February 12, 2015 21:58
N-gram tokenizer function without any Java dependencies (like in RWeka)
ngrams.tokenizer <- function(x, n = 2) {
trim <- function(x) gsub("(^\\s+|\\s+$)", "", x)
terms <- strsplit(trim(x), split = "\\s+")[[1]]
ngrams <- vector()
if (length(terms) >= n) {
for (i in n:length(terms)) {
ngram <- paste(terms[(i-n+1):i], collapse = " ")
ngrams <- c(ngrams,ngram)
}
}
@nonsleepr
nonsleepr / kfold.R
Last active August 29, 2015 14:06
Implementation of K-fold cross validation
require(plyr)
kfold <- function(df, k, train.f, predict.f) {
progress.bar <- create_progress_bar("text")
progress.bar$init(k)
N <- nrow(df)
subsample.id <- sample(1:k, N, replace = TRUE)
r <- vector(length = N)
@nonsleepr
nonsleepr / kaggle.R
Created September 24, 2014 15:42
Set of functions to download datasets from Kaggle
### Set of functions to download datasets from Kaggle
# Usage:
#
# > train <- kaggle_get_file("train.csv",
# + competition.name = "titanic-gettingStarted",
# + username = "username",
# + password = "password")
#
# > head(train, n = 2)
@nonsleepr
nonsleepr / gist:afd37de1622d935995eb
Created July 2, 2014 06:14
DENSE_RANK for Teradata
-- Via http://forums.teradata.com/forum/database/dense-rank
SELECT
department_number,
/*** Syntax not implemented in Teradata ***/
DENSE_RANK() OVER (PARTITION BY department_number ORDER BY salary_amount),
last_name,
salary_amount
FROM employee;
@nonsleepr
nonsleepr / futurelearn_dl.sh
Last active October 25, 2015 09:09
FutureLearn Video downloader
#!/bin/bash
#
# Usage:
# > futurelearn_dl.sh login@email.com password course-name week-id
# Where *login@email.com* and *password* - your credentials
# ,*course-name* is the name from URL
# and *week-id* is the ID from the URL
#
# E.g. To download all videos from the page: https://www.futurelearn.com/courses/corpus-linguistics/todo/238
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.