Skip to content

Instantly share code, notes, and snippets.

View dishbreak's full-sized avatar

Vishal Kotcherlakota dishbreak

View GitHub Profile
@dishbreak
dishbreak / television-buggy.cpp
Last active August 29, 2015 13:56
Correction: The Right Way To Manage State in C++
void Television::pressPowerButton()
{
tvIsOn = !tvIsOn;
if (tvIsOn == true)
{
turnOn();
}
else
{
@dishbreak
dishbreak / brodcastmainwin.cpp
Created March 3, 2014 05:05
Compiling, Coffins, and Getting to Kansas: Telling the Ends from the Means
#include "brodcastmainwin.h"
#include "ui_brodcastmainwin.h"
BrodCastMainWin::BrodCastMainWin(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::BrodCastMainWin)
{
ui->setupUi(this);
<script src="https://gist.github.com/dishbreak/9318728.js"></script>
@dishbreak
dishbreak / duration.py
Created June 25, 2018 05:24
Simple Python Code for Turning Seconds into Hours, Minutes, Seconds
def express_as_duration(delta)
timestamp = []
hours = int(delta / (60 * 60))
minutes = int((delta % (60 * 60)) / 60)
seconds = delta % 60
if hours > 0:
if hours == 1:
timestamp.append("1 hour")
else:

Wifi Logger Webtask

This is intended to work with the Google Wifi applet on If This Then That (IFTTT) to log when specific devices connect and disconnect from the wifi network. It exposes two endpoints, both POSTs.

Note: We calculate connection/disconnection time server-side. This isn't the best way to do this, but this is for fun, after all.

POST /start/:deviceName

@dishbreak
dishbreak / notify_slack.sh
Created November 2, 2018 23:09
Send a message to a Slack Webhook
#!/bin/bash
set -e
## Take in the Webhook URL from Slack and the actual message to send.
if [[ $# -ne 2 ]]; then
( >&2 echo "Usage $(basename "$0") WEBHOOK_URL MESSAGE" )
exit 1
fi
WEBHOOK_URL=$1
@dishbreak
dishbreak / role_counter.sh
Last active November 5, 2018 19:23
For each role on a chef server, display the number of servers with that role.
#!/bin/bash
set -e
if ! which knife; then
( >&2 echo "Couldn't find knife on your path!" )
exit 1
fi
# Redirecting stderr to /dev/null will make output clean.
ROLES=$(knife role list 2>/dev/null)
#!/usr/bin/env python3
"""
Usage:
./server_control show -e ENVIRONMENT -a APPLICATION
./server_control terminate -e ENVIRONMENT -a APPLICATION
./server_control launch -e ENVIRONMENT -a APPLICATION
Options:
-e ENVIRONMENT Environment the server is in. Supported values are staging, production.
@dishbreak
dishbreak / parallel.sh
Created March 26, 2019 21:34
Executing Multiple Subprocesses in Parallel
#!/usr/bin/env bash
# kill all subprocesses when the user presses CTRL + C
trap "kill 0" SIGINT
# exit on first failed command (good practice)
set -e
echo "Starting"
@dishbreak
dishbreak / README.md
Last active April 16, 2019 16:19
Solve the Ciphers!

What is this?

This is a program that brute-force solves the ciphers in Chapter 7 of Sherlock Holmes, Consulting Detective. Pass it ciphertext as an argument, and it will print out 26 different "plaintext" sequences, one for each rotation on the cipher wheel.

Obviously, this program can spoil a lot of the fun, so be careful with it!