Skip to content

Instantly share code, notes, and snippets.

@rguliev
rguliev / convert_pdf.py
Last active March 25, 2024 21:12 — forked from terencezl/convert_pdf.py
Python 3: pdfminer code to convert pdf to text, html or xml
# Use `pip3 install pdfminer.six` for python3
from typing import Container
from io import BytesIO
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter, XMLConverter, HTMLConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
@rguliev
rguliev / passenger_wsgi.py
Last active June 11, 2019 14:47
Passenger WSGI settings with virtualenv and StaticFilesHandler
# -*- coding: utf-8 -*-
import os, sys
sys.path.insert(0, '<abs path to the project>')
sys.path.insert(1, '<abs path to the venv>/lib/python3.6/site-packages')
# Use python from virtual env.
INTERP = os.path.expanduser("<abs path to the venv>/bin/python")
if sys.executable != INTERP:
os.execl(INTERP, INTERP, *sys.argv)
@rguliev
rguliev / hyperSpec_heatmap.R
Last active March 21, 2019 13:48
Plot spectra as heatmap with ggplot + hyperSpec
ggplot(as.long.df(spc), mapping = aes(x = .wavelength, y = spc)) +
geom_vline(aes(color=spc, xintercept=.wavelength)) +
facet_grid(group~.) +
scale_color_gradient2(low='white', mid='red', high='darkred',midpoint = 0.5)
@rguliev
rguliev / pre-commit
Last active November 9, 2020 14:59
A pre-commit hook to minify js & css files.
#!/bin/bash
# A pre-commit hook to update minified versions of
# css/js files on commit
# Go to the project's root
cd "$(dirname "$0")"
cd ../../
# Set up compression command
stat_smooth_func <- function(mapping = NULL, data = NULL,
geom = "smooth", position = "identity",
...,
method = "auto",
formula = y ~ x,
se = TRUE,
n = 80,
span = 0.75,
fullrange = FALSE,
level = 0.95,
@rguliev
rguliev / Caret Models Examples.R
Last active October 30, 2018 13:50
Caret code exmaples
fitControl <- trainControl(
method = 'LOOCV',
savePredictions = TRUE,
classProbs = TRUE,
summaryFunction = twoClassSummary)
fitControlOversampling <- trainControl(
method = 'LOOCV',
savePredictions = FALSE,
classProbs = TRUE,
@rguliev
rguliev / field.html
Created August 3, 2017 12:58
django-uni-form + Twitter Bootstrap
{% if field.is_hidden %}
{{ field }}
{% else %}
<div class="control-group {% if field.errors %}error{% endif %}">
<label for="{{ field.auto_id }}" {% if field.field.required %}class="control-label"{% endif %}>
{% if field.field.required %}<b>{% endif %}{{ field.label|safe }}{% if field.field.required %}*</b>{% endif %}
</label>
<div class="controls">
{{ field }}
{% if field.errors %}