Skip to content

Instantly share code, notes, and snippets.

@ronreiter
ronreiter / memcached.py
Last active Mar 8, 2019
memcached Python example implementation
View memcached.py
import socketserver
import time
cache = {}
class MyTCPHandler(socketserver.StreamRequestHandler):
def handle(self):
while True:
if not self.rfile.peek():
@ronreiter
ronreiter / stats.py
Created Apr 6, 2018
Facebook post stats
View stats.py
from collections import Counter
name = None
in_text = False
current_text = ""
all_text = []
for line in open("stats.txt"):
#print('current line: %s in_text: %s name: %s' % (line.strip(), in_text, name))
line = line.strip()
@ronreiter
ronreiter / myfunction.js
Created Apr 1, 2017
Lambda + API Gateway + DynamoDB example
View myfunction.js
'use strict';
console.log('Loading function');
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
exports.handler = (event, context, callback) => {
//console.log('Received event:', JSON.stringify(event, null, 2));
@ronreiter
ronreiter / longest.py
Created Mar 14, 2017
Longest word in Hebrew
View longest.py
a = open("/Users/Ron/words.txt").read().decode("utf8").split()
first_row = ["ק", "ר", "א", "ט", "ו", "ן", "ם", "פ"]
second_row = ["ש", "ד", "ג", "כ", "ע", "י", "ח", "ל", "ך", "ף"]
third_row = ["ז", "ס", "ב", "ה", "נ", "מ", "צ", "ת", "ץ"]
first_row = [x.decode("utf8") for x in first_row]
second_row = [x.decode("utf8") for x in second_row]
third_row = [x.decode("utf8") for x in third_row]
only_first = sorted([(len(x), x) for x in a if all(y in first_row for y in x)])
only_second = sorted([(len(x), x) for x in a if all(y in second_row for y in x)])
@ronreiter
ronreiter / gist:7c0d97f320c21bb25c1d
Created Mar 21, 2016
mehmetkose/python3.5-async-crawler
View gist:7c0d97f320c21bb25c1d
#!/usr/bin/env python
# python 3.5 async web crawler.
# https://github.com/mehmetkose/python3.5-async-crawler
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2016 Mehmet Kose mehmet@linux.com
View sqlalchemy_example.py
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref, sessionmaker, joinedload
# For this example we will use an in-memory sqlite DB.
# Let's also configure it to echo everything it does to the screen.
engine = create_engine('sqlite:///:memory:', echo=True)
# The base class which our objects will be defined on.
Base = declarative_base()
You can’t perform that action at this time.