Skip to content

Instantly share code, notes, and snippets.

View tombasche's full-sized avatar

Thomas Basche tombasche

  • Helsinki, Finland
View GitHub Profile
@tombasche
tombasche / 0_reuse_code.js
Last active September 14, 2015 06:20
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@tombasche
tombasche / json_error_catch.php
Created December 18, 2015 04:41
JSON Error Catch
<?php
/** \file jsonError.php
* \brief This code defines an error catch function to detect any errors in the JSON formatting. It converts the obscure code to the definition as provided in the JSON documentation.
* @see http://php.net/manual/en/function.json-last-error.php
*
*/
function jsonErrorCatch() {
switch (json_last_error())
{
//JSON_ERROR_DEPTH
@tombasche
tombasche / stringReverse.s
Last active April 1, 2022 09:42
Run in Spim or Mars to reverse a string with assembler! (MIPS)
# Mips program to reverse a string
# mips.s
.data
str: .space 128 # character buffer
.text
.globl main
@tombasche
tombasche / removeEmptyFolders.bat
Created April 30, 2016 06:52
Run in a directory to remove all empty folders (in windows)
for /f "delims=" %%d in ('dir /s /b /ad ^| sort /r') do rd "%%d"
@tombasche
tombasche / cdver.py
Last active November 4, 2016 08:03
Dronever
#inspired by http://cube-drone.com/comics/c/version-sacrifice
# note: you'll need to pip install pygithub
import time
import urllib2
import random
from github import Github
def nvl(var, val):
if var is None:
return val
@tombasche
tombasche / merge.py
Last active January 12, 2017 22:48
Merges all pdf files in a directory (needs pypdf - get using pip). Instructions: pip install pillow pip install pypdf Backup any images first Ensure any mergedpdf files are deleted run python merge.py in the directory with the images/pdfs
import os
import copy
from PIL import Image
from pyPdf import PdfFileWriter, PdfFileReader
def append_pdf(input,output):
[output.addPage(input.getPage(page_num)) for page_num in range(input.numPages)]
output = PdfFileWriter()
cwd = os.getcwd()
param (
[Parameter(Mandatory=$true)][string]$Hostname
)
$failure = ""
while (!$failure) {
try {
$net = [System.Net.Dns]::GetHostAddresses($Hostname)
$Host.UI.RawUI.BackgroundColor = ($bckgrnd = 'DarkGreen')
} catch [Exception] {
$failure = "yes"
@tombasche
tombasche / popclock.py
Last active March 1, 2017 22:15
Population Clock - using the ABS population API
import requests, json, time, os
ABS_URL = 'http://www.abs.gov.au/api/demography/populationprojection'
def getData():
r = requests.get(ABS_URL)
return json.loads(r.text)
def getPopulation():
text = getData()
@tombasche
tombasche / urlfuzzer.py
Last active April 11, 2017 09:54
Fuzzer to find folders and common files on websites
import requests
import os, sys
url = sys.argv[1]
dicts_dir = sys.argv[2]
result_dir = sys.argv[3]
def import_dict(dir, filepath):
file = open(os.path.join(dir,filepath), 'r')
return [item for item in file]
@tombasche
tombasche / scan.py
Created April 11, 2017 09:53
Python port scanner
import socket
import subprocess
import sys
url = str(sys.argv[1])
remoteIp = socket.gethostbyname(url)
print "Scanning " + url + " (" + remoteIp + ")"
try:
for port in range(1,5000):