Skip to content

Instantly share code, notes, and snippets.

@itailulu
itailulu / google-apps-script-get-driving-distance.gs
Created January 28, 2024 06:59
Google Apps Script - Get Driving Distance
/**
* A custom function that gets the driving distance between two addresses.
*
* @param {String} origin The starting address.
* @param {String} destination The ending address.
* @return {Number} The distance in meters.
*/
function drivingDistance(origin, destination) {
const directions = getDirections(origin, destination);
return directions.routes?.[0]?.legs?.[0]?.distance?.value || 'Error';
@itailulu
itailulu / make-scenarios-consumption.js
Last active January 9, 2024 15:18
Get Make.com Scenarios Consumption
/**
* ----------------------------------------------
* Make Scenarios Consumption Data Extractor
* ----------------------------------------------
* This script is designed to efficiently extract and process
* consumption data for various scenarios from Make's API.
* It enables easy integration of this data into spreadsheet applications
* by formatting the data for straightforward copy-pasting.
*
*
@itailulu
itailulu / create_monthly_partitions_for_partitioned_table.sql
Created March 31, 2022 19:26
Create monthly partitions for a partitioned table in Postgres
/**
Running 'SELECT create_monthly_partitions_for_partitioned_table( 'party_test', '2021-11-15', '2022-01-15' );'
Will result in executing the following statements:
`CREATE TABLE party_test_y2021_m11 PARTITION OF party_test FOR VALUES FROM ('2021-11-01 00:00:00+00') TO ('2021-12-01 00:00:00+00');`
`CREATE TABLE party_test_y2021_m12 PARTITION OF party_test FOR VALUES FROM ('2021-12-01 00:00:00+00') TO ('2022-01-01 00:00:00+00');`
`CREATE TABLE party_test_y2022_m01 PARTITION OF party_test FOR VALUES FROM ('2022-01-01 00:00:00+00') TO ('2022-02-01 00:00:00+00');`
*/
CREATE OR REPLACE FUNCTION create_monthly_partitions_for_partitioned_table(base_table TEXT, start_month DATE, end_month DATE) RETURNS VOID AS
$$
@itailulu
itailulu / dbsh.sh
Last active December 15, 2021 20:32
Interactively bash into a docker container, without having to type it's full name - just pick its number!
dbsh() {
docker ps --format '{{.Names}}' | nl -s ") "
echo "Pick container"
read CONTAINER
CONTAINER_NAME=$(docker ps --format '{{.Names}}' | sed -n "${CONTAINER}p")
docker exec -ti $CONTAINER_NAME /bin/bash
}
@itailulu
itailulu / add-users.sh
Last active October 28, 2021 06:58
Wireguard: Add multiple clients script. Based on angristan/wireguard-install
#!/bin/bash
# This script is based on code from https://github.com/angristan/wireguard-install and might not work if you use another script. Use it on your own responsibility.
# Usage: `./add-users.sh "marty;emmet;biff"`
# Check if WireGuard is already installed and load params
if [[ -e /etc/wireguard/params ]]; then
source /etc/wireguard/params
else
echo "wireguard is not installed, please install using this script: https://github.com/angristan/wireguard-install"
@itailulu
itailulu / upw-only-posts-with-thumbnail.php
Last active August 29, 2015 14:21
Add filter to only load posts with thumbnails when the "show thumbnail" option is selected
add_filter('upw_wp_query_args', 'upw_only_posts_with_thumbnails',10 , 2);
function upw_only_posts_with_thumbnails($args, $instance) {
if ( $instance['show_thumbnail'] ) {
$args['meta_query'] = array(
array(
'key' => '_thumbnail_id',
'compare' => 'EXISTS'
)
);
@itailulu
itailulu / gist:9802978
Created March 27, 2014 08:33
Filter array
//returns keys and values of $arr if key exist in $keys
function filter_array(array $arr, array $keys){
$ret = array();
foreach ( $keys as $k ){
if (array_key_exists($k,$arr)){
$ret[$k] = $arr[$k];
}
}