Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

smac89

🎯
Focusing
View GitHub Profile
@smac89
smac89 / chain.ts
Created Jun 29, 2017
Chained callbacks
View chain.ts
interface ChainedCallback {
(): void;
}
class ChainedCallback {
private chain: Callback[];
public static fromCallbacks(...cbs: Callback[]): ChainedCallback {
let chained = new ChainedCallback();
cbs.forEach(chained.attach);
@smac89
smac89 / upgrade_packages.md
Last active Dec 1, 2018
Updating all packages installed by various package managers (brew, sdkman, gem, pip, etc)
View upgrade_packages.md

Brew

brew update && brew upgrade $(brew outdated)

SDKMAN

sdk selfupdate && sdk upgrade <package>

Gem

gem update $(gem list | cut -d' ' -f1)

Pip

@smac89
smac89 / disjoint.hpp
Created May 9, 2017
Implementation of a disjoint_set data structure
View disjoint.hpp
#include <algorithm>
#include <iterator>
#include <unordered_set>
#include <vector>
class disjoint_set {
struct ranked { int root, rank, size; };
public:
explicit disjoint_set(int n): cc(n + 1) {
@smac89
smac89 / range.hpp
Last active May 9, 2017
C++ range implementation
View range.hpp
#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
smac89 / immutable-stack.scala
Last active Apr 27, 2017 — forked from lambda-hacker/immutable-stack.scala
Stack using List [Scala]
View immutable-stack.scala
// Immutable Stack Type using List
case class Stack[A] (elems: Seq[A] = List.empty[A]) {
def push(v: A) : Stack[A] = Stack(v +: elems)
def pushAll(xs: Iterable[A]) : Stack[A] =
xs.foldLeft (this) ((accStack, e) => accStack.push(e))
def pop(): Either[String, (A, Stack[A])] = {
if (isEmpty) Left("Cannot pop from empty stack")
@smac89
smac89 / WinAdminCommands.md
Last active Jun 8, 2017
Windows administrative Commands (Powershell)
View WinAdminCommands.md
@smac89
smac89 / fbootfix.md
Last active May 28, 2020
Linux Fix Fastboot "no permissions, verify udev rules"
View fbootfix.md

Determine your device id

  1. Unplug your device from the computer and type lsusb in the terminal. You should get an output similar to this:
Bus 002 Device 002: ID 8087:8000 Intel Corp. 
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:8008 Intel Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 005: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
@smac89
smac89 / fpr.py
Last active May 10, 2020
Floating point regex: A regular expression to match any valid python floating point value.
View fpr.py
# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
# See it in action https://regex101.com/r/ObowxD/5
import re
regex = r"""
(?xm)
(?:\s|^)
([-+]*(?:\d+\.\d*|\.?\d+)(?:[eE][-+]?\d+)?)
@smac89
smac89 / BitmapDrawableFromDrawable.java
Created Jun 27, 2016
Converts drawable image to BitmapDrawable
View BitmapDrawableFromDrawable.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.Canvas;
public static final class BitmapDrawableFromDrawable {
public static BitmapDrawable drawableToBitmapDrawable (Context ctx, Drawable drawable) {
Bitmap bitmap;
if (drawable instanceof BitmapDrawable) {
You can’t perform that action at this time.