Skip to content

Instantly share code, notes, and snippets.

@cattaka
cattaka / shrink_db.sql
Created March 24, 2020 08:10
The snippet for delete rows with temporally enable delete cascade for all tables
DROP FUNCTION IF EXISTS shrink_db;
CREATE FUNCTION shrink_db() RETURNS VOID AS $$
DECLARE
r RECORD;
BEGIN
DROP TABLE IF EXISTS work1;
CREATE TEMP TABLE work1 AS SELECT
CONCAT('ALTER TABLE ', nsp.nspname, '.', rel.relname, ' DROP CONSTRAINT "', con.conname, '";') delete_query,
CONCAT('ALTER TABLE ', nsp.nspname, '.', rel.relname, ' ADD CONSTRAINT ', con.conname, ' ', pg_get_constraintdef(con.oid), ' ON DELETE CASCADE;') create_cascade,
CONCAT('ALTER TABLE ', nsp.nspname, '.', rel.relname, ' ADD CONSTRAINT ', con.conname, ' ', pg_get_constraintdef(con.oid)) create_original,
#include <Arduino.h>
#include <M5Stack.h>
#include <WiFi.h>
#include <HTTPClient.h>
#define CYAN 0x07FF
#define ORANGE 0xFDA0
#define LIGHTGRAY 0xC618
#define FW 6
#define FH 8
function doGet(e) {
var now = new Date();
var sheet = getSheetOfDate(now);
var rawWeightFrom = e && e.parameter && e.parameter.raw_weight_from;
var rawWeightTo = e && e.parameter && e.parameter.raw_weight_to;
var etc = e && e.parameter && e.parameter.etc;
var response;
if (rawWeightTo) {
// https://stackoverflow.com/a/17637159
WITH SRC AS (
SELECT
_TABLE_SUFFIX ldate,
*
FROM `hoge.analytics_123456789.events_intraday_*`
-- WHERE _TABLE_SUFFIX = '2019-07-25'
),
TD_COMPAT AS (
@cattaka
cattaka / mutter_fix_scroll.patch
Created May 21, 2019 20:57
Patch Gnome 3.30 for Workspace-Gridhttps://medium.com/@hkdb/patch-gnome-3-30-for-workspace-grid-1ee8b1dd92f9
--- ./mutter-3.30.2_orig/src/core/meta-workspace-manager.c 2019-05-22 05:46:37.667434418 +0900
+++ ./mutter-3.30.2/src/core/meta-workspace-manager.c 2019-05-22 05:46:46.859495121 +0900
@@ -200,6 +200,8 @@ meta_workspace_manager_new (MetaDisplay
* variable values in update_num_workspaces ()
* This can be overriden using _NET_DESKTOP_LAYOUT in
* meta_x11_display_new (), if it's specified */
+ workspace_manager->workspace_layout_overridden = FALSE;
+
meta_workspace_manager_update_workspace_layout (workspace_manager,
META_DISPLAY_TOPLEFT,
@cattaka
cattaka / MakerbotReplicatorDualForCura
Created December 28, 2018 16:35
Settings for MakerbotReplicatorDual on Cura
{
"version": 2,
"name": "My Custom",
"inherits": "fdmprinter",
"metadata": {
"visible": true,
"author": "Ultimaker",
"manufacturer": "Custom",
"category": "Custom",
"file_formats": "text/x-gcode",
#!/bin/bash
NUM=$1
if [[ ! "$NUM" =~ ^[0-9]+$ ]] || [ "$NUM" -le 0 ]; then
echo "Usage: launch-emurators.sh <num>"
exit
fi
EMULATOR_PIDS=""
CREATE TEMPORARY FUNCTION pullFromQueryParams(s string, key string)
RETURNS string
LANGUAGE js AS """
// function pullFromQueryParams(s, key) {
if (!s) return null;
var ts = s.split("&");
for (var i = 0;i<ts.length;i++) {
var vs = ts[i].split("=",2);
if (vs[0] == key && vs.length >= 2) {
return decodeURIComponent(vs[1]);
@cattaka
cattaka / convert_odp_gif_apng.sh
Created September 28, 2018 06:26
Convert GIF files in ODP to APNG to upload Google Slide
#!/bin/bash
if [ -z "$1" -o -z "$2" ]; then
echo "Usage: $0 <from_file> <to_file>"
exit
fi
FROM_FILE=$1
TO_FILE=$2
WORK_DIR=_tmp
# Acer
SUBSYSTEM=="usb", ATTR{idVendor}=="0502", MODE="0660", GROUP="plugdev"
# ASUS
SUBSYSTEM=="usb", ATTR{idVendor}=="0b05", MODE="0660", GROUP="plugdev"
# Dell
SUBSYSTEM=="usb", ATTR{idVendor}=="413c", MODE="0660", GROUP="plugdev"
# Foxconn
SUBSYSTEM=="usb", ATTR{idVendor}=="0489", MODE="0660", GROUP="plugdev"
# Fujitsu
SUBSYSTEM=="usb", ATTR{idVendor}=="04c5", MODE="0660", GROUP="plugdev"