Skip to content

Instantly share code, notes, and snippets.

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

Philip Norton philipnorton42

🏠
Working from home
View GitHub Profile
<?php
/**
* Googl
*
* For more information on this file and how to use the class please visit
* http://www.hashbangcode.com/blog/googl-url-shortening-service-class-php-528.html
*
* PHP version 5
*
@philipnorton42
philipnorton42 / Config Merge
Last active December 2, 2018 19:31
A stand alone script that can be used to compare and copy configuration from two different sub-sites into a default configuration.
<?php
require './vendor/autoload.php';
// Set up the directories needed.
$parentDirectory = 'config/siteone';
$siblingDirectory = 'config/sitetwo';
$destinationDirectory = 'config/default';
<?php
function renderGame($state, $activeCell, $player) {
$output = '';
$output .= 'Player:' . $player . PHP_EOL;
foreach ($state as $x => $line) {
$output .= '|';
foreach ($line as $y => $item) {
@philipnorton42
philipnorton42 / FloodProtectedForm.php
Last active December 13, 2020 20:51
FloodProtectedForm example of the Drupal flood service. Take from https://www.hashbangcode.com/article/drupal-9-integrating-flood-protection-forms
<?php
namespace Drupal\mymodule\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Flood\FloodInterface;
use Drupal\Component\Utility\Crypt;
<?php
class Entity {
public $positionX = 0;
public $positionY = 0;
public function __construct($x, $y) {
$this->positionX = $x;
$this->positionY = $y;
}
@philipnorton42
philipnorton42 / time.py
Last active October 3, 2021 17:16
Converting The Current Time Into A Sentence In Python (see https://www.hashbangcode.com/article/converting-current-time-sentence-python)
# The following code will print out the current time as a sentence.
# See https://www.hashbangcode.com/article/converting-current-time-sentence-python for information on this code.
def translate_to_or_past(minute):
to_or_past = ''
if 3 <= minute < 33:
to_or_past = 'PAST'
elif 33 <= minute <= 57:
to_or_past = 'TO'
return to_or_past
# Creates a Tkinter application that shows the current time as a word wall
# For more information see: https://www.hashbangcode.com/article/creating-word-clock-python-and-tkinter
#
# 0123456789ABC
# 0 ITRISUHALFTEN
# 1 QUARTERTWENTY
# 2 FIVEQMINUTEST
# 3 PASTMTOSAMOPM
# 4 ONENTWOZTHREE
# 5 FOURFIVESEVEN
@philipnorton42
philipnorton42 / calculator.py
Last active November 1, 2021 09:04
A calculator, created with Tkinter and Python. See https://www.hashbangcode.com/article/creating-simple-calculator-application-tkinter-python for more informaiton.
import tkinter as tk
class Calculator(tk.Tk):
def __init__(self):
super().__init__()
self.title("Calcuator")
self.buttons = {}
<?php
function translateKeypress($string) {
switch ($string) {
case "\033[A":
return "UP";
case "\033[B":
return "DOWN";
case "\033[C":
return "RIGHT";
'''
Conway's Game Of Life With Tkinter In Python
See https://www.hashbangcode.com/article/conways-game-life-tkinter-python for
a detailed breakdown of this code.
'''
import tkinter as tk
from tkinter import Canvas
import random, math
class game_of_life(tk.Tk):