Skip to content

Instantly share code, notes, and snippets.

View gauravssnl's full-sized avatar
😸
use code::latest ;

GAURAV gauravssnl

😸
use code::latest ;
View GitHub Profile
@gauravssnl
gauravssnl / python_over_ssh
Created July 1, 2017 13:15 — forked from mattyjones/python_over_ssh
Execute a script located on a remote server over ssh using python
#! /usr/bin/env python
import secure
import pexpect
# the file containing the list of servers to log into
input_file = "script_list"
# The login creds
user = secure.USER
@gauravssnl
gauravssnl / python_ssh.py
Created July 1, 2017 13:18 — forked from JonnyWong16/python_ssh.py
Run a SSH command using Python
# 1. Install the paramikio module for python.
# pip install paramiko
# 2. Edit the SSH details below.
import paramiko
import sys
## EDIT SSH DETAILS ##
SSH_ADDRESS = "192.168.0.1"
@gauravssnl
gauravssnl / fabfile.py
Created July 1, 2017 13:21 — forked from elliottb/fabfile.py
Example Python Fabric deployment script. Deploys code from a deployment box to a remote host. Usage from command line on the deployment box: fab deploy.
from fabric.api import local, run, env, put
import os, time
# remote ssh credentials
env.hosts = ['10.1.1.25']
env.user = 'deploy'
env.password = 'XXXXXXXX' #ssh password for user
# or, specify path to server public key here:
# env.key_filename = ''
@gauravssnl
gauravssnl / scp_demo.py
Created July 1, 2017 13:22 — forked from mlafeldt/scp_demo.py
[Python] paramiko examples
#!/usr/bin/env python
import sys, paramiko
if len(sys.argv) < 5:
print "args missing"
sys.exit(1)
hostname = sys.argv[1]
password = sys.argv[2]
@gauravssnl
gauravssnl / paramiko_example.py
Created July 1, 2017 13:22 — forked from batok/paramiko_example.py
Paramiko example using private key
import paramiko
k = paramiko.RSAKey.from_private_key_file("/Users/whatever/Downloads/mykey.pem")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print "connecting"
c.connect( hostname = "www.acme.com", username = "ubuntu", pkey = k )
print "connected"
commands = [ "/home/ubuntu/firstscript.sh", "/home/ubuntu/secondscript.sh" ]
for command in commands:
print "Executing {}".format( command )
@gauravssnl
gauravssnl / create_repo.py
Created July 1, 2017 13:23 — forked from jkeesh/create_repo.py
Python script to create a remote git repo that checks out the latest commit with a post-receive hook
#
# This script creates a repository and sets it up with a post receive
# hook that checks out the code to the desired directory.
#
# Really nice for setting up an easy way to push code to a remote
# server without lots of overhead.
#
# After running this script simply add a remote locally like
#
# git remote add web ssh://you@server/path/to/repo.git
@gauravssnl
gauravssnl / README.md
Created July 1, 2017 13:25 — forked from Lazza/README.md
VPNGate Python script

vpngate.py

This script allows to use the free VPN service provided by VPNGate in an easy way. The user just needs to provide the desidered output country, and the script automatically chooses the best server.

After this step, OpenVPN is launched with the proper configuration. The VPN can be terminated by pressing Ctrl+C.

Usage

Run the script by providing the desired output country:

@gauravssnl
gauravssnl / pycdump.py
Created July 2, 2017 13:10 — forked from anonymous/pycdump.py
Dump .pyc file (Python 3.5 version)
#
# read a .pyc file and pretty-print it
#
# copied from http://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html
# and updated to Python 3.5 (Nov 10th 2015)
@gauravssnl
gauravssnl / check_float_rounding.py
Created July 9, 2017 15:12 — forked from ncoghlan/check_float_rounding.py
Checking Python's rounding behaviour
# Prompted by this article about implementing "Round half away from zero" in Go
# https://www.cockroachlabs.com/blog/rounding-implementations-in-go/
# Python uses round-half-even by default to reduce statistical bias,
# but round-half-away-from-zero can be implemented more efficiently
# (since it doesn't need to examine all the bits of the number)
# I figured the folks doing computational analysis in Python would
# have made sure this was handled correctly years ago, but it never
# hurts to check that kind of assumption :)
@gauravssnl
gauravssnl / stopwatch.py
Created July 11, 2017 12:10 — forked from sumeet/stopwatch.py
A Python timer class.
import time
class Stopwatch(object):
"""A stopwatch utility for timing execution that can be used as a regular
object or as a context manager.
NOTE: This should not be used an accurate benchmark of Python code, but a
way to check how much time has elapsed between actions. And this does not
account for changes or blips in the system clock.