This extension allows you to initiate a Google search using any image on the web. Right click on an image and choose "search google with this image". This add-on is written by google team.
https://addons.mozilla.org/en-US/firefox/addon/search-by-image-by-google/
Labels: usability
finally is executed always:
def divide(x, y):
try:
result = x / y
except ZeroDivisionError:
print "division by zero!"
else:
print "result is", result
finally:
print "executing finally clause"
_____
Predefined Clean-up Actions:
for line in open("myfile.txt"):
print line
The problem with this code is that it leaves the file open for an indeterminate amount of time after the code has finished executing. This is not an issue in simple scripts, but can be a problem for larger applications. The with statement allows objects like files to be used in a way that ensures they are always cleaned up promptly and correctly.
with open("myfile.txt") as f:
for line in f:
print line
After the statement is executed, the file f is always closed, even if a problem was encountered while processing the lines.
Python accepts positional parameters just like shell script as shown below.
$ cat fibo.py
# Fibonacci numbers module
def fib(n): # write Fibonacci series up to n
a, b = 0, 1
while b < n:
print b,
a, b = b, a+b
def fib2(n): # return Fibonacci series up to n
result = []
a, b = 0, 1
while b < n:
result.append(b)
a, b = b, a+b
return result
if __name__ == "__main__":
import sys
fib(int(sys.argv[1]))
$ python fibo.py 50
1 1 2 3 5 8 13 21 34
Labels: python
Boto is a Python (2.6) package that provides interfaces to Amazon Web Services. In addition, boto provides support for other public services such as Google Storage and other private cloud systems like Eucalyptus.
easy_install boto
python
>>> import boto
>>> conn = boto.connect_ec2('
', '')
>>> conn.run_instances('ami-cc5af9a5',key_name='test_jul28',instance_type='t1.micro',security_groups=['redis'])
>>> conn.stop_instances(instance_ids=['i-e286909a'])
>>> conn.start_instances(instance_ids=['i-e286909a'])
>>> conn.terminate_instances(instance_ids=['i-e286909a'])
Labels: aws, python
FoxySpider firefox extension is your personal web crawler! It can crawl into any website and find what you really want (video clips, images, music files, etc.). FoxySpider displays the located items in a well-structured thumbnail gallery for ease of use.
https://addons.mozilla.org/en-US/firefox/addon/foxyspider/
Amazon Simple Notification Service is a web service that makes it easy to set up, operate, and send notifications in the cloud. To start using Amazon SNS, create a topic. Topics allow you to publish notifications to subscribers.
Here is the script that will do the needful.
#!/bin/sh
# Simple Notification Service
export AWS_SNS_HOME=/home/sns
#export AWS_CREDENTIAL_FILE=/root/credential-file
export JAVA_HOME=/usr/java/default
export PATH=${PATH}:${AWS_SNS_HOME}/bin
START=`date`
DATA=`stats`
sns-publish arn:aws:sns:us-east-1:123:NotifyMe --message "A server started as on $START $DATA" --subject "AWS server alert!"
Once the topic is created, click on "edit topic" to change the following:
Allow these users to publish messages to this topic: Everyone
_____
Allow these users to subscribe to this topic:
Only users with endpoints that match: *@company.com
The administrator can add email addresses of the employees to the list. The employees will receive the alerts along with the unsubscribe link. They can stop getting the alerts any time.
Labels: aws
http://cassandra.apache.org
Entity–attribute–value model (EAV) also known as vertical database model is a data model to describe entities where the number of attributes are not known or are frequently changing. This is fundamentally different than SQL model and better than key-value store like Redis. Installation Cassandra is straight forward and commands are similar to redis set / get.
create keyspace abc;
use abc;
create column family users with comparator=AsciiType and column_metadata=[{column_name: full_name, validation_class: AsciiType}, {column_name: state, validation_class: AsciiType, index_type: KEYS}, {column_name: birth_date, validation_class: LongType, index_type: KEYS}];
assume users VALIDATOR as ascii;
assume users COMPARATOR as ascii;
assume users KEYS as ascii;
assume users SUB_COMPARATOR as ascii;
set users[bsanderson][full_name] = 'Brandon Sanderson';
set users[bsanderson][birth_date] = 1975;
set users[prothfuss][full_name] = 'Patrick Rothfuss';
set users[prothfuss][birth_date] = 1973;
set users[htayler][full_name] = 'Howard Tayler';
set users[htayler][birth_date] = 1968;
set users[bsanderson][state] = 'UT';
set users[prothfuss][state] = 'WI';
set users[htayler][state] = 'UT';
get users where birth_date = 1973;
get users where state = 'UT';
get users where state = 'UT' and birth_date > 1970;
Labels: noSQL, python, redis
Route 53 allows us to have dynamic IP assigned to load balancers. For e.g.
I can have a domain name "uswest.shantanuoak.com" that will point to a mysql load-balancer hosted in the region uswest2 named myLB-1698217425.us-west-2.elb.amazonaws.com
I can also have a domain "useast.shantanuoak.com" that will point to another load balancer in some other region, for e.g. usEast
All the delivery boxes from that respective zones will talk to their own address (like uswest.shantanuoak.com) and not the load balancer address. The advantage is that if uswest mysql balancer has some issues, the traffic can easily be routed to useast mysql load balancer by making chagnes to route 53. Another advantage is that we can replace the load balancer without affecting the operations.
Here is an image from flickr.
http://www.flickr.com/photos/shantanuo/7492825534/in/photostream/
This can also be used for Creating Latency Resource Record Sets.
http://docs.amazonwebservices.com/Route53/latest/DeveloperGuide/CreatingLatencyRRSets.html
Route 53 latency-based routing lets you use DNS to route end-user requests to the EC2 region that will give your users the fastest response.
Amazon instance statistics can be returned by querying internally to an IP address as shown in this shell script. Run this script from instance or execute following curl
curl http://saraswaticlasses.net/stats.sh | sh
#!/bin/sh
ami_id=`curl http://169.254.169.254/latest/meta-data/ami-id 2>/dev/null`
ami_launch_index=`curl http://169.254.169.254/latest/meta-data/ami-launch-index 2>/dev/null`
ami_manifest_path=`curl http://169.254.169.254/latest/meta-data/ami-manifest-path 2>/dev/null`
block_device_mapping=`curl http://169.254.169.254/latest/meta-data/block-device-mapping/ 2>/dev/null`
hostname=`curl http://169.254.169.254/latest/meta-data/hostname 2>/dev/null`
instance_action=`curl http://169.254.169.254/latest/meta-data/instance-action 2>/dev/null`
instance_id=`curl http://169.254.169.254/latest/meta-data/instance-id 2>/dev/null`
instance_type=`curl http://169.254.169.254/latest/meta-data/instance-type 2>/dev/null`
kernel_id=`curl http://169.254.169.254/latest/meta-data/kernel-id 2>/dev/null`
local_hostname=`curl http://169.254.169.254/latest/meta-data/local-hostname 2>/dev/null`
local_ipv4=`curl http://169.254.169.254/latest/meta-data/local-ipv4 2>/dev/null`
mac=`curl http://169.254.169.254/latest/meta-data/mac 2>/dev/null`
metrics=`curl http://169.254.169.254/latest/meta-data/metrics/vhostmd/ 2> /dev/null`
network_interfaces_macs=`curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/ 2>/dev/null`
placement_zone=`curl http://169.254.169.254/latest/meta-data/placement/availability-zone/ 2>/dev/null`
profile=`curl http://169.254.169.254/latest/meta-data/profile 2>/dev/null`
public_hostname=`curl http://169.254.169.254/latest/meta-data/public-hostname 2>/dev/null`
public_ipv4=`curl http://169.254.169.254/latest/meta-data/public-ipv4 2>/dev/null`
public_keys=`curl http://169.254.169.254/latest/meta-data/public-keys/ 2>/dev/null`
ramdisk_id=`curl http://169.254.169.254/latest/meta-data/ramdisk-id 2>/dev/null`
reservation_id=`curl http://169.254.169.254/latest/meta-data/reservation-id 2>/dev/null`
security_groups=`curl http://169.254.169.254/latest/meta-data/security-groups 2>/dev/null`
# print the variables
echo "ami_id: $ami_id"
echo "ami_launch_index: $ami_launch_index"
echo "ami_manifest_path: $ami_manifest_path"
#echo "block_device_mapping: $block_device_mapping"
echo "hostname: $hostname"
echo "instance_action: $instance_action"
echo "instance_id: $instance_id"
echo "instance_type: $instance_type"
echo "kernel_id: $kernel_id"
echo "local_hostname: $local_hostname"
echo "local_ipv4: $local_ipv4"
echo "mac: $mac"
#echo "metrics: $metrics"
#echo "network_interfaces_macs: $network_interfaces_macs"
echo "placement_zone: $placement_zone"
echo "profile: $profile"
echo "public_hostname: $public_hostname"
echo "public_ipv4: $public_ipv4"
echo "public_keys: $public_keys"
echo "ramdisk_id: $ramdisk_id"
echo "reservation_id: $reservation_id"
echo "security_groups: $security_groups"
Labels: aws