Skip to content

Instantly share code, notes, and snippets.

View jonathan-s's full-sized avatar
🍵
Constantly drinking tea.

Jonathan Sundqvist jonathan-s

🍵
Constantly drinking tea.
View GitHub Profile
044a67388db31d9df360003456f57920b20db8e7263407dfa2ad30ec83c332eee8aaa90192950a606b1357e84afaddb7255f3e8708ad54fce57979f6a62f16174a;jsoucheiron
from django.db import models
from django.db import connection
from django.db.models.sql.datastructures import Join
class JoinQueryset(models.QuerySet):
def join(self, qs=None):
'''
Either uses the current queryset and effectively does a self-join to
create a new limited queryset OR it uses a querset given by the user.
code --install-extension ZigaGrcar.theme-monokai-phoenix
code --install-extension bibhasdn.django-html
code --install-extension Cameron.rerun-last-command
code --install-extension CoenraadS.bracket-pair-colorizer
code --install-extension dbaeumer.jshint
code --install-extension dbaeumer.vscode-eslint
code --install-extension donjayamanne.githistory
code --install-extension DotJoshJohnson.xml
code --install-extension esbenp.prettier-vscode
code --install-extension GrapeCity.gc-excelviewer

Keybase proof

I hereby claim:

  • I am jonathan-s on github.
  • I am argparse (https://keybase.io/argparse) on keybase.
  • I have a public key ASAM1dd0xTa4t_6ecm939rNaW0kioxjYb4mMiyTxp41pogo

To claim this, I am signing this object:

@jonathan-s
jonathan-s / package.json
Last active April 15, 2020 07:38
The most minimal setup for webpack that loads javascript from a directory and spits out the compiled version of that javascript. Probably needs babel as well.
{
"name": "foxflash-backend",
"version": "1.0.0",
"description": "Generate javascript and css",
"main": "index.js",
"scripts": {
"build": "webpack --mode production",
},
"repository": {
"type": "git"
@jonathan-s
jonathan-s / decorator.py
Created May 7, 2020 16:41
Reminder for how decorators work, so I don't need to look it up.
def method_decorator(argument, argument2):
# decorator name used here.
def decorator(func, argument=argument, argument2=argument2):
# the function passed and we need to pass the arguments as well.
# I couldn't get it to work otherwise.
def wrapped(self, argument=argument, argument2=argument2, *fargs, **fkwargs):
# the first argument is self, this is a decorator for methods.
# passing the arguments again. Otherwise trouble.
# here we also get the function arguments.
@jonathan-s
jonathan-s / webpack.config.js
Created May 10, 2020 12:16
Webpack configuration that could be used as a starting point.
const webpack = require('webpack');
const glob = require('glob');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
// npm install needed
// css-loader postcss-loader postcss-import tailwindcss autoprefixer mini-css-extract-plugin glob
let globOptions = {
ignore: [
'./node_modules/**',
@jonathan-s
jonathan-s / controller_stuff.js
Last active December 22, 2020 14:00
Stimulus.js snippets that are useful for controllers, see it as a playground for now.
import { Controller } from 'stimulus'
export default class extends Controller {
addClasses(element) {
let toId = element.dataset.toId
let toElement
if (toId) {
toElement = document.getElementById(toId)
} else {
@jonathan-s
jonathan-s / btc_carbon_impact.md
Last active February 17, 2021 22:29
The carbon impact of btc per usd.

Bitcoin

Every 10 minutes a new block is mined. A year contains 525960 minutes. So there are 52596 blocks in a year.

Currently 6.25 btc is mined in each block. That means that 52596 * 6.25 = 328725 btc is minted this year.

The estimates of the energy impact the bitcoin network has depends on the source. Cambridge centre for alternative finance gives an upper bound of 281.76 TWh, an estimated bound of 123.99 TWh and a lower bound of 42.05 TWh.

Digiconomist estimates a number of 77.78 TWh.

import flask
import requests
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor,
)