Skip to content

Instantly share code, notes, and snippets.

View amitsaha's full-sized avatar

Amit Saha amitsaha

View GitHub Profile
@amitsaha
amitsaha / funcs.py
Created August 26, 2012 13:10
Using getattr() to construct function objects from strings
def color_red():
return 'I am red'
def color_green():
return 'I am green'
def color_blue():
return 'I am blue'
@amitsaha
amitsaha / inspect_demo.py
Created August 27, 2012 09:04
Demo code using the Python inspect module
''' Demo script experimenting with various features of the
inspect module
'''
# To be run with Python3.3
from inspect_test import MyClass
from inspect_test import myfunc
from inspect_test import mygen
@amitsaha
amitsaha / Sample output
Created August 27, 2012 11:00
Array passing "by value" and "by reference" in Python
Original array changes::
array('i', [1, 2, 3])
Object Identifier: 3075060736
Object Identifier: 3075060736
array('i', [1, 4, 9])
Original array doesn't change::
array('i', [1, 2, 3])
@amitsaha
amitsaha / virsh_cheat.rst
Created September 4, 2012 00:05
Virsh cheat sheet

Domain Management

  • List domains: #virsh list --all
  • Undefine domains: #virst undefine <domain-name>

Volume Management

  • List all volumes in pool 'default': #virsh vol-list default
@amitsaha
amitsaha / beaker_inittests.log
Created September 14, 2012 08:47
beaker_inittests
+ env PYTHONPATH=../Common:../Server:../LabController/proxy/src:../Client/src:../IntegrationTests/src nosetests -v rhts bkr
Ensure Architectures field is parsed correctly ... ok
Ensure that an Architectures field following a Releases field is parsed correctly ... ok
Ensure a blank Bug field is handled ... ok
Ensure that multiple Bug and Bugs lines work ... ok
Ensure that multiple values for a Bugs field work ... ok
Ensure a single Bug field works ... ok
Ensure a single Bugs field works ... ok
Ensure Description field is parsed correctly ... ok
Ensure Description field containing a colon is parsed correctly ... ok
@amitsaha
amitsaha / atexit.c
Created September 14, 2012 22:07
atexit in C
/* Demo of atexit in C
http://www.gnu.org/software/libc/manual/html_node/Cleanups-on-Exit.html
*/
# include<stdio.h>
void cleanup()
{
printf("Program terminated\n");
}
@amitsaha
amitsaha / purge_handlers.py
Created September 18, 2012 03:58
purge_handlers
def purge_handlers():
#shutdown logging subsystem
#Called during application exit or reinitialization, hence OK.
logging.shutdown()
#remove all handlers
for (_, logger) in logging.root.manager.loggerDict.items():
if hasattr(logger, 'handlers'):
for handler in logger.handlers:
logger.removeHandler(handler)
@amitsaha
amitsaha / cloghandler.py
Created September 20, 2012 00:42
cloghandler source
# Copyright 2008 Lowell Alleman
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
@amitsaha
amitsaha / beaker_inittests.log
Created September 20, 2012 07:50
beaker_inittests
+ env PYTHONPATH=../Common:../Server:../LabController/proxy/src:../Client/src:../IntegrationTests/src python -c '__requires__ = ["TurboGears"]; import pkg_resources; from nose.core import main; main()' -v rhts bkr
Ensure Architectures field is parsed correctly ... ok
Ensure that an Architectures field following a Releases field is parsed correctly ... ok
Ensure a blank Bug field is handled ... ok
Ensure that multiple Bug and Bugs lines work ... ok
Ensure that multiple values for a Bugs field work ... ok
Ensure a single Bug field works ... ok
Ensure a single Bugs field works ... ok
Ensure Description field is parsed correctly ... ok
Ensure Description field containing a colon is parsed correctly ... ok
@amitsaha
amitsaha / myfind.py
Created September 21, 2012 01:20
File finding Utility
#!/usr/bin/env python
"""myfind
Usage:
myfind.py [--directory=<dir>] [--pattern=<p>] [--text=<text>]
myfind.py -h | --help
myfind.py --version
Examples: