Skip to content

Instantly share code, notes, and snippets.

View abhigenie92's full-sized avatar
🤫
Hungry

Abhishek Bhatia abhigenie92

🤫
Hungry
View GitHub Profile
from twisted.internet.protocol import DatagramProtocol
# Here's a UDP version of the simplest possible protocol
class AudioEchoUDP(DatagramProtocol):
echoers = []
def startProtocol(self):
print "Audio server started"
def datagramReceived(self, datagram, address):
if address not in self.echoers:
from twisted.internet.protocol import Protocol, ClientFactory
import pdb
# audio imports
import pyaudio,wave
class AudioClientFactory(ClientFactory):
def __init__(self, canvas_obj):
self.canvas_obj = canvas_obj
def buildProtocol(self, addr):
return StrokeClient(self)
# -*- coding: utf-8 -*-
from twisted.internet.protocol import Protocol, Factory
class AudioEcho(Protocol):
def __init__(self, factory):
self.factory = factory
def connectionMade(self):
print "Connected client:",self
self.factory.echoers.append(self)
# -*- coding: utf-8 -*-
from twisted.internet.protocol import Protocol, Factory
class StrokeEcho(Protocol):
def __init__(self, factory):
self.factory = factory
def connectionMade(self):
print "Connected client:",self
self.factory.echoers.append(self)
Aim: associate each protocol with a username
Method right now: I make the client send it's username to server upon connecting in the connectionMade method. This is
thus, the first msg of the client.
The server differentiates this msg from client from rest by using flag unregistered in the class StrokeEcho,
Required approach:
Do this without the use of flag by appending something to the first msg the client sends while establishing
a connection with the server and then receive it the server end. I am assuming the client sends some data to
the server when I call connectTCP like it's IP-address etc. I want to modify that msg and receive at the
server end.
from twisted.internet.protocol import ClientFactory
import pdb,json
from twisted.protocols.basic import NetstringReceiver
from twisted.internet.defer import inlineCallbacks
from twisted.internet.threads import deferToThread
from Queue import Queue
# audio imports
import pyaudio,wave,threading
class AudioClient(NetstringReceiver):
import os,re,pdb
## Get the repos
path='/var/lib/apt/lists/'
files=os.listdir(path)
release_files=[file for file in files if file.endswith('Release')]
origin_pattern=re.compile('Origin: (.*)\n')
suite_pattern=re.compile('Suite: (.*)\n')
@abhigenie92
abhigenie92 / nbmerge.py
Created April 28, 2017 08:54 — forked from fperez/nbmerge.py
Merge/concatenate multiple IPython notebooks into one.
#!/usr/bin/env python
# Note, updated version of
# https://github.com/ipython/ipython-in-depth/blob/master/tools/nbmerge.py
"""
usage:
python nbmerge.py A.ipynb B.ipynb C.ipynb > merged.ipynb
"""
import io
@abhigenie92
abhigenie92 / check.py
Created August 11, 2017 23:50
check tensorflow gnu
jaan@gonzo /> python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
2017-08-11 16:49:07.472553: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-11 16:49:07.472591: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-11 16:49:07.472612: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-08-11 16:49:07.472628: W tensorflow/c
1. Install oh-my-zsh
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
2. Clone necessary plugins.
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
3. Add plugins to ~/.zshrc as
plugins = ( [plugins...] zsh-autosuggestions zsh-history-substring-search zsh-syntax-highlighting)