Skip to content

Instantly share code, notes, and snippets.

View MattSegal's full-sized avatar
💭
Recovering engineering student

Matt Segal MattSegal

💭
Recovering engineering student
View GitHub Profile
"""
Python Script Manager
allows user to select a python (.py) script from directory and run it.
the script may be selected from a list and run in a command window or opened using a text editor
user can navigate folders in ROOT_DIRECTORY
TO DO:
add 'troubleshoot' to open python intepreter in a separate cmd window
"""
Test GUI
"""
from Tkinter import *
import os
import subprocess
def main():
""" starts up GUI """
from __future__ import print_function # Ignore this
# Example 1 - Function with argument
def say_hello(name):
# Prints 'Hello {name}!' to the screen
print("Hello {}!".format(name))
# We 'invoke' / 'call' a function using the ()s
say_hello('Nick')
def say_hello():
print("Hello")
def say_bye():
print("Bye")
def say_sup():
print("Sup?")
# This works fine
print("hey " + "you!")
# This causes an error because "hey" is a string and 1 is an integer
print("hey " + 1)
foo = "hey " + 1 # This is an error too
print(foo)
# This works fine - the argument is an integer
@MattSegal
MattSegal / hash.py
Last active August 22, 2017 02:34
hashing stuff in python
from hashlib import sha256
def get_sha256_hash(text):
text_bytes = text.encode('utf-8')
text_hash = sha256(text_bytes)
return text_hash.hexdigest()
password_1 = 'hunter2'
password_2 = 'hunter2'
@MattSegal
MattSegal / salt.py
Last active October 10, 2017 00:13
import hashlib
user_password = 'hunter12'
database_password = '6618f892842dcbc32f7968cc8f73b5b0065ec04e'
salt = '#&@#DH@HDHUUS'
user_password_hashed = hashlib.sha1(user_password + salt).hexdigest()
print(user_password_hashed == user_password_hashed)
@MattSegal
MattSegal / text-block.js
Created May 11, 2018 00:48
Draftail atomic block state change
import { Component } from 'react';
const { AtomicBlockUtils, EditorState, SelectionState, Modifier } = window.DraftJS
// The source gathers data for new entities that are being added in the Draftail editor
// It is invoked only when an new embed is inserted by the user
export class TextSource extends Component {
componentDidMount() {
const { editorState, entityType, onComplete } = this.props;
@MattSegal
MattSegal / super_and_subscript.py
Created June 19, 2018 03:29
Draftail Super and Subscript
# models.py
from wagtail.core.fields import RichTextField
from wagtail.core.models import Page
class MyModel(Page):
# ...
body = RichTextField(features=[
# ...
'subscript',
'superscript',
class ArticlePage(Page):
pass
class SectionPage(Page):
# ...
def route(self, request, path_components):
"""
Perform ORM optimisations on ArticlePage to speed up article load times
"""
try: