Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Swierczewski cswiercz

View GitHub Profile
@cswiercz
cswiercz / plotting_example.py
Created Mar 23, 2020
Example pandas plotting by label
View plotting_example.py
import pandas as pd
import matplotlib.pyplot as plt
# obtain example dataset
iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
# get the matplotlib default color cycle
cycle = iter(plt.rcParams['axes.prop_cycle'].by_key()['color'])
# use pandas to plot by label
@cswiercz
cswiercz / .bashrc_ps1
Created Dec 19, 2019
Custom Bash Prompt
View .bashrc_ps1
# A custom prompt that looks like this:
#
# <NEWLINE>
# (conda-environment) (current-datetime) [current-full-directory]
# username@host $
#
# First clear the PS1 variable. This allows conda setup to populate the PS1 with
# the current anaconda environment before we create a custom prompt. Necessary
# because I want a newline before each prompt. (Maybe better way?)
#
@cswiercz
cswiercz / mnuk_conditions_fraction_fields.py
Created Feb 23, 2018
mnuk_conditions() Fraction Field Timing Test
View mnuk_conditions_fraction_fields.py
# coding: utf-8
# In[1]:
R = QQbar['x,y']
x,y = R.gens()
g1 = x^4 + x^2*y^2 + (-2)*x^2*y - x*y^2 + y^2
g2 = -x^7 + 2*x^3*y + y^3
@cswiercz
cswiercz / reference_wrappers.md
Last active May 11, 2020
C++11 Reference Wrappers
View reference_wrappers.md

My Problems (There Are Many)

The C++ standard library containers are nice. Like, really nice. As the kind of person who worries about performance to the point that they were shy of anything other than a raw data array I've come to appreciate the usability (and speed!) of ye olde std::vector. Does that many me sound like a wannabe oldie?

Recently I came across a situation where I had, say, a vector [a, b, c, d] and wanted to create the vectors [a, b, c], [a, b, d], [a, c, d], and [b, c, d]. I didn't want to actually allocate O(N(N-1)) additional memory but learned that std::vector didn't support holding references. That's when I came across std::reference_wrapper.

Reference Wrappers

From the Cppreference page:

@cswiercz
cswiercz / introduction-to-new-operators.md
Last active Jul 6, 2017
Introduction to Creating a New MXNet Operator
View introduction-to-new-operators.md

WIP - There is still much to learn.

Creating a New MXNet Operator

################################################################################ Let's begin by creating a simple, near-minimal working example. I'll start with the code and then walk through each component. We will create an operator, add_one() which will take a vector as input, add one to each element, and return the result.

@cswiercz
cswiercz / cached_factory.cpp
Last active Apr 3, 2017
Herb Sutter's favorite sub-10 line C++ snippet: Factory w/Cache
View cached_factory.cpp
/*
Cached Factory
Sometimes you want to make objects with a lifetime managed
by their target owner but you also want to hold reference
to them in a custom cache. The target owner, naturally, will
be given a shared_ptr to the output object. However, we don't
want the lifetime of the output object to be tied to the
internal cache. I.e. if the owner dies then the object should
die even if referenced in the cache.
@cswiercz
cswiercz / diagram.md
Created Jul 27, 2016
Testing sequence diagrams in GitHub.
View diagram.md

Sequence Diagrams in GitHub

js-sequence-diagrams turns text into UML sequence diagrams. However, jsseq and sequence code blocks do not automatically render in GitHub. A Google Chrome plugin Github sequence diagrams allows rendering of sequence diagrams within GitHub!

An Example Sequence Diagram

@cswiercz
cswiercz / RaceConditionProblem.md
Last active Jun 8, 2016
A race condition problem and solution from the AMath 483/583 final examination I wrote this Spring.
View RaceConditionProblem.md

Problem Statement

In the below OpenMP code, a shared memory location counter is being incremented by two threads, each thread incrementing counter 100 times. The incrementation process

counter += 1
@cswiercz
cswiercz / KnightsAndKnaves.md
Created May 17, 2016
A problem from my Advanced Mathematical Logic final when I was an undergraduate.
View KnightsAndKnaves.md

On the island of Tautologos, all of the inhabitants are either knights, who always tell the truth, or knaves, who always lie. In addition, some of the knights are called “established knights” and some of the knaves are called “established knaves”. Now, the inhabitants of this island form various clubs. It is possible that an inhabitant may belong to more than one club. Given any inhabitant X and any club C, either X claims they are a member of C or they claim they’re not a member of C.

We are also given the following four facts:

  • E1: The set of all established knights forms a club.
  • E2: The set of all established knaves forms a club.
  • C (The Complementation Condition): Given any club C, the set of all inhabitants of the island who are not members of C form a club of their own, CBar.
  • G (The Godelian Condition): Given any club C, there is at least one inhabitant of the island who claim that they are a member of C. (Of course, this claim might be false: they could be a
You can’t perform that action at this time.