Skip to content

Instantly share code, notes, and snippets.

View Se7enSquared's full-sized avatar
🐍
import this

HGray Se7enSquared

🐍
import this
View GitHub Profile
@Se7enSquared
Se7enSquared / gist:aa73fee01a092840a83813a6a7613809
Last active October 18, 2019 22:01
Javascript Sleep/Wait code to insert a waiting period into code before execution resumes
// sleep / wait function
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds) {
break;
}
}
}
@Se7enSquared
Se7enSquared / capslock_remap_alt.ahk
Created January 29, 2019 16:48 — forked from Danik/capslock_remap_alt.ahk
Autohotkey Capslock Remapping Script. Makes Capslock function as a modifier key to get cursor keys etc. on the left side of the keyboard, so you never have to move your hand to the right.
; Autohotkey Capslock Remapping Script
; Danik
; More info at http://danikgames.com/blog/?p=714
; danikgames.com
;
; Functionality:
; - Deactivates capslock for normal (accidental) use.
; - Hold Capslock and drag anywhere in a window to move it (not just the title bar).
; - Access the following functions when pressing Capslock:
; Cursor keys - J, K, L, I
@Se7enSquared
Se7enSquared / transpose_matrix.py
Last active October 18, 2019 22:00
Transpose a matrix (python list of lists)
matrix = [[1, 3, 5], [6, 7, 8], [10, 11, 12], [13, 14, 15]]
[[row[i] for row in matrix] for i in range(3)]
@Se7enSquared
Se7enSquared / pythonor.py
Last active October 18, 2019 21:59
Specify a default value to be returned from a function if the original return value would be None
# The or operator can return a default value if the requested return value is "None":
def test_func():
var_value = 'some value which could be none'
return var_value or "No value received"
# if var_value is None, the user will receive "No value received"
@Se7enSquared
Se7enSquared / pytest.py
Last active October 18, 2019 21:57
Creates a demo test in pytest
# in a file called 'digits.py':
def last_digit(n1, n2):
    '''
        Define a function that takes in two non-negative integers a and b and 
        returns the last decimal digit of a^b
    '''
    return pow(n1, n2, 10)
# in a file called 'test_digits.py':
@Se7enSquared
Se7enSquared / pymssql.py
Last active October 18, 2019 21:56
Connecting a SQL Server Database and executing a simple select query
import pymssql
host = "hostname"
username = "username"
password = "password"
database = "database"
conn = pymssql.connect(host, username, password, database)
cursor = conn.cursor()
cursor.execute("SELECT * FROM table")
@Se7enSquared
Se7enSquared / ttkthemes.py
Last active October 18, 2020 12:31
Boilerplate for using the arc theme in tkinter
# must pip install tkinter and pip install ttkthemes
# list of themes & theme reference:
# https://ttkthemes.readthedocs.io/en/latest/themes.html
import tkinter as tk
from tkinter import ttk
from ttkthemes import ThemedTk
window = ThemedTk(theme="arc")
ttk.Button(window, text="Quit", command=window.destroy).pack()
@Se7enSquared
Se7enSquared / counterignorecase.py
Last active October 18, 2019 21:54
Creates a Counter dict with all lowercase letters for case-insensitive keys
mydict = Counter(map(str.lower, mylist))
@Se7enSquared
Se7enSquared / strippunc.py
Last active October 18, 2019 21:54
For each item in a list of words, if it contains punctuation, strip it off
import string
listOfWords = [''.join(c for c in s if c not in string.punctuation)
for s in listOfWords]
@Se7enSquared
Se7enSquared / djangoimagepath.py
Last active October 18, 2019 21:53
Set a path to your media/images directory in your django project
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
#Things to change in settings first: