Skip to content

Instantly share code, notes, and snippets.

@ny0m
ny0m / dataframe_requires.py
Last active November 22, 2019 19:05
A nice way to accept Pandas DataFrames as function arguments. Read more: https://brr.ai/posts/dataframe/
def dataframe_requires(column_names: List[str]):
"""
Wraps a function that takes a pandas.DataFrame as its first argument.
Ensures that functions wrapped by this can safely assume that the required
columns are available.
Also ensures that a copy of the given dataframe is used by the function to
prevent modifying parent dataframes kept in memory.
@ny0m
ny0m / dataframe_requires.py
Last active November 22, 2019 14:52
A nice way to accept Pandas DataFrames as function arguments. Read more: https://brr.ai/posts/dataframe/
def dataframe_requires(column_names: List[str]):
"""
Wraps a function that takes a pandas.DataFrame as its first argument.
Ensures that functions wrapped by this can safely assume that the required
columns are available.
Also ensures that a copy of the given dataframe is used by the function to
prevent modifying parent dataframes kept in memory.

Keybase proof

I hereby claim:

  • I am bradmerlin on github.
  • I am melin (https://keybase.io/melin) on keybase.
  • I have a public key ASCpXHWN4Pt1oQSO_ugKcQDqAe2G-i4kqKR7oUMJJYGSWwo

To claim this, I am signing this object:

@ny0m
ny0m / plot.js
Created June 12, 2013 13:07
Function I use to plot menu items around a fixed point on http://cmnd.li
function plot(points, diameter, offset){
var x, y,
angle = 0,
links = $('nav a'),
increase = Math.PI * 2 / points;
for (var i=0; i <= points; i++) {
x = diameter * Math.cos(angle) + offset
y = diameter * Math.sin(angle) + offset
angle += increase
@ny0m
ny0m / REM-unit-polyfill+@media.js
Last active December 18, 2015 09:59
Some additions to REM-unit-polyfill to prevent it from cycling through styles enclosed in @media queries in browsers that don't support them.
// Test for Media Query support
mediaQuery = function() {
if (window.matchMedia || window.msMatchMedia) { return true; }
return false;
}
// Remove queries.
removeMediaQueries = function(css) {
if (!mediaQuery()) {
while (css.match(/@media/) !== null) { // If CSS syntax is correct there should always be a "@media" str matching a "}\s*}" string
@ny0m
ny0m / jplayer.draggable.js
Last active December 15, 2017 16:58
A snippet to make jPlayer volume bar draggable.
$('.jp-volume-bar').mousedown(function() {
var parentOffset = $(this).offset(),
width = $(this).width();
$(window).mousemove(function(e) {
var x = e.pageX - parentOffset.left,
volume = x/width
if (volume > 1) {
$("#JPID").jPlayer("volume", 1);
} else if (volume <= 0) {
$("#JPID").jPlayer("mute");
@ny0m
ny0m / fix_title.php
Last active December 18, 2015 00:38
PHP function to fix Wordpress error "Undefined property: stdClass::$labels in general-template.php (for this Trac ticket: http://core.trac.wordpress.org/ticket/20994). I needed it to fix the title send in an RSS feed for my custom taxonomy, but helps with quite a few edge cases. Just paste into functions.php
<?php
add_action('pre_get_posts', 'fix_title');
function fix_title(){
global $wp_query;
if ( $wp_query->is_post_type_archive && $wp_query->is_tax ) {
global $queried_object;
$queried_object = get_queried_object();
$queried_object->labels = new stdClass();
$queried_object->labels->name = $queried_object->name;
return $queried_object;
@ny0m
ny0m / slice.py
Created June 2, 2013 15:49
A python class to split a word into separate units, split into syllables, called morphemes. Part of a portmanteau generator I built.
class Slice(object):
def __init__(self, root, leng):
self.root = root # The original word
self.leng = leng # How many morphemes should be used as the prefix for the new portmanteau
self.morphemes = []
self.output = '' #
self.slice()
def slice(self):
import re