Skip to content

Instantly share code, notes, and snippets.

@saleph
saleph / primes.py
Last active August 29, 2015 14:25
Simple prime numbers finder in 1 line.
__author__ = 'tom'
import math
print([x for x in range(2, 1000) if not any([x % y == 0 for y in range(2, math.floor(math.sqrt(x))+1)])])
@saleph
saleph / fib.py
Created July 22, 2015 17:51
recursive fib sequence
__author__ = "tom"
def fib(n):
if n == 1:
return 1
if n == 2:
return 1
return fib(n-1) + fib(n-2)
print([fib(x) for x in range(1, 30)])
@saleph
saleph / palindrome.py
Last active August 29, 2015 14:25
simple palindrome checker
__author__ = 'tom'
def palindrome(word):
if all(word[x] == word[len(word)-x-1] for x in range(0, len(word)/2)):
return True
else:
return False
print(palindrome("mock"))
print(palindrome("lol"))
@saleph
saleph / reverse_file.py
Last active August 29, 2015 14:26
Print lines of a file conversly
__author__ = 'tom'
import sys
file_name = sys.argv[1]
source = open(file_name).readlines()
print(''.join(source[::-1]))
@saleph
saleph / tooltip.py
Last active August 29, 2015 14:28
[qt5] tooltips
__author__ = 'tom'
import sys
from PyQt5.QtWidgets import (QWidget, QToolTip,
QPushButton, QApplication)
from PyQt5.QtGui import QFont
class Example(QWidget):
def __init__(self):
@saleph
saleph / closing.py
Last active March 25, 2016 18:34
[qt5] signals - quiting
__author__ = 'tom'
import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
from PyQt5.QtCore import QCoreApplication
class Example(QWidget):
def __init__(self):
super().__init__()
@saleph
saleph / msgbox.py
Last active November 3, 2019 13:09
[qt5] handling close event - msg box
__author__ = "tom"
import sys
from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication
class Example(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
@saleph
saleph / centering.py
Last active August 8, 2022 05:20
[qt5] center a window on screen
__author__ = 'tom'
import sys
from PyQt5.QtWidgets import QWidget, QDesktopWidget, QApplication
class Example(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
@saleph
saleph / statusbar.py
Last active August 26, 2015 12:47
[qt5] window's statusbar
__author__ = 'tom'
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.init_ui()
@saleph
saleph / menubar.py
Created August 26, 2015 12:46
[qt5] menubar + tip in statusbar
__author__ = 'tom'
import sys
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
from PyQt5.QtGui import QIcon
class Example(QMainWindow):
def __init__(self):
super().__init__()