Skip to content

Instantly share code, notes, and snippets.

@mendhak
mendhak / dummy-web-server.py
Created August 25, 2017 21:33 — forked from bradmontgomery/dummy-web-server.py
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else. Also prints POST body
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./dummy-web-server.py [<port>]
Send a GET request::
curl http://localhost
@mendhak
mendhak / msysgit2unix-socket.py
Last active March 25, 2020 21:20 — forked from duebbert/msysgit2unix-socket.py
Script to help Bash on Ubuntu on Windows use KeeAgent's TCP socket file - so ssh can use KeePass installed on Windows 10
#!/usr/bin/python3
"""
msysGit to Unix socket proxy
============================
This small script is intended to help use msysGit sockets with the new Windows Linux Subsystem (aka Bash for Windows).
It was specifically designed to pass SSH keys from the KeeAgent module of KeePass secret management application to the
ssh utility running in the WSL (it only works with Linux sockets). However, my guess is that it will have uses for other
@mendhak
mendhak / update-another-users-pullrequest.md
Last active July 26, 2023 07:35
Update a pull request by pushing to another user's forked repository

Add the other user as a remote

#Using https
git remote add otheruser https://github.com/otheruser/yourrepo.git
# Or - Using SSH
git remote add otheruser git@github.com:otheruser/yourrepo.git

Fetch

git fetch otheruser

@mendhak
mendhak / ssh-tunnel.sh
Last active May 30, 2017 21:45
Reliable methods of creating SSH tunnels for TCP forwarding
#Source: https://stackoverflow.com/questions/2241063/bash-script-to-setup-a-temporary-ssh-tunnel
#SSH feature - control sockets
ssh -4 -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa -M -S my-ctrl-socket -fnNT -L 10023:remoteserver.com:8000 dev@middleserver.internal
#Get PID - you'll have to parse this
ssh -S my-ctrl-socket -O check dev@middleserver.internal
#Exit
ssh -S my-ctrl-socket -O exit dev@middleserver.internal
@mendhak
mendhak / InteractiveScrollView.java
Last active February 21, 2023 08:25 — forked from marteinn/InteractiveScrollView.java
ScrollView with a OnBottomReachedListener for Android
package se.marteinn.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ScrollView;
/**
* Triggers a event when scrolling reaches bottom.

Keybase proof

I hereby claim:

  • I am mendhak on github.
  • I am mendhak (https://keybase.io/mendhak) on keybase.
  • I have a public key whose fingerprint is 6989 CF77 4903 69CF FDCB CD89 95E7 D75C 76CB E9A9

To claim this, I am signing this object:

@mendhak
mendhak / s3downloader.py
Created March 23, 2014 01:47
A script to download and concatenate AWS ELB Access logs
import os
import pytz
import sys
import datetime
import dateutil.parser
import boto
downloadFolder = "downloads"
if len(sys.argv) > 1:
import time
import socket
def collect_metric(name, value, timestamp):
sock = socket.socket()
sock.connect( ("localhost", 2003) )
sock.send("%s %d %d\n" % (name, value, timestamp))
sock.close()
def now():
return int(time.time())
@mendhak
mendhak / gist:3996857
Created November 1, 2012 21:50
Mount an SSHFS share
sshfs username@machinename.local:/home/username /mnt/mountname -p 1234 -o allow_other -o IdentityFile=/home/mendhak/Documents/keys/id_rsa
@mendhak
mendhak / gist:3369293
Created August 16, 2012 11:00
Extension method to get value from a field in a SQLDataReader
public static class DataRecordExtensions
{
public static T GetValue<T>(this IDataRecord reader, string columnName)
{
object columnValue = reader[columnName];
T returnValue = default(T);
if (!(columnValue is DBNull))
{
returnValue = (T)Convert.ChangeType(columnValue, typeof(T));
}