Skip to content

Instantly share code, notes, and snippets.

View horvatha's full-sized avatar

Árpád Horváth horvatha

View GitHub Profile
@horvatha
horvatha / safe_keyboardinterrupt.py
Created November 3, 2012 07:06
Handle Keyboard Interrupt for critical functions
#!/usr/bin/env python3
"""See the docstring of SafeInterruptHandler.
Works with python3 as well.
"""
__author__ = 'Arpad Horvath'
import signal
import functools
# PEP 498 -- Literal String Interpolation
# Works with Python 3.6
i = 6
j = 7
print(f"{i*j} {i+j}")
print('\n'.join(
[
f'{i}x{j}={i*j}' + ('\n' if j == 30 else "")
from django.test import TestCase
import re
class MyTestCase(TestCase):
@staticmethod
def remove_csfr(html_code):
csrf_regex = r'<input[^>]+csrfmiddlewaretoken[^>]+>'
return re.sub(csrf_regex, '', html_code)
#!/bin/bash
# használat: kepatalakito fájlnév...
# példa: kepatalakito *.jpg
# Az argumentumként megadott jpg képfájlokat átalakítja (pl. más méretre).
# Készítette: Horváth Árpád http://harp.pythonanywhere.com
for i in "$@"
do
# Kiterjesztés és útvonal leszedése
name=`basename "$i" '.jpg'` # Leszedi a jpg kiterjesztést
#! /usr/bin/env python3
def main():
with open("egyketto.txt") as f:
sorok = f.readlines()
print("".join([s for s in szures(sorok, "POST Data", "New host")]))
def szures(sorok, pluszegyes, sima):
kimeno_sorok = []
ennyi_sort_meg = 0
import math
def prime_factorize(n):
factors = []
number = math.fabs(n)
while number > 1:
factor = get_next_prime_factor(number)
factors.append(factor)
number /= factor
class AudioRecord(models.Model):
file_ = models.FileField()
comment = models.TextField(max_length=200, blank=True)
class PracticingRecord(models.Model):
audio_record = modelf.ForeignKey(AudioRecord)
composition = models.ForeignKey(Composition)
part = models.CharField(
max_length=3,
choices=(
#!/usr/bin/env python3
# coding: utf-8
"""Find something near a given coordinate.
client_id and client_secret needs a registration on FourSquare
pip install requests
"""
for root, _, files in os.walk("."):
print('root: ', root)
for file in files:
if file.endswith(".py"):
with open(os.path.join(root, file)) as f:
b = f.read()
print(file, b.count('\n'))
@horvatha
horvatha / TSplit.txt
Created September 9, 2020 07:40
TSplit results comparison
This file has been truncated, but you can view the full file.
uloc=RTP, NC & around the world
new TSplit: ['rtp', 'nc', '&', 'around', 'the', 'world']
old TSplit: ['rtp,', '&', 'around', 'nc & around the world', 'world', 'rtp', 'the', 'nc']
uloc=SOUTHERN CAMEROONS
new TSplit: ['southern', 'cameroons']
old TSplit: ['cameroons', 'southern', 'southern cameroons']
uloc=Bhopal, Madhya pradesh, India
new TSplit: ['bhopal', 'madhya', 'pradesh', 'india']
old TSplit: ['bhopal,', 'india', 'pradesh,', 'madhya pradesh', 'bhopal', 'madhya']
uloc=Malibu, CA