Skip to content

Instantly share code, notes, and snippets.

View m3g4p0p's full-sized avatar
💭
waits until idle

m3g4p0p

💭
waits until idle
View GitHub Profile
import json
import pickle
from contextlib import contextmanager
import requests
def hash_args(args, kwargs):
return hash(json.dumps((args, kwargs), sort_keys=True))
@m3g4p0p
m3g4p0p / roles.go
Created October 15, 2021 19:35
Another Safe Enum in Go
package main
import (
"errors"
"fmt"
)
type role string
const (
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Monaco</title>
</head>
<body>
import sys
from itertools import product
class Hint:
def __init__(
self,
digits,
wrongly_placed=0,
well_placed=0
@m3g4p0p
m3g4p0p / load-script.js
Last active October 22, 2020 09:58
Dynamically load JavaScript
// Using vanilla JS
const script = document.createElement('script')
script.src = 'my-script.js'
document.body.appendChild(script)
// Using jQuery
const $script = $('<script />').prop('src', 'my-script.js')
$(document.body).append($script)
@m3g4p0p
m3g4p0p / bookmarklet
Created September 29, 2020 11:12
cache purging bookmarklet
javascript:(function(){!function(e)%7Bvar%20t%3D%7B%7D%3Bfunction%20n(r)%7Bif(t%5Br%5D)return%20t%5Br%5D.exports%3Bvar%20o%3Dt%5Br%5D%3D%7Bi%3Ar%2Cl%3A!1%2Cexports%3A%7B%7D%7D%3Breturn%20e%5Br%5D.call(o.exports%2Co%2Co.exports%2Cn)%2Co.l%3D!0%2Co.exports%7Dn.m%3De%2Cn.c%3Dt%2Cn.d%3Dfunction(e%2Ct%2Cr)%7Bn.o(e%2Ct)%7C%7CObject.defineProperty(e%2Ct%2C%7Benumerable%3A!0%2Cget%3Ar%7D)%7D%2Cn.r%3Dfunction(e)%7B%22undefined%22!%3Dtypeof%20Symbol%26%26Symbol.toStringTag%26%26Object.defineProperty(e%2CSymbol.toStringTag%2C%7Bvalue%3A%22Module%22%7D)%2CObject.defineProperty(e%2C%22__esModule%22%2C%7Bvalue%3A!0%7D)%7D%2Cn.t%3Dfunction(e%2Ct)%7Bif(1%26t%26%26(e%3Dn(e))%2C8%26t)return%20e%3Bif(4%26t%26%26%22object%22%3D%3Dtypeof%20e%26%26e%26%26e.__esModule)return%20e%3Bvar%20r%3DObject.create(null)%3Bif(n.r(r)%2CObject.defineProperty(r%2C%22default%22%2C%7Benumerable%3A!0%2Cvalue%3Ae%7D)%2C2%26t%26%26%22string%22!%3Dtypeof%20e)for(var%20o%20in%20e)n.d(r%2Co%2Cfunction(t)%7Breturn%20e%5Bt%5D%7D.bind(null%2Co))%3Breturn%2
@m3g4p0p
m3g4p0p / lazy-getter.js
Created September 4, 2020 17:50
lazily get object properties
const lazyGetter = (getters) => Object.create(null, Object
.keys(getters)
.reduce((result, key) => Object.assign(result, {
[key]: {
get () {
const value = getters[key].call(this)
Object.defineProperty(this, key, { value })
return value
},
configurable: true
@m3g4p0p
m3g4p0p / app.py
Created August 8, 2020 13:25
eel window communication
import eel
eel.init('.')
@eel.expose
def send_message(message):
eel.on_message(message)
@m3g4p0p
m3g4p0p / index.html
Last active May 6, 2022 18:48
local storage communication
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
<input id="message">
<script>
@m3g4p0p
m3g4p0p / inner.html
Created July 30, 2020 18:15
Monitor events inside iframe
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Inner</title>
</head>
<body>
<a href="#" id="my-link">Click me</a>
</body>
</html>