Skip to content

Instantly share code, notes, and snippets.

View qmmr's full-sized avatar

Marcin Kumorek qmmr

View GitHub Profile
@qmmr
qmmr / 00-README-NEXT-SPA.md
Created March 25, 2023 16:27 — forked from gaearon/00-README-NEXT-SPA.md
Next.js SPA example with dynamic client-only routing and static hosting

Next.js client-only SPA example

Made this example to show how to use Next.js router for a 100% SPA (no JS server) app.

You use Next.js router like normally, but don't define getStaticProps and such. Instead you do client-only fetching with swr, react-query, or similar methods.

You can generate HTML fallback for the page if there's something meaningful to show before you "know" the params. (Remember, HTML is static, so it can't respond to dynamic query. But it can be different per route.)

Don't like Next? Here's how to do the same in Gatsby.

import { useState, useEffect } from 'react';
// Usage
function App() {
// Call our hook for each key that we'd like to monitor
const happyPress = useKeyPress('h');
const sadPress = useKeyPress('s');
const robotPress = useKeyPress('r');
const foxPress = useKeyPress('f');
@qmmr
qmmr / python-es6-comparison.md
Created March 14, 2019 15:20 — forked from revolunet/python-es6-comparison.md
# Python VS ES6 syntax comparison

Python VS ES6 syntax comparison

Python syntax here : 2.7 - online REPL

Javascript ES6 via Babel transpilation - online REPL

Imports

import math
@qmmr
qmmr / input_output.py
Last active July 11, 2021 10:19
Python Homework Assignment #8: Input and Output (I/O)
"""
Python Homework Assignment #8: Input and Output (I/O)
Details:
Create a note-taking program. When a user starts it up, it should prompt them for a filename.
If they enter a file name that doesn't exist, it should prompt them to enter the text they want to write to the file. After they enter the text, it should save the file and exit.
If they enter a file name that already exists, it should ask the user if they want:
A) Read the file
B) Delete the file and start over
@qmmr
qmmr / main.py
Last active July 29, 2021 04:29
Python Homework Assignment #6: Advanced Loops
"""
pirple.com/python
Python Homework Assignment #6: Advanced Loops
Details:
Create a function that takes in two parameters: rows, and columns, both of which are integers.
The function should then proceed to draw a playing board (as in the examples from the lectures)
the same number of rows and columns as specified. After drawing the board, your function should return True.
@qmmr
qmmr / dict_and_sets.py
Last active July 13, 2021 15:50
Python Homework Assignment #7: Dictionaries and Sets
"""
pirple.com/python
Python Homework Assignment #7: Dictionaries and Sets
Details:
Return to your first homework assignments, when you described your favorite song.
Refactor that code so all the variables are held as dictionary keys and value.
Then refactor your print statements so that it's a single loop that passes through each item in the dictionary
and prints out it's key and then it's value.
@qmmr
qmmr / tipc_and_tricks.py
Last active March 10, 2019 12:56
Tips & tricks in Python 3
"""
A collection of useful tips when working with Python 3
"""
import json
# from collections import Hashable
from random import choice, randrange
# Check if sth is "hashable" cause Sets only store unique and hashable items
# Whereas Lists can store anything
# print("Is empty object {} hashable? -> {0:b} ")
@qmmr
qmmr / main.py
Last active June 29, 2021 05:01
Python Home Assignment #5: Basic Loops
"""
pirple.com/python
Python Home Assignment #5: Basic Loops
You're about to do an assignment called "Fizz Buzz", which is one of the classic programming challenges.
It is a favorite for interviewers, and a shocking number of job-applicants can't get it right.
But you won't be one of those people. Here are the rules for the assignment (as specified by Imran Gory):
- Write a program that prints the numbers from 1 to 100.
- But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz".
@qmmr
qmmr / main.py
Last active June 24, 2021 04:44
Python Homework Assignment #4: Lists
"""
pirple.com/python
Homework Assignment #4: Lists
Create a global variable called myUniqueList. It should be an empty list to start.
Next, create a function that allows you to add things to that list.
Anything that's passed to this function should get added to myUniqueList,
unless its value already exists in myUniqueList.
If the value doesn't exist already it should be added and the function should return True.
@qmmr
qmmr / main.py
Last active August 16, 2023 14:13
Homework Assignment #3: "If" Statements
"""
pirple.com/python
Homework Assignment #3: "If" Statements
If conditionals.
Create a function that accepts 3 parameters and checks for equality between any two of them.
Your function should return True if 2 or more of the parameters are equal,
and false is none of them are equal to any of the others.