Skip to content

Instantly share code, notes, and snippets.

View ortsed's full-sized avatar

Llewellyn Jones ortsed

View GitHub Profile
@marnixkoops
marnixkoops / target_encoder.py
Last active February 5, 2022 16:49
Target Encoding in Python
import pandas as pd
import numpy as np
from custom_code import timefold
from sklearn import preprocessing
def target_encoder(df, column, target, index=None, method='mean'):
"""
Target-based encoding is numerization of a categorical variables via the target variable. Main purpose is to deal
@Den1al
Den1al / pandas-explode.py
Created November 29, 2018 09:05
An implementation of HIVE's explode function in pandas
def explode(df, by_column, new_col_name):
rows = []
for row in df.itertuples():
for value in getattr(row, by_column):
rows.append({
new_col_name: value,
**{
key: getattr(row, key)
for key in row._fields
@jart
jart / lolc.sh
Last active June 7, 2023 15:44
Run C code in Bash
#!/bin/bash
# lolc.sh - run c code in bash
# by justine tunney <[email protected]>
# licensed mit or apache 2.0
runc() {
local bin=$(mktemp -u)
gcc -xc -o ${bin} /dev/stdin || return
chmod u+x ${bin}
${bin} "$@"
@tartakynov
tartakynov / fourex.py
Last active December 20, 2024 08:10
Fourier Extrapolation in Python
import numpy as np
import pylab as pl
from numpy import fft
def fourierExtrapolation(x, n_predict):
n = x.size
n_harm = 10 # number of harmonics in model
t = np.arange(0, n)
p = np.polyfit(t, x, 1) # find linear trend in x
x_notrend = x - p[0] * t # detrended x
@Kartones
Kartones / postgres-cheatsheet.md
Last active April 14, 2026 10:12
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
anonymous
anonymous / django-1.4.1-with-hints
Created October 16, 2012 20:59
Django 1.4.1 SQL Hints Patch
diff --git a/db/models/query.py b/db/models/query.py
index 44acadf..a241fbd 100644
--- a/db/models/query.py
+++ b/db/models/query.py
@@ -90,7 +90,7 @@ class QuerySet(object):
return len(self._result_cache)
def __iter__(self):
- if self._prefetch_related_lookups and not self._prefetch_done:
+ if hasattr(self, "_prefetch_related_lookups") and self._prefetch_related_lookups and not self._prefetch_done:
@richieforeman
richieforeman / makeauthority.sh
Created July 23, 2012 21:38
Issue Your Own Self-Signed S/MIME Certs with OpenSSL
# Run this once
openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt