Skip to content

Instantly share code, notes, and snippets.

@samhiatt
samhiatt / mocha.ts
Created May 25, 2022 05:34
Async unit tests with mocha
import assert = require("assert");
describe("Async Tests", function() {
it("uses callback", function(done) {
console.log("Starting test...");
setTimeout(()=>{
assert.ok("Timeout complete");
console.log("Test complete");
done();
}, 1000);
@samhiatt
samhiatt / main.dart
Created May 4, 2022 02:48
DartPad Demo App
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@samhiatt
samhiatt / patch_eventmachine.bat
Created February 12, 2021 03:58
Patch eventmachine.rb to enable Jekyll livereload on Windows 10. Tested with Ruby 2.7. Resolves the following error on Windows 10: "Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'"
@ECHO off
REM Patch eventmachine.rb to enable Jekyll livereload (jekyll serve -l)
REM Resolves the following error on Windows 10:
REM "Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'"
REM Tested on Ruby2.7, might also work on earlier versions.
REM See https://github.com/tabler/tabler/issues/155
REM Find eventmachine.rb
FOR /F "delims=" %%i IN ('gem environment gemdir') DO set gemdir=%%i
@samhiatt
samhiatt / vim.bat
Last active August 8, 2020 17:04
vim.bat shortcut for windows command line
REM: Depends on WSL (Windows Subsystem for Linux)
REM: Install WSL and then place this file in a directory included in your system PATH.
REM: Thanks to https://medium.com/powershell-explained/text-editor-inside-powershell-22d2f5e748b8
@ECHO off
bash.exe -c "vim %1"
@samhiatt
samhiatt / display_small.py
Created March 7, 2020 23:25
snippet to change the font size of the HTML table representation of a pandas data frame.
import pandas as pd
def display_small(df):
# pd.set_option('display.max_rows', 20)
return df.style.set_table_styles([
dict(selector="th", props=[("font-size", "7pt"), ("text-align", "center")]),
dict(selector='td', props=[('font-size', '7pt')]),
])
df = pd.DataFrame([{'a':1,'b':2},{'a':3,'b':5}])
@samhiatt
samhiatt / plumbum_example.py
Last active October 26, 2019 01:37
Example plumbum app demonstrating: 1. how to display output of a running process, 2. how to create a simple CLI app, and 3. use of colors in terminal output with plumbum.
#!/usr/bin/env python
# coding: utf-8
from plumbum import colors, cli
from plumbum.cmd import du
import sys
class MyApp(cli.Application):
path = cli.Flag(['p','path'],help="Path to search. (default: '.')")
@samhiatt
samhiatt / msg.json
Created October 21, 2019 23:22
Verify SNS message signature in Python
{
"Type" : "Notification",
"MessageId" : "531cb486-97ba-51cf-a438-e2aea8f027d3",
"TopicArn" : "arn:aws:sns:us-east-1:980559779107:HelloSNS",
"Message" : "Verify this!",
"Timestamp" : "2019-10-21T23:19:38.256Z",
"SignatureVersion" : "1",
"Signature" : "qYOYu1oxQbMLlpVec1cUCXV1Ye0OOviZ+XoO/mh+3SdsenlX6pi+j8t/lbvdnlwI/2zY1XT0CC9i4VIuy5gzP2toL8W2t9S0rc1yIg2Aj3v+mw6UNcBdp7suMWJk4v6totFMNhBqAs0gs+06DRBAyb+s45KWrcv+vq5chfn46Jvbe6GP5K8eYU2u0gjZ8nVbmb//lH5HOugQGi/3PMWXX13xGp4pqC7PWMb+WGxyHh8iXzHXInIcMGv5KWj+pQnbh3ADQ5EamBx63S240sS1bPumkQW0So9ec4qJbauAMhS95cmjyQBALd0DLJE7TNwcv+mTQQyfEL9H1Wgrbt86nA==",
"SigningCertURL" : "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-6aad65c2f9911b05cd53efda11f913f9.pem",
"UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:980559779107:HelloSNS:372a1c41-0c8b-40f7-9a8b-e28553258d83"
@samhiatt
samhiatt / patch_venv_prompt.sh
Created October 20, 2019 23:04
Alters the activate script in a virtualenv to show the parent directory in the shell prompt.
#!/bin/sh
if [ -z $1 ]; then
echo "Usage: $0 <target_venv>"
exit 1
fi
env_name=$(basename $1)
patch_str='57,58c57,60\n< if [ "x('$env_name') " != x ] ; then\n< \tPS1="('$env_name') ${PS1:-}"\n---\n> PS1=${PS1/(`cat /etc/debian_chroot`)//}\n> PS1=${PS1/\$\{debian_chroot\:\+(\\$debian_chroot)\}/}\n> if [ "x($(basename $(dirname $VIRTUAL_ENV))/$(basename $VIRTUAL_ENV)) " != x ] ; then\n> PS1="($(basename $(dirname $VIRTUAL_ENV))/$(basename $VIRTUAL_ENV)) ${PS1:-}"\n> PS1="($(basename $(dirname $VIRTUAL_ENV))/$(basename $VIRTUAL_ENV)) ${PS1:-}"'
activate_file="$1/bin/activate"
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<polymer-element name="my-element">