Skip to content

Instantly share code, notes, and snippets.

@qfgaohao
qfgaohao / device_properties.cu
Last active July 5, 2022 15:58
List GPU Specs. The code is modified from the Udacity Parallel Computing Course.
#include <stdio.h>
void deviceQuery ()
{
cudaDeviceProp prop;
int nDevices=0, i;
cudaError_t ierr;
ierr = cudaGetDeviceCount(&nDevices);
@qfgaohao
qfgaohao / priority_map.py
Created September 8, 2017 09:47
A structure combines priority queue and dict. You can pop out the biggest item from it like in queue. You can also set and get item like on a dict, while the order in the priority queue is maintained.
class Pair:
def __init__(self, key, value):
self.key = key
self.value = value
def __str__(self):
return "({}, {})".format(str(self.key), str(self.value))
def __repr__(self):
return self.__str__()
@qfgaohao
qfgaohao / draw_rectangle_circle.py
Created June 23, 2017 01:44
Examples of Drawing rectangles and circles
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from skimage.draw import (line, polygon, circle,
circle_perimeter,
ellipse, ellipse_perimeter,
bezier_curve)
# Draw a rectangle
img = np.ones((10, 10), dtype=np.double) # a gray image
@qfgaohao
qfgaohao / overlay.py
Last active June 23, 2017 01:41
Overlay a rectangle on an image
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from skimage import data
# get image
img = data.astronaut()
print('image size', img.shape)
fig, ax = plt.subplots()
ax.imshow(img)
@qfgaohao
qfgaohao / pyramid.py
Created June 22, 2017 19:13
get a pyramid of an image and show multiple images in one notebook cell.
# modified from http://scikit-image.org/docs/stable/auto_examples/transform/plot_pyramid.html#sphx-glr-auto-examples-transform-plot-pyramid-py
import numpy as np
import matplotlib.pyplot as plt
from skimage import data
from skimage.transform import pyramid_gaussian
image = data.astronaut()
@qfgaohao
qfgaohao / rotate_elastic_ip.py
Created June 21, 2017 02:04
Rotate elastic ips for an EC2 Machine
client = boto3.client('ec2')
instance_id = 'my instance id'
def rotate_ip(last_eip=None):
if last_eip:
client.release_address(AllocationId=last_eip['AllocationId'])
eip = client.allocate_address(Domain='vpc')
r = client.associate_address(AllocationId=eip['AllocationId'], InstanceId=instance_id)
return eip