Skip to content

Instantly share code, notes, and snippets.

@bulv1ne
bulv1ne / client.py
Last active January 1, 2016 20:09
Server/Client using multiprocessing.Pool
import socket
if __name__ == "__main__":
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 9012))
data = "some data"
sock.sendall(data)
result = sock.recv(1024)
print result
sock.close()
@bulv1ne
bulv1ne / marks
Created February 13, 2014 07:21
Checkmarks
U+2713 ✓ check mark
U+2714 ✔ heavy check mark
U+2717 ✗
U+2718 ✘
class Photo(models.Model):
photo = models.ImageField(upload_to='photos')
@set_attributes(short_description='Image', allow_tags=True)
def image_tag(self):
if not self.photo:
return u''
return u'<img width="100" src="/media/%s" />' % self.photo
numbers = map(int, open("num.txt").readlines())
filtered_list = []
for i in numbers:
# Check against last element of last list
if filtered_list and filtered_list[-1][-1] < i:
# Append element to last list
filtered_list[-1].append(i)
else:
# Create a new list
filtered_list.append([i])
@bulv1ne
bulv1ne / Gruntfile.js
Created April 16, 2014 14:33
angular html2js grunt
module.exports = function(grunt) {
grunt.initConfig({
html2js: {
options: {
base: ''
},
main: {
src: [ 'partials/*.html' ],
dest: 'js/templates.js'
from collections import namedtuple
Node = namedtuple('Node', 'value next')
class Stack(object):
def __init__(self):
self.top = None
def push(self, value):
n = Node(value, self.top)
@bulv1ne
bulv1ne / debug.sh
Last active August 29, 2015 14:00
Debugging smtpd
python -m smtpd -n -c DebuggingServer localhost:1025
"""
usage 'pinhole port host [newport]'
Pinhole forwards the port to the host specified.
The optional newport parameter may be used to
redirect to a different port.
eg. pinhole 80 webserver
Forward all incoming WWW sessions to webserver.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define CHICKENS 20
char *chicken[] = {
" MM\n"
"<' \\___/|\n"
" \\_ _/\n"
# ls should return only 1 file
{ ls -l *DVD*; sleep 1; ls -l *DVD*; } | awk '{ print $5 }' | awk 'NR==2 { now = $1 }; NR==1 { then=$1 }; END { print (now-then)/1024 "kB/s" }'