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
@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 / 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 / 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 / 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'];
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'))