Skip to content

Instantly share code, notes, and snippets.

View smac89's full-sized avatar

Nobleman smac89

View GitHub Profile
smac89 / sln.html
Last active August 29, 2015 14:19
CMPT 280 sample final tentative solutions
margin: 5px 0;
<ol type="a">
<li>(3 points) What are the three components that an Abstract Data Type has, regardless of the method of ADT specification used? <em>(Note: not looking for sets, syntax, semantics..." here, those are components of a specific ADT specification method.)</em><br/><br/>
smac89 /
Last active May 20, 2016 23:00
Version of python's string join which allows for random seperators
import random
def join_rand(words, *sep):
return reduce(lambda joined, new: random.choice(sep).join((joined, new)), words)
smac89 /
Created June 27, 2016 01:01
Converts drawable image to BitmapDrawable
import android.content.Context;
public static final class BitmapDrawableFromDrawable {
public static BitmapDrawable drawableToBitmapDrawable (Context ctx, Drawable drawable) {
Bitmap bitmap;
if (drawable instanceof BitmapDrawable) {
smac89 /
Last active August 29, 2016 16:16
[SOLVED] The struggle to print your u of s schedule without unnecessary details filling up the page

This is a method to get a clear, printable version of your uofs time table. This method involves a little work from you, then the attached app below does the rest. For this method to work well, you need to use firefox browser, as the end result looks off on chrome.

  1. Open your schedule in a browser:

  1. Right-click anywhere in the page and select Inspect Element:

  2. Inside the new window, type table.datadisplaytable into the search bar:

smac89 /
Last active November 29, 2016 05:45
Efficient method to read words from a file.
import itertools
def readwords(file_object):
byte_stream = itertools.groupby(
itertools.takewhile(lambda c: bool(c),
itertools.repeat(1))), str.isspace)
return ("".join(group) for pred, group in byte_stream if not pred)
smac89 / disjoint.hpp
Created May 9, 2017 17:04
Implementation of a disjoint_set data structure
#include <algorithm>
#include <iterator>
#include <unordered_set>
#include <vector>
class disjoint_set {
struct ranked { int root, rank, size; };
explicit disjoint_set(int n): cc(n + 1) {
smac89 / range.hpp
Last active May 9, 2017 17:04
C++ range implementation
#include <iostream>
#include <type_traits>
#include <limits>
#include <stdexcept>
template <typename I>
class range_t {
static_assert(std::is_integral<I>::value, "Integer type required");
class offset {
smac89 /
Last active June 8, 2017 06:38
Windows administrative Commands (Powershell)
smac89 / .gitconfig
Last active June 21, 2017 15:59
Gitconfig settings to use p4merge on windows using Cygwin terminal
tool = p4merge
[mergetool "p4merge"]
path = "C:/PROGRA~1/Perforce/p4merge.exe"
keepBackup = false
trustExitcode = false
tool = p4merge
smac89 / chain.ts
Created June 29, 2017 02:15
Chained callbacks
interface ChainedCallback {
(): void;
class ChainedCallback {
private chain: Callback[];
public static fromCallbacks( Callback[]): ChainedCallback {
let chained = new ChainedCallback();