Skip to content

Instantly share code, notes, and snippets.

🐐

Anders L. Hurum peakBreaker

🐐
Block or report user

Report or block peakBreaker

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@peakBreaker
peakBreaker / Arch.Dockerfile
Created Aug 16, 2019
Build an arch based dockerimage with yay for installing packages. Useful for testing bugs if they show up in arch
View Arch.Dockerfile
FROM archlinux/base:latest
# Basic dependencies
RUN pacman -Syu --noconfirm
RUN pacman -S tar curl sudo grep base-devel --noconfirm
RUN mkdir -p /opt/yay/
WORKDIR /opt/yay/
# Add the builduser (cant install yay as root)
RUN useradd builduser -m # Create the builduser
@peakBreaker
peakBreaker / analyzedocs.py
Last active Jul 10, 2019
A quick document analysis
View analyzedocs.py
"""
From documents to clusters
This script will run through a list of docs and process out the groups the docs may belong to using
cluster analysis, NMF and TF*IDF for preprocessing. These are some basic techniques for unsupervised NLP
which may be very handy.
"""
# For creating the data structure to process
View mytsne.py
# Import TSNE
from sklearn.manifold import TSNE
def run_tsne(samples):
# Create a TSNE instance: model
model = TSNE(learning_rate=200)
# Apply fit_transform to samples: tsne_features
tsne_features = model.fit_transform(samples)
@peakBreaker
peakBreaker / postproc_scikit_sample.py
Last active Jun 19, 2019
Postprocessing multiple scikit learn models probabilities and predictions to a multilevel dataframe
View postproc_scikit_sample.py
# Pred and prob arrays are numpy array outputs from a sklearn model:
# - pred_array = model.predict(X).astype(int)
# - prob_arr = model.predict_proba(X)
#
# Here we run the inital data through multiple models and structure the
# model output into a multilevel dataframe for probabilities and predictions
#
# Typically the next stage would be to enhance the labels of numerical results
# to string/categories or similar basaed on whatever we want, aswell as providing
# the results to a database or something like that
@peakBreaker
peakBreaker / statutils.py
Last active Jun 11, 2019
ecdf, correlation, bootstrapping
View statutils.py
def ecdf(data):
"""Compute ECDF for a one-dimensional array of measurements.
Very useful for graphical EDA
"""
# Number of data points: n
n = len(data)
# x-data for the ECDF: x
x = np.sort(data)
@peakBreaker
peakBreaker / analyze.md
Last active Jun 11, 2019
CodeAnalysis in Python
View analyze.md

Based on talk by James Powell - https://www.youtube.com/watch?v=mr2SE_drU5o

Static Analysis

  1. cloc
  2. find -iname '*.' | xargs cat | sort | uniq -c | sort -nr
  3. Python:
from subprocess import check_output
files = check_output('find -iname *.<type>'.split())\
@peakBreaker
peakBreaker / get_filename.py
Last active Nov 26, 2018
Gets the filename, no extention from the script running this code.
View get_filename.py
# Get filename, whcih can be used for script identification
filename_no_ext = path.splitext(path.basename(__file__))[0]
@peakBreaker
peakBreaker / daterange.py
Last active Nov 26, 2018
Iterating through historical data until today
View daterange.py
import datetime
# Set the config for the date iterator
start_date = datetime.datetime(2018, 9, 10)
end_date = datetime.datetime(2018, 11, 20)
d = start_date
delta = datetime.timedelta(days=1)
# Iterate from start date, adding delta with every iteration
while d <= end_date:
View PageTable.tex
%%
%% Full page table test
%%
\documentclass[12pt]{article}
\pagenumbering{gobble}
\usepackage{tabularx}
\newcolumntype{C}{>{\hsize=.5\hsize}X}
\usepackage[left=1cm, right=1cm, top=1cm, bottom=1cm]{geometry}
View cuphead.sh
# Program to enable avahi service discovery of printers and CUPS
# In Arch Linux
#
## First install the needed programs
sudo pacman -S cups nss-mdns
## Add user to cups group
sudo usermod -a -G cups <USER>
## Alter the hosts line to be like this
# hosts: ... mdns_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns ...
You can’t perform that action at this time.