Skip to content

Instantly share code, notes, and snippets.

@ronreiter
ronreiter / useMousePosition.tsx
Created March 15, 2024 07:00
Mouse position React hook
import { useEffect, useState } from 'react';
export default function useMousePosition() {
const [coords, setCoords] = useState({ x: 0, y: 0 });
useEffect(() => {
const handleWindowMouseMove = (event: MouseEvent) => {
setCoords({
x: event.clientX,
y: event.clientY
@ronreiter
ronreiter / memcached.py
Last active April 28, 2021 06:59
memcached Python example implementation
import socketserver
import time
cache = {}
class MyTCPHandler(socketserver.StreamRequestHandler):
def handle(self):
while True:
if not self.rfile.peek():
@ronreiter
ronreiter / stats.py
Created April 6, 2018 13:57
Facebook post stats
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 April 1, 2017 07:55
Lambda + API Gateway + DynamoDB example
'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 March 14, 2017 20:07
Longest word in Hebrew
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 March 21, 2016 21:57
mehmetkose/python3.5-async-crawler
#!/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 [email protected]
@ronreiter
ronreiter / sqlalchemy_example.py
Created August 10, 2015 06:21
SQLAlchemy Example
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()