Skip to content

Instantly share code, notes, and snippets.

View m-radzikowski's full-sized avatar

Maciej Radzikowski m-radzikowski

View GitHub Profile
@m-radzikowski
m-radzikowski / script-template.sh
Last active April 8, 2024 03:04
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@m-radzikowski
m-radzikowski / migrate-comments-to-giscus.py
Last active April 7, 2024 20:35
Migrate comments from WordPress wpDiscuz (https://wpdiscuz.com/) to Giscus (https://giscus.app/) powered by GitHub Discussions
import hashlib
import re
from time import sleep
from urllib.parse import urlparse
import requests
from bs4 import BeautifulSoup
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
from markdownify import markdownify as md
@m-radzikowski
m-radzikowski / cdk.json
Created March 15, 2023 10:58
Context parameters example for Opinionated CI Pipeline (https://github.com/merapar/opinionated-ci-pipeline)
{
"app": "...",
"context": {
"projectName": "myproject",
"environments": {
"default": {
"account": "111111111111",
"region": "us-east-1"
},
"prod": {
@m-radzikowski
m-radzikowski / cdk.ts
Last active March 15, 2023 10:55
Minimal usage example of Opinionated CI Pipeline (https://github.com/merapar/opinionated-ci-pipeline)
import {CDKApplication} from 'opinionated-ci-pipeline';
import {MyStack} from '../lib/myStack';
new CDKApplication({
stacks: {
create: (scope, projectName, envName) => {
new MyStack(scope, 'MyStack', {stackName: `${projectName}-${envName}-MyStack`});
},
},
repository: {
#!/usr/bin/env bash
# Personal script to setup Linux Mint
# and install bunch of tools.
set -euo pipefail
echoerr() { echo "$@" 1>&2; }
ensure_sudo() {
@m-radzikowski
m-radzikowski / cognito-app-client-auth.sh
Last active May 24, 2021 22:34
Amazon Cognito App Client authorization
#!/usr/bin/env bash
# Discover Cognito User Pool and API Gateway params,
# authorize with Cognito App Client ID and Secret
# and make request to the API.
# set Cognito and API Gateway params
REGION="eu-west-1"
USER_POOL_NAME="apiAuth-dev"
CLIENT_NAME="MyServiceClient"
@m-radzikowski
m-radzikowski / LICENSE
Created December 15, 2020 16:22
This license applies to all public gists https://gist.github.com/m-radzikowski
MIT License
Copyright (c) 2020 Maciej Radzikowski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@m-radzikowski
m-radzikowski / TruncateHtmlExtension.php
Created July 2, 2013 19:13
Twig Filter for Symfony 2 - truncate HTML string without stripping tags after reach the minimum length of displayed text
<?php
/**
* Twig Filter for Symfony 2 - truncate HTML string without stripping tags after reach the minimum length of displayed text
* Truncates only first-level tags after reach the minimum, so returned text will be >= minimum
* Works well with (only?) utf-8 encoding.
*
* Installation:
* 1. Add this file to your bundle into src/Acme/DemoBundle/Twig/TruncateHtmlExtension.php
* 2. Update namespace, if your bundle isn't Acme/DemoBundle
* 3. Register it in app/config.yml:
<?php
/**
* Twig Filter for Symfony 2 - check if asset exists.
*
* Modified Alain's Tiemblo code: http://stackoverflow.com/a/16906315/2512304
*
* Installation:
* 1. Add this file to your bundle into src/Acme/DemoBundle/Twig/AssetExistsExtension.php
* 2. Update namespace, if your bundle isn't Acme/DemoBundle
* 3. Register it in app/config.yml:
@m-radzikowski
m-radzikowski / DropAllTables
Last active August 29, 2015 14:11
Drops all tables, views and routines in database. Based on http://stackoverflow.com/a/18625545/2512304
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
-- drop tables
SET @tables = NULL;
SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables
FROM information_schema.tables
WHERE table_schema = (SELECT DATABASE()); -- from currently selected schema
SELECT IFNULL(@tables, 'dummy') INTO @tables; -- to prevent error when there are already no tables