This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import time | |
items = [] | |
lock = threading.Lock() # Shared lock object for our threads. | |
# Thread work function. | |
def do_work(): | |
thread_id = threading.get_ident() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
# PerfTimer is a class that allows us to use instances in a 'with' block thanks | |
# to the special '__enter__' and '__exit__' functions. | |
class PerfTimer: | |
def __init__(self, name): | |
self.name = name | |
def __enter__(self): | |
self.start_time = time.perf_counter() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import math | |
pygame.init() | |
BLACK = (0, 0, 0) | |
WHITE = (255, 255, 255) | |
# Set the dimensions of the window | |
size = (800, 600) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, pygame | |
import random | |
pygame.display.init() | |
size = width, height = 1000, 1000 | |
background = 0, 0, 0 | |
screen = pygame.display.set_mode(size) | |
pygame.display.set_caption("Balls") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Post Converter</title> | |
</head> | |
<body> | |
<textarea id="src" cols="100" rows="50">[t] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fasty import * | |
@get("/") | |
def index(): | |
return "Hello from my very own HTTP framework called Fasty!" | |
@get("/weather") | |
def weather(): | |
return "It's raining." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns the amount of seconds between two given dates. | |
* @param {Date} dtStart The start time. | |
* @param {Date} dtEnd The end time. | |
* @returns The number of seconds between the two dates. | |
*/ | |
function secondsBetween(dtStart, dtEnd) { | |
var diff = (dtStart.getTime() - dtEnd.getTime()) / 1000; | |
return Math.abs(diff); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import json | |
def loadWeather(city): | |
url = f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid={your API key goes here}&units=imperial' | |
with urllib.request.urlopen(url) as response: | |
data = response.read() | |
result = json.loads(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<h1 id="cnt">0</h1> | |
<script type="text/javascript"> | |
const state = { | |
count: 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8'> | |
<meta http-equiv='X-UA-Compatible' content='IE=edge'> | |
<title>Layout Example</title> | |
<meta name='viewport' content='width=device-width, initial-scale=1'> | |
<style> | |
/* Default styling for mobile phones (mobile first CSS) */ | |
.container { |