Skip to content

Instantly share code, notes, and snippets.

View simplyvikram's full-sized avatar

vikram singh simplyvikram

View GitHub Profile
@simplyvikram
simplyvikram / greenlet_first.py
Last active December 22, 2015 20:59
greenlet
from greenlet import greenlet
print "\n\nSwitching between greenlets"
def test1():
print "In test 1 - a"
gr3.switch()
print "In test 1 - b"
@simplyvikram
simplyvikram / create_greenlet.py
Created September 30, 2013 17:25
Testing Greenlet creation
from gevent import Greenlet
import gevent
class MyNoopGreenlet(Greenlet):
def __init__(self, number, seconds):
Greenlet.__init__(self)
self.number = number
self.seconds = seconds
print "Initialized greenlet with number:%i seconds:%i" % \
@simplyvikram
simplyvikram / select_echo_server.py
Created September 30, 2013 20:42
Trying out select
import select
import socket
import sys
import Queue
# Create a TCP/IP socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setblocking(0)
# Bind the socket to the port
import socket
import sys
messages = [ 'This is the message. ',
'It will be sent ',
'in parts.',
]
server_address = ('localhost', 10000)
# Create a TCP/IP socket
@simplyvikram
simplyvikram / tornado_long_blocking.py
Last active February 27, 2022 00:07
trying to call a long blocking function in tornado in a non blocking way, updated based on feedback(https://gist.github.com/badlydrawnrod/7003909)
import tornado.web
import tornado.gen
import time
from functools import partial
import os
from concurrent.futures import ThreadPoolExecutor
def long_blocking_function(index, sleep_time):
print "Entering run counter:%s" % (index,)
[user]
name = vikram singh
email = [email protected]
[credential]
helper = osxkeychain
[core]
editor = vim
[merge]
tool = p4mergetool
@simplyvikram
simplyvikram / attribute_acess_first.py
Last active August 29, 2015 13:56
Descriptors, __getattr__
# http://nbviewer.ipython.org/urls/gist.github.com/ChrisBeaumont/5758381/raw/descriptor_writeup.ipynb
# http://pyvideo.org/video/1760/encapsulation-with-descriptors
class NonNegativeValue(object):
__counter = 0
def __init__(self):
prefix = self.__class__.__name__
def lzw_encode(text):
"""Compress a string to a list of output symbols."""
# Build the dictionary.
dict_size = 256
dictionary = dict((chr(i), i) for i in xrange(dict_size))
w = ""
result = []
for c in text:
package main
import "fmt"
type Asset interface {
AssetType() string
GetBase() Base
SetBase(b Base)
}
type Base struct {
from math import sqrt
class Point(object):
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):