Skip to content

Instantly share code, notes, and snippets.

View JenkinsDev's full-sized avatar
🏠
Working from home

David JenkinsDev

🏠
Working from home
View GitHub Profile
@JenkinsDev
JenkinsDev / game.cpp
Last active July 18, 2021 14:15
LCD Game
#include <LiquidCrystal.h>
#define JOYSTICK_X_ANALOG_PIN A0
#define JOYSTICK_Y_ANALOG_PIN A1
const int LCD_SCREEN_CHAR_WIDTH = 16;
const int LCD_SCREEN_ROW_HEIGHT = 2;
const int BUTTON_PIN = 7;
@JenkinsDev
JenkinsDev / update-sublime-ruby-path.py
Last active September 13, 2019 15:47
Sublime Support rvm and rbenv ruby versioning
import os
import subprocess
from os.path import expanduser, join, exists
# We expect rbenv and rvm to be installed in their default locations. Can
# be updated to find them, if necessary.
rbenv_path = expanduser('~/.rbenv')
rvm_path = expanduser('~/.rvm')
@JenkinsDev
JenkinsDev / contiguous-sublists.py
Created August 28, 2016 14:49
Finding All Possible Contiguous Sub Lists
def contiguous_sublists(vals):
sub_lists = []
for ind, a in enumerate(vals):
sub_lists.append([a])
for b in range(ind+1, len(vals)):
sub_lists.append(sub_lists[-1] + [vals[b]])
return sub_lists
@JenkinsDev
JenkinsDev / sort_dict_by_date.py
Created November 4, 2015 18:24
Sort a Python 3 Dictionary By Date, On Keys
from collections import OrderedDict
from datetime import datetime
def sort_dict_by_date(the_dict, date_format):
# Python dicts do not hold their ordering so we need to make it an
# ordered dict, after sorting.
return OrderedDict(reversed(sorted(
the_dict.items(),
key=lambda x: datetime.strptime(x[0], date_format)
@JenkinsDev
JenkinsDev / fisher-yates-shuffle.py
Last active October 14, 2020 15:00
Fisher-Yates Shuffle In Python
from random import randint, random
from math import floor
def fisher_yates_shuffle(the_list):
list_range = range(0, len(the_list))
for i in list_range:
j = randint(list_range[0], list_range[-1])
the_list[i], the_list[j] = the_list[j], the_list[i]
return the_list
@JenkinsDev
JenkinsDev / reverse_num.py
Last active March 29, 2016 15:12
Reverse Number Without Strings In Python
# To the not-so-mathematically-inclined, this function may look like pure witch-
# craft. That's why I shall describe how it works.
#
# Let's say we start with an initial number of `13`, we expect an output of `31`,
# right? Let's see:
#
# reverse_number(13)
#
# num = 13
# reversed_num = 0
@JenkinsDev
JenkinsDev / CTRLHotkeyForVirtualDesktopChanger.ahk
Last active October 2, 2015 17:11
Allows you to change Window 10's current virtual desktop by hitting CTRL + Direction. Uses AutoHotkey.
#NoEnv
#NoTrayIcon
#IfWinActive ahk_class WorkerW
^Right::^#Right
^Left::^#Left
@JenkinsDev
JenkinsDev / Example.html
Created March 13, 2015 18:27
Traverse To Ancestor ~ jQuery
<!DOCTYPE html>
<html>
<head>
<title>Example for traverseToAncestor</title>
</head>
<body>
<div class="top-ancestor">
<div class="grandparent">
<div class="parent">
<div class="child"></div>
@JenkinsDev
JenkinsDev / redirectWithGetDataChange
Last active August 29, 2015 14:16
JavaScript update GET query key/value pair and redirect.
function redirectWithGetDataChange(key, value) {
var getData = window.location.search.substr(1).split("&"),
getKeyValue = null,
getKeyChanged = false;
for (var i=0; i<getData.length; i++) {
getKeyValue = getData[i].split("=");
if (getKeyValue[0] == key) {
getData[i] = key + "=" + value;
@JenkinsDev
JenkinsDev / Table2CSV.py
Last active August 29, 2015 14:15
HTML table to CSV
import sys
def generate_csv_data_from_html_table(html):
csv_header = ""
csv_rows = []
rows = create_rows_from_trs(remove_tab_and_newline(html))
for row in rows:
if not row.find("<th>") == -1:
csv_header = row.replace("<th>", "").replace("</th>", ",")
elif not row.find("<td>") == -1: