Skip to content

Instantly share code, notes, and snippets.

View squio's full-sized avatar

Johannes la Poutre squio

View GitHub Profile
@squio
squio / RoundRobinArray.js
Last active November 26, 2021 11:43
Round robin array iterator in Javascript
/**
* Round robin array iterator
* @param {string | any[]} arr
*/
function* RoundRobinArray(arr) {
let idx = 0;
for (;;) {
yield arr[idx];
idx++;
if (idx >= arr.length) {
@squio
squio / settings.py
Created October 25, 2021 15:43
Add 2fa authentication to dj_rest_auth login
# in settings.py
REST_AUTH_SERIALIZERS = {
# override dj_rest_auth serializer for 2fa
'LOGIN_SERIALIZER': 'my_app.serializers.user.LoginSerializer'
}
@squio
squio / app-resume.service.spec.ts
Last active April 5, 2022 10:35
Ionic App Resume
import { TestBed } from '@angular/core/testing';
import { AppResumeService } from './app-resume.service';
describe('AppResumeService', () => {
let service: AppResumeService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(AppResumeService);
@squio
squio / urls.py
Created June 8, 2021 08:20
Use url with uid and token generated by dj-rest-auth for actual password reset routine from django allauth
urlpatterns = [
# this path is used to generate email content for password reset request
# from dj-rest-auth API; format is same as used by default django auth so
# the generated URL must be translated to be used with allauth
path('accounts/password/reset/key/api/<uidb64>/<token>/',
user.ApiPasswordResetView.as_view(),
name='password_reset_confirm'),
]
@squio
squio / hex2str.js
Created May 17, 2021 09:08
Space separated hex dump to ascii in javascript
let chs = "7b 22 72 65 73 22 3a 22 6c 6f 67 69 6e 22 2c 22 73 74 61 74 22 3a 34 30 33 2c 22 6d 73 67 22 3a 22 43 6f 64 65 20 65 78 70 69 72 65 64 22 7d"
let str = chs.split(" ").map(ch => String.fromCharCode(parseInt(ch, 16))).join("")
@squio
squio / base62.cpp
Last active September 24, 2021 11:05
Base62 encoding / decoding
// Base62 encoding / decoding
// Test: `g++ -Wall -g -std=c++11 base4.cpp && ./a.out`
#include <iostream>
#include <algorithm>
#include <time.h>
#include <assert.h>
static const char alphanum[] =
"0123456789"
@squio
squio / account_adapter.py
Created May 10, 2021 12:56
Use configured Site name instead of request host Django (Rest) Auth
from allauth.account.adapter import DefaultAccountAdapter
from django.contrib.sites.shortcuts import get_current_site
from django.contrib.sites.models import Site
class AccountAdapter(DefaultAccountAdapter):
def get_email_confirmation_url(self, request, emailconfirmation):
""" Override to get domain name from Sites configuration instead of request """
# when 'request' is empty, the url from Sites is used
try:
// Insert geoseach JS after leaflet JS files from yii2-leaflet-extension
// https://github.com/2amigos/yii2-leaflet-extension
// https://github.com/smeijer/leaflet-geosearch
$this->registerJsFile('https://unpkg.com/leaflet-geosearch@3.0.0/dist/geosearch.umd.js', [
'depends' => [\dosamigos\leaflet\LeafLetAsset::class]
]);
// Create a customized SVG pin icon on the fly
// uses vars: lat, lon, color, title
// map is leaflet Map object
const color = '#cc0000';
const svg = `<?xml version="1.0" encoding="UTF-8"?><svg width="27" height="53.5" version="1.1" viewBox="-31 -22 22 18" xmlns="http://www.w3.org/2000/svg"><path d="m-20 8.8889c-2-20-10-22-10-30a10 10 0 1 1 20 0c0 8-8 10-10 30zm-2-30a2 2 0 1 1 4 0 2 2 0 1 1-4 0" fill="${color}" stroke="#000" stroke-width=".8"/></svg>`;
const iconUrl = 'data:image/svg+xml;base64,' + btoa(svg);
const icon = L.icon({
iconUrl: iconUrl,
iconAnchor: [13.5, 53],
@squio
squio / pihole-hiseeu-webcam.txt
Last active December 28, 2020 21:43
A blocklist for all domains used by the Hiseeu webcam
MOVED: https://github.com/squio/oneliners/blob/main/pi-hole/pihole-hiseeu-webcam.txt