Skip to content

Instantly share code, notes, and snippets.

@Toshinaki
Toshinaki / Wagtail FormBuilder + drf.md
Last active October 18, 2021 08:00
create submissions to wagtail forms created with formbuilder, with django rest framework

Thanks to the friendly and detailed advice of @LB from Wagtail community (https://wagtail.io/slack/)

views.py

class FormSubmissionViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet):
    """
    A viewset for viewing and editing contact form submissions.
    """

    serializer_class = FormSubmissionSerializer
@Toshinaki
Toshinaki / versionTag.sh
Last active February 23, 2023 17:16
Detect latest version tag and create a new version based on that and commit type. Only work for "major.minor.patch" format.
#!/bin/bash
# get current tag
curr=`git describe --tags --abbrev=0` || curr=""
newTag=""
# check if tag exists
if [ -n "$curr" ]
then
# got latest tag
@Toshinaki
Toshinaki / common-regex.md
Created June 2, 2023 14:18
Commonly used regular expressions.

All regex are in Javascript syntax.

  • URL validation: (http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)
@Toshinaki
Toshinaki / @lodash.ts
Created November 24, 2023 13:38
lodash custom mixin
import __ from 'lodash';
/**
* You can extend Lodash with mixins
* And use it as below
* import _ from '@lodash'
*
* copy the file and remove functions that not needed
*/
const _ = __.runInContext();
@Toshinaki
Toshinaki / Options.tsx
Last active January 13, 2024 03:00
Custom Mantine Select takes in any object as option and a custom renderer. Basically a copy of the built-in [Select](https://mantine.dev/core/select/).
import classes from './Select.module.css';
import { ReactNode, memo } from 'react';
import clsx from 'clsx';
import _ from '@lodash';
import { isOptionGroup } from './utils';
import { CheckIcon, Combobox, ScrollArea } from '@mantine/core';
import type { ParsedOption, ParsedOptionGroup } from '../types';
interface OptionProps<T extends object> {
data: ParsedOption<T> | ParsedOptionGroup<T>;
@Toshinaki
Toshinaki / MultiSelect.module.css
Created January 13, 2024 03:03
Custom Mantine MultiSelect takes in any object as option and a custom renderer. Basically a copy of the built-in [MultiSelect](https://mantine.dev/core/multi-select/).
/* ------- OptionsDropdown ------- */
.optionsDropdownScrollArea {
margin-right: calc(var(--_combobox-padding) * -1);
@mixin rtl {
margin-left: calc(var(--_combobox-padding) * -1);
margin-right: 0;
}
}