Skip to content

Instantly share code, notes, and snippets.

View telmotrooper's full-sized avatar
🐧
➜ ~ echo "Hello, World\!" | lolcat

Telmo "Trooper" telmotrooper

🐧
➜ ~ echo "Hello, World\!" | lolcat
View GitHub Profile
@telmotrooper
telmotrooper / safe_input.py
Last active March 7, 2016 20:29
Guarantees that the user input respects the specified built-in type.
def input_float(msg):
while True:
try:
return float(input(msg))
except ValueError:
print("The input value is not a float.")
def input_int(msg):
while True:
@telmotrooper
telmotrooper / random_message.py
Last active May 21, 2016 21:07
Reads a random message from a file and prints it
"Reads a random message from a file and prints it"
from random import randint
with open("antichamber.txt") as file:
messages = file.readlines()
file_title = messages[0].replace("\n","")
random_number = randint(1, len(messages)-1)
random_message = messages[random_number].replace("\n","")
@telmotrooper
telmotrooper / FBullCowGame.cpp
Last active January 27, 2017 00:40
BullCowGame with difficulty settings
/*
This is the implementation of the FBullCowGame header.
*/
#pragma once
#include "FBullCowGame.h"
#include <map>
#define TMap std::map
FBullCowGame::FBullCowGame() {Reset();}
@telmotrooper
telmotrooper / DBGuy.java
Last active February 7, 2017 01:59
Basic PostgreSQL/Java example
import java.sql.*;
public class DBGuy {
private Connection c = null;
public DBGuy() {
try {
Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection("jdbc:postgresql://localhost:5432/testdb",
@telmotrooper
telmotrooper / wsh.bat
Last active April 15, 2017 15:10
Script to shutdown your Windows system in a given number of hours
@echo off
title Windows Shutdown Helper
echo ###########################
echo # Windows Shutdown Helper #
echo ###########################
set /p hours= "Hours to shutdown: "
set /a seconds= (%hours% * 60 * 60)
@telmotrooper
telmotrooper / toggle_touchpad.sh
Last active May 28, 2018 13:01
Toggle touchpad script (recommended shortcut is "Ctrl + \")
#!/bin/bash
var=$(synclient -l | grep TouchpadOff)
if [[ "$var" == " TouchpadOff = 0" ]]; then
synclient TouchpadOff=1
else
synclient TouchpadOff=0
fi
@telmotrooper
telmotrooper / wwwappender.py
Created April 30, 2017 22:57
Simple script to help appending the "www." prefix to entries in your hosts file
from shutil import copyfile
copyfile("in.txt", "out.txt")
inputFile = open("in.txt", "r")
outputFile = open("out.txt", "a")
outputFile.write("\n\n")
for line in inputFile.readlines():
@telmotrooper
telmotrooper / getpid.sh
Created April 30, 2017 23:19
Get Process ID by clicking on it
xprop _NET_WM_PID | cut -d' ' -f3
class Sudoku:
"""Sudoku validator"""
grid = [[0] * 9 for i in range(9)]
def __init__(self):
self.populate_grid()
self.print_grid()
self.validate_grid()
@telmotrooper
telmotrooper / share_wifi.sh
Created May 26, 2018 19:23
Share your Wi-Fi connectiong through cable
# Based on tutorial at:
# https://null-byte.wonderhowto.com/how-to/share-your-laptops-wireless-internet-with-ethernet-devices-0130528/
# Bring your ethernet interface up and assign an IP to it
sudo ifconfig enp7s0 up
sudo ifconfig enp7s0 192.168.2.1
# Enable IPv4 forwarding
sudo echo "1" | sudo tee /proc/sys/net/ipv4/ip_forward