Skip to content

Instantly share code, notes, and snippets.

@rtomaszewski
rtomaszewski / list_cs.py
Created April 6, 2013 21:22
list cloud servers using pyrax module
import os
import pyrax
conf = os.path.expanduser("rackspace_cloud_credentials.txt")
#pyrax.set_credential_file(conf, "LON")
pyrax.set_credential_file(conf)
cs = pyrax.cloudservers
servers = cs.servers.list()
print ("cloud server under your account:")
@rtomaszewski
rtomaszewski / wheel-scroling.au3
Created February 10, 2013 23:45
autoit script to change mouse wheel sensitivity
; This program adjust scroling of the mouse wheel on windows.
GLOBAL CONST $SPI_SETWHEELSCROLLLINES = 105
$SPIF_UPDATEINIFILE = 0x1
$SPIF_SENDWININICHANGE = 0x2
$SPIF_SENDCHANGE = $SPIF_SENDWININICHANGE
$WHEEL_PAGESCROLL = 4294967295 ; Use this, if you want scroll one Screen at a time
def myfunc(message):
"""
This is external function
@param message: this is string that is going to be printed
@return: none
"""
print("myfunc: %s" % message)
@rtomaszewski
rtomaszewski / bastion.py
Created August 28, 2012 23:43
example how to use paramiko to implement a bastion host pattern for command execution
#!/usr/bin/env python
import re
import time
import datetime
import paramiko
import traceback
DEBUG = 1
@rtomaszewski
rtomaszewski / example_paramiko_with_tty.py
Created August 19, 2012 19:49
example paramiko script with interactive terminal
import paramiko
import time
import re
bastion_ip='ip'
bastion_pass='pass'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy() )
ssh.connect(bastion_ip, username='root', password=bastion_pass)
@rtomaszewski
rtomaszewski / example_paramiko_notty.py
Created August 19, 2012 19:05
example paramiko script that tries to run an interactive command that needs a terminal
import paramiko
bastion_ip='ip' # you have to edit and provide valid IP address
bastion_pass='pass' # you have to edit it and provide valid password
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy() )
ssh.connect(bastion_ip, username='root', password=bastion_pass)
chan = ssh.invoke_shell()
@rtomaszewski
rtomaszewski / check_rackconnect.sh
Created August 13, 2012 21:47
An example bash script checking RackConnect deployment status
#!/bin/bash
iptables=$(iptables -nL)
ret=no
if echo $iptables | grep -q 'Chain INPUT .policy DROP.' ; then
if echo $iptables | grep -q 'Chain FORWARD .policy DROP.' ; then
if echo $iptables | grep -q 'Chain OUTPUT .policy ACCEPT.' ; then
if echo $iptables | grep -q 'Chain RS-RackConnect-INBOUND' ; then
ret=yes
@rtomaszewski
rtomaszewski / ssh_example.py
Last active July 7, 2019 11:13
Example script written in python that executes remotely commands over ssh
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy() )
ssh.connect('5.79.4.10', username='root', password='7raW6nS6Krttest')
stdin, stdout, stderr = ssh.exec_command('echo text on stdout stream; echo text on stderror stream 1>&2')
print("reading outputs from the remote command")
for l in stdout :
@rtomaszewski
rtomaszewski / JavaExample.java
Created August 9, 2012 21:56
Simple java code showing that before we can assign value to variable it has to be known to the javac compiler in advance
public class JavaExample {
// with the next line commented the code is erroring out when we try to compile it
//public int number;
public JavaExample (int _number) {
number=_number;
}
public void show() {
System.out.println("[test " + number + "] list=%s");
@rtomaszewski
rtomaszewski / object_variables_example.py
Created August 9, 2012 20:38
Differences between class and instance variables in Python
class Test1InstanceVariable:
mylist=[]
def __init__(self, number):
self.number= number
def add(self, i):
self.mylist.append(i)
def show(self):