Skip to content

Instantly share code, notes, and snippets.

@bq1990
bq1990 / models.py
Created November 17, 2023 21:52
Cascade delete SqlAlchemy
class Parent(Model):
__tablename__ = "parent"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
class Child(Model):
__tablename__ = "child"
from decimal import Decimal
import sys
import time
import boto3
from boto3.dynamodb.conditions import Key
session = boto3.Session(profile_name='anil')
client = session.resource('dynamodb')
@bq1990
bq1990 / gist:2c88da6f9c0bdefbdbc108b2e393addc
Created June 21, 2019 20:12
Heroku pull db using sql dump
heroku run 'pg_dump -xO $DATABASE_URL' -a myapp | psql mydb
[ req ]
default_bits = 4096
prompt = no
encrypt_key = no
default_md = sha256
distinguished_name = dn
req_extensions = req_ext
[ dn ]
CN = example.com
@bq1990
bq1990 / gist:acc83001a7c9fcd18e820213920b4359
Last active June 2, 2019 19:00
Update max upload size on bitnami
/opt/bitnami/php/etc/php.ini
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
sudo /opt/bitnami/ctlscript.sh restart php-fpm
@bq1990
bq1990 / bundle.sh
Created May 19, 2019 18:28
Bundle Python requirements in zip file
#!/bin/bash
pip install -r requirements.txt --target ./packages
if [ -d packages ]; then
cd packages
find . -name "*.pyc" -delete
find . -name "*.egg-info" | xargs rm -rf
zip -9mrv packages.zip .
mv packages.zip ..
cd ..
rm -rf packages
@bq1990
bq1990 / urllib.py
Created May 15, 2019 20:14
use urllib to post with basic auth
import base64
from datetime import datetime
import urllib.request
import urllib.parse
data = urllib.parse.urlencode({'recorded': datetime.utcnow(), 'product': 'LALA', 'amount': 20000}).encode()
url = 'http://localhost:8000/api/'
request = urllib.request.Request(url)
credentials = ('%s:%s' % ('user', 'pass!'))
encoded_credentials = base64.b64encode(credentials.encode('ascii'))
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MQTT console for AWS IoT Core with MQTT over WebSocket</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/aws-sdk/2.404.0/aws-sdk.min.js" integrity="sha256-5j5NcghceMlKBa2qXSGw6l24mOkiXOsdi9sB21pBips=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.2/mqttws31.min.js" integrity="sha256-UplsBBNj5zR16Nyo1bVLLVd0ndtLYs0A5c4WrbK/etU=" crossorigin="anonymous"></script>
<script>/* from https://docs.aws.amazon.com/ja_jp/iot/latest/developerguide/protocols.html */
/**
@bq1990
bq1990 / awsiot_thing_shadow_core.html
Created May 2, 2019 00:21 — forked from ma2shita/awsiot_thing_shadow_core.html
AWS IoT's Thing Shadow access w/ Websocket over MQTT and Cognito
<!--
AWS IoT's Thing Shadow access w/ Websocket over MQTT and Cognito
-->
<script type="text/javascript" src="https://sdk.amazonaws.com/js/aws-sdk-2.3.9.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/sha256.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/hmac-sha256.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/ma2shita/2c5a4c29242dd5382b05ce941731fd41/raw/eb4bc16c02e7a72bbd0086e937050c258da09a20/sigv4utils.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/ma2shita/63fb1dfd07753dc1ff67fe98132c0bc0/raw/ef50f3ec3276dd1c5dd90a3003e5105045b837e2/mqttws31.js"></script>
<script>
@bq1990
bq1990 / Wagtail dynamic templates
Created October 11, 2018 22:15 — forked from bgrace/Wagtail dynamic templates
Override Wagtail CMS templates based on the URL of the incoming request. Search by specific URL, then look for templates which override by model type.
class PathOverrideable(object):
def get_template(self, request, mode='', **kwargs):
try:
return self._path_overrideable_template
except AttributeError:
if not self.url:
return get_template(self.template)