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 / AsyncTaskHelp.java
Created November 10, 2013 20:23
Basic AsyncTask layout that I point people to when they are confused.
public class MyAsyncTaskName extends AsyncTask<String, Integer, String> {
// String: The first string is the parameter, this is what is passed to doInBackground()
// Integer: The first, and only, Integer type is used for progress updates, this is what is passed to onProgressUpdate()
// String: The second String is for what is returned by doInBackground() and what is passed to onPostExecution();
@Override
protected void onPreExecute() {
// Handles what happens before the AsyncTask fully executes.
// Here you can do things like add a progress bar, loading animation, etc.
@JenkinsDev
JenkinsDev / calculate_age
Created June 6, 2014 00:09
Calculate Age (One Liner)
$age = floor((time() - strtotime($data_of_birth)) / 31556926);
@JenkinsDev
JenkinsDev / fadein
Last active August 29, 2015 14:12
fadeOut and fadeIn elements with JS (Drop In)
Element.prototype.fadeIn = function(callback) {
var ele = this,
opacity = ele.style.opacity = Number(ele.style.opacity) || 0.0,
fadeInLoop = null,
intervalTime = 10,
opacityAmount = 0.05;
ele.style.display = 'block';
// If the opacity is already greater than or equal to zero then there is nothing
@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:
@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 / 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 / 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 / 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 / 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 / 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)