Skip to content

Instantly share code, notes, and snippets.

View squio's full-sized avatar

Johannes la Poutre squio

View GitHub Profile
// 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/[email protected]/dist/geosearch.umd.js', [
'depends' => [\dosamigos\leaflet\LeafLetAsset::class]
]);
@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:
@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 / 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 / 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 / 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 / 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 / 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 / submit_line.html.md
Last active January 11, 2025 14:16
Override Django Admin submit_line.html

Enhancing https://stackoverflow.com/posts/65938495/

It is also possible to override/extend the innermost {% block submit-row %} like so:

{% extends 'admin/submit_line.html' %}
{% load i18n admin_urls %}

{% block submit-row %}
 {% if extra_button_allowed %}
@squio
squio / ipv4toint.js
Created March 25, 2022 14:32
Translate an IPv4 address into an integer
const ip='192.168.1.123';
const decimal_ip = ip.split('.').reverse().map((e,i) => parseInt(e)*(2**(8*i))).reduce((sum, n) => sum + n);
// decimal_ip = 3232235899