Skip to content

Instantly share code, notes, and snippets.

View stemount's full-sized avatar
📺
As seen on TV

Stephen Mount stemount

📺
As seen on TV
View GitHub Profile
const t1 = performance.now();
let count_y = 0;
let count_n = 0;
for (let i = 0; i < 10_000; i++) {
let message = `!play ${i}`;
if (/^!(play|playball|givecompliment)(?:\s+(\w+))?$/.test(message))
count_y += 1;
else
@stemount
stemount / keybase.md
Created February 3, 2021 18:37
keybase.md

Keybase proof

I hereby claim:

  • I am stemount on github.
  • I am stemount (https://keybase.io/stemount) on keybase.
  • I have a public key ASD6A4CIlxYm1WRLfAdZc87WfoqMRoJFRZSUE0XQUBtgWAo

To claim this, I am signing this object:

@stemount
stemount / regex.js
Created December 15, 2020 12:57
Official Gov.UK Postcode Regex remixed (allowing space e.g. SW1V 2AA)
([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([AZa-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))[0-9][A-Za-z]{2})
@stemount
stemount / ReactUseCallbackBefore.js
Last active October 31, 2020 17:17
React useCallback does not work with submit handler with an empty value.
const App = () => {
const [ title, setTitle ] = React.useState('');
const handleSubmit = React.useCallback((event) => {
event.preventDefault();
console.log(title);
alert(`the value of title is ${title}`);
}, []);
const handleTitleChange = React.useCallback(
@stemount
stemount / tsconfig.json
Created October 13, 2020 01:47
TSConfig
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"lib": [
"dom",
"es6",
"es2018",
"esnext.asynciterable"
],
@stemount
stemount / Nested.ts
Created August 21, 2020 08:37
type-graphql hack/scalar for Nested field validation - take inspiration from this (and even just see if it works!)
import { Field } from 'type-graphql';
import { ValidateNested } from 'class-validator';
import { plainToClass } from 'class-transformer';
export function Nested(options?: { each?: boolean; nullable?: boolean }) {
return (target: any, propertyName: string) => {
const Ctx = Reflect.getMetadata(
'design:type',
target.constructor.prototype,
propertyName
const dot = require('dot-object');
exports.getProductsBySpecs = async(req,res,next) => {
try{
const q = req.query;
const specificationsInDotNotation = dot.dot(req.query.filter((key) => {
// Only allow size/color attributes.
return key === 'size' || 'color';
}));
@stemount
stemount / WinningFunction.js
Created May 18, 2020 18:13
If you are sharing code with `@todo` tags, definitely share via Gist as those not using IDEs like Sublime/whatever won't have `@todo` highlighted
// @todo #winning is subjective and should not always return true.
winning = function () {
return true;
}
@stemount
stemount / ForceRevokeAllLaravelPassportAndLaravelSessions.php
Last active January 3, 2020 12:35
Force/Revoke All Laravel User Sessions and Passport Tokens
string(65) "=== Forcibly logging out xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx ==="
string(325) "revoking user token {"id":"xxxxxxxx","user_id":"xxxxxxxx","client_id":215,"name":"UserToken","scopes":[],"revoked":true,"created_at":"2020-01-03 11:53:21","updated_at":"2020-01-03 11:53:21","expires_at":"2040-01-03 11:53:21"}"
string(68) "=== Forcibly logged out out xxxxxxxx-xxxxxxxx-4646-9854-xxxxxxxx ==="
@stemount
stemount / enable_php73_extensions.sh
Created August 19, 2019 12:36
How to enable PHP 7.3 phpenmod extensions mysql sqlite ext-bcmath mysqli composer.json Laravel Ubuntu 18.04 LTS 19.04 Debian Pop_OS!
sudo phpenmod ext-bcmath
sudo phpenmod mysqlnd
sudo phpenmod opcache
sudo phpenmod pdo
sudo phpenmod xml
sudo phpenmod calendar
sudo phpenmod ctype
sudo phpenmod curl
sudo phpenmod dom
sudo phpenmod exif