Skip to content

Instantly share code, notes, and snippets.

View cmccormack's full-sized avatar
🔍
Code Reviews

Christopher McCormack cmccormack

🔍
Code Reviews
View GitHub Profile
def calc(expr):
operators = ['+', '-', '*', '/']
stack = list()
for item in expr.split(' '):
if item in operators:
right, left = [str(i) for i in (stack.pop(), stack.pop())]
stack.append(eval(left + item + right))
else:
stack.append(eval(item + '+ 0'))
@cmccormack
cmccormack / chromesearchmultvar.js
Last active December 9, 2022 21:44
Google Chrome Search Engine with multiple search strings
/**
* @desc this snippet will allow multiple arguments to a search query in Google Chrome
* examples include https://www.reddit.com/r/%s/search?q=%s
* @author Chris McCormack mccormack.christopher@gmail.com
* @required Google Chrome. Replace all values in brackets ([]) with valid entries.
* To add to Chrome, go to Settings > Search [Manage search engines...] > Other search engines.
* At the bottom of this section, there are three required fields:
* [Add a new search engine] [Keyword] [URL with %s in place of query]
* - Add a new search engine: Descriptive name of your search
* - Keyword: used to trigger search.
@cmccormack
cmccormack / send_message_email.php
Last active March 2, 2018 19:26
Simple PHP Contact Form
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
@cmccormack
cmccormack / asyncletter.py
Last active March 3, 2018 00:20
Testing Python3 Threading
from threading import Thread, Lock
from random import randint
from time import sleep
class AsyncLetter(Thread):
def __init__(self, letter):
super().__init__()
self.timer = randint(1,5)
@cmccormack
cmccormack / mongoose_examples.js
Created April 16, 2018 01:14
Mongoose Query and Update Examples
// Example of a schema for a Poll document
const PollSchema = new mongoose.Schema({
createdBy: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
createdTime: {
type: String,
required: true
},
@cmccormack
cmccormack / AccurateInterval.js
Created August 3, 2018 17:43
A more accurate timer to replace setInterval
class AccurateInterval {
intervalId = null
constructor(fn, timer) {
this.fn = fn
this.timer = timer
}
start = () => {
@cmccormack
cmccormack / linux_networking.sh
Last active January 23, 2023 21:48
Linux Networking Commands
# View device IP Address(es)
ip -o address show [interface] | awk '{print $4}' # Prints the IP address(es) of a single interface
ip address # Displays all interfaces
ifconfig # (deprecated)
hostname -I # Displays only IP addresses
# DNS name and resolution
host
dig
/etc/hosts # Add manual DNS record to hostname mappings (normally checked before configured DNS server(s))
@cmccormack
cmccormack / Linux-Notes.md
Last active August 31, 2018 20:10
Notes on Linux Systems

Linux Boot Process

Bootloaders - Starts the OS:

  • LILO - Linux Loader -
  • GRUB - Grand Unified Bootloader
    • Replaced LILO

initrd - initial RAMDisk

  • Temporary filesystem loaded into memory with helpers that can perform hardware detection and loads modules to get the filesystem mounted
@cmccormack
cmccormack / linux_commands.md
Last active August 30, 2018 15:00
Common Linux commands with examples

tee

The tee utility copies standard input to standard output, making a copy in zero or more files. The output is unbuffered.

Example:

echo "I am the very model of a modern Major General" | tee general.txt
I am the very model of a modern Major General # Output
cat general.txt
I am the very model of a modern Major General # Output
@cmccormack
cmccormack / fake.json
Created October 26, 2018 17:10
Fake JSON for testing
{
"url": "https://api.github.com/gists/53e1780a5a68fe9281cfbbc9820d381f",
"forks_url": "https://api.github.com/gists/53e1780a5a68fe9281cfbbc9820d381f/forks",
"commits_url": "https://api.github.com/gists/53e1780a5a68fe9281cfbbc9820d381f/commits",
"id": "53e1780a5a68fe9281cfbbc9820d381f",
"git_pull_url": "https://gist.github.com/53e1780a5a68fe9281cfbbc9820d381f.git",
"git_push_url": "https://gist.github.com/53e1780a5a68fe9281cfbbc9820d381f.git",
"html_url": "https://gist.github.com/53e1780a5a68fe9281cfbbc9820d381f",
"files": {
"forgeLikeServerSetup.md": {