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 / README.md
Last active February 1, 2024 22:30
Google Foobar Ion Relabeling Solution

Ion Relabeling Solution

Acknowledgements

This post on StackExchange Code Review is the basis for this algorithm.

Problem Summary

Oh no! Commander Lambda's latest experiment to improve the efficiency of her LAMBCHOP doomsday device has backfired spectacularly. She had been improving the structure of the ion flux converter tree, but something went terribly wrong and the flux chains exploded. Some of the ion flux converters survived the explosion intact, but others had their position labels blasted off. She's having her henchmen rebuild the ion flux converter tree by hand, but you think you can do it much more quickly - quickly enough, perhaps, to earn a promotion! >

@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!

@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 / magic_jq_task.sh
Last active January 19, 2024 08:36
Easy way in Bash to check that a binary is installed.
#!/bin/bash
# Exit on the first command that returns a nonzero code.
set -e
# Function that checks if a given executable is on the path. If it isn't, prints an install message and exits.
# Usage: check_binary EXECUTABLE_NAME INSTALL_MESSAGE
check_binary() {
if ! which "$1" > /dev/null; then
# Using a subshell to redirect output to stderr. It's cleaner this way and will play nice with other redirects.
@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)