Skip to content

Instantly share code, notes, and snippets.

View brahmlower's full-sized avatar
🦀

Brahm Lower brahmlower

🦀
View GitHub Profile
@brahmlower
brahmlower / rust-dynclone-example.rs
Last active August 13, 2023 08:43
A quick demo of using DynClone on a trait so structs with `dyn TraitName` can derive Clone
#!/usr/bin/env cargo +nightly -Zscript
//! ```cargo
//! [dependencies]
//! dyn-clone = "1.0.12"
//! ```
use std::fmt::Debug;
use dyn_clone::DynClone;
@brahmlower
brahmlower / exclude_example.ts
Created June 19, 2022 03:53
Omitting `symbol` and `number` from `keyof` on generic type using `Exclude`
// Example showing usage of typescripts `Exclude` utility type.
// Typescript playground link: https://www.typescriptlang.org/play?#code/FAYw9gdgzgLgBAQwG4JAgJmKBJdcC8cAjAEwDMA3MKJLIgA70A2AplAMoCeAtgXF9wBGYJgAoARAkaso4gJTUAlhBgsATgDNULOADE1AV0UwAQgigBrFvADewOA7gBtKczYCAugC44EA0PV7RzA1BAgAczYfPwC1IId6FgQ1KGj-QUDHZ2RUDCxcb190wIBfag0DCBAYRUg4DUNjABUwAFFuMAArRVEGoxgAOQRuFh9YNWVwuTGYCYi4OyyoAHdjEAALOF7GweGWOQX4rLg0KB1xELDI2S8j48c1awM1CDhxQB4NwCl98TvHU-PEskbr97o8YM9Xh9AAr7P3uDnQLC0BiYMFucOOYIhbwAPJULBAwMsIAA+WGOMplYAVKo1Or0OYwfT9IYjbFNAA0cAA0nAWAAPVQQdBQOCtPkgJgGBHYqycMAaOAcuBQHjCJhwAA+RVixOJ22Zex8XM5gnMVlRiumytmk0OWVY8D6xnaXUUfCdMBaLu6+uMLP2Rwd9R2A38fFNlmsTg9-o8R0xLzgAAMACQ2D3exQlOBpmP+EpJ4CUoMR80+JnGMyR+CERaOFzSdw8QoAVnZR0uESixHbWUBKR8ZF79ZyaEwOHQhQALO3KQB6OeitRqEIi1Ywda3BeOACCanC-hYKjg8rgME4iTgAHJJI3ZFe4IoRQT4OYoIpwhAEIJWGewHB6GSPZVDUE8FXPS8b07a5xE1N5+3vYAFyQxdwGgEQWAAOiYMBwlEellEZEM9gkVwZHEE0zWsOQFBQpcVxSOB103OiHD3A8RmPU8IJ0K9KkUABHAwdBVIQRAfJ9fDAV8oHfT9v1-GB-0A0IRhAsCzwvXiLlCLtZDg8QEPEK9MJQui0KgDDsNw-CGQrXYRlE
@brahmlower
brahmlower / Main.hs
Created March 21, 2018 21:16
Short circuiting a chain of operations in Haskell
module Main where
import Control.Monad.Except
(ExceptT
, runExceptT
, throwError
)
import Control.Monad.IO.Class ( liftIO )
@brahmlower
brahmlower / rst_parse.py
Created February 15, 2017 08:48
Automatic TestCase creation for rst literal_block shell examples in python class docstrings
import sys
import unittest
from docutils.core import publish_doctree
import subprocess
import opendir_dl
class ShellTestCase(unittest.TestCase):
def assert_shell_yields(self, command, expected_result):
result = subprocess.check_output(command, shell=True)[:-1]
if result != expected_result:
#!/usr/bin/python
import urllib2
import json
last_timestamp_utc = 0
reddit_api = 'https://www.reddit.com/r/opendirectories/new.json?sort=new'
page_request = urllib2.urlopen(reddit_api)
page_content = json.loads(page_request.read())
posts = page_content['data']['children']
# API results are in order of newest to oldest, but we want to
import threading
import SocketServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
import httplib2
class QuietSimpleHTTPRequestHandler(SimpleHTTPRequestHandler):
"""Quiet http request handler
Subclasses SimpleHTTPRequestHandler in order to overwrite the log_message
method, letting us reduce output generated by the handler. Only standard
messages are overwritten, so errors will still be displayed.
@brahmlower
brahmlower / dynamic_property_test.py
Last active September 18, 2016 22:29
Dynamic property assignment with default custom get and set methods
#!/usr/bin/python
# This example implementation is *extremely* similar to what is being asked and
# answered on the following stack overflow page:
# http://stackoverflow.com/questions/1325673/how-to-add-property-to-a-python-class-dynamically
# Simply running this script will return the following output, which follows
# a story told through inline comments.
# user@debian:~$ ./dynamic_property_test.py
@brahmlower
brahmlower / phpVirtualBox Debian 8 Install Script
Last active November 8, 2017 06:52
This is a script to install VirtualBox and phpVirtualBox on a headless Debian 8 machine.
#!/bin/bash
# Author: Brahm Lower
# Name: phpVirtualBox Debian 8 Install Script
# Source: https://gist.github.com/bplower/b7e193fc3861e964c367/
# Prerequisite Packages:
# bash, openssl, cat, grep, echo, wget, apt-key, apt-get, useradd, usermod, passwd, mv, cp, sed, systemctl
# Installed Packages:
# build-essential, dkms, unzip, apache2, php5, php5-mysql, libapache2-mod-php5, php-soap, virtualbox-5.0
# Description:
# This is a script to install VirtualBox and php VirtualBox on a headless Debian 8 machine.
@brahmlower
brahmlower / koel-installation-docs_debian8.md
Last active June 8, 2021 09:03
This is installation documentation for installing Koel on Debian 8.

Installation on Debian 8

This is installation documentation for installing Koel on Debian 8.

Install Dependancies

Most packages can be installed via apt-get.

user@debian:~/$ sudo apt-get install -y apache2 mysql-server php5 php5-mysql g++ git curl

Composer

Keybase proof

I hereby claim:

  • I am bplower on github.
  • I am bplower (https://keybase.io/bplower) on keybase.
  • I have a public key whose fingerprint is 9397 76F4 F064 4FD2 955D 0511 1ECD 50E2 4027 9A7E

To claim this, I am signing this object: