Skip to content

Instantly share code, notes, and snippets.

@dtbaker
dtbaker / application.rb
Created January 24, 2023 09:08
Debug SQL queries in rails app
module YourApp
class Application < Rails::Application
# all the things....
# Print SQL debug to the console
config.after_initialize do
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.verbose_query_logs = true
@dtbaker
dtbaker / some-auto-login-file.php
Created June 11, 2020 10:19
WordPress set admin cookie programmatically
<?php
include 'wp-load.php';
wp_set_auth_cookie( $wpdb->get_var( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key LIKE '%capabilities%' AND meta_value LIKE '%admin%' LIMIT 1" ) );
@dtbaker
dtbaker / wordpress-hook-debug-snippet.php
Created January 6, 2020 00:28
WordPress hook call stack debug
// WordPress hook call stack debug:
$debug = debug_backtrace();
foreach($debug as $item){
echo $item['file'] .':' .$item['line'] .' - '.$item['function'].'()' ."\n";
if(!empty($item['args']) && is_array($item['args']) && isset($item['args'][1]) && is_string($item['args'][1])){
echo ' --- '. $item['args'][1] ."\n";
}
}
@dtbaker
dtbaker / exportImagesFromFigma.js
Created November 28, 2019 01:09
Extract Images from Figma to S3
// This takes an array of images (from getFigmaImageIds) and exports them to S3.
const exportImagesFromFigma = async ({figmaImages, figmaExportScale = 1}) => {
const figmaFileId = await getSecretConfiguration('figma_file_id')
const figmaApiKey = await getSecretConfiguration('figma_api_key')
const exportedImages = []
const imageIdsToExport = figmaImages.map(image => image.imageId)
@dtbaker
dtbaker / term-meta.php
Last active August 8, 2018 06:31 — forked from chrisdc/term-meta.php
Add a custom meta box to the new/edit category pages. The meta data is saved using update_term_meta.
<?php
/**
*Add meta box to the term category page.
*/
function dtbaker_taxonomy_edit_meta_field( $term ) {
// Retrieve the existing value(s) for this meta field.
$term_meta = $term && !empty($term->term_id) ? get_term_meta( $term->term_id, 'custom_page_id', true ) : false;
?>
<tr class="form-field">
@dtbaker
dtbaker / remote-ip.php
Last active March 17, 2018 21:53
Self hosted Dynamic DNS / No-IP script in PHP
<?php
/**
* Simple Dynamic DNS / No-IP script for Route53
*
* Setup:
* 1) Setup a new Route53 zone to hold your dynamic DNS records (e.g. dynamic.mywebsite.net)
* 2) Make sure this instance has permission to modify this Route53 zone (e.g. instance IAM profile, .aws credentials or ENV variables)
* 3) Upload this PHP script to your instance (make sure vendor files are availalbe by running: composer require aws/aws-sdk-php)
* 4) Put the allowed hostnames in the list below
@dtbaker
dtbaker / map.html
Last active March 10, 2021 19:27
Hide street numbers from Google Maps
<style type="text/css">
#map {
width: 750px;
height: 500px;
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript">

Keybase proof

I hereby claim:

  • I am dtbaker on github.
  • I am dtbaker (https://keybase.io/dtbaker) on keybase.
  • I have a public key ASC97lhPufWpAR3JpYNuOXAUFR0ETsK3xbBuJtdxUsbiIAo

To claim this, I am signing this object:

@dtbaker
dtbaker / foo.php
Created February 26, 2017 03:03
Hacky way to import pictures after a WordPress site migration that didn't go well.
// This will search through all blog content and find/replace <a href> and <img src> links
// It will find images on the old multi-site host, e.g. http://dtbaker.net/wp-content/uploads/sites/* and import those images into the new blog, then update the links/src in the post content.
add_action('init', function(){
if(isset($_REQUEST['do_import'])){
ini_set('display_errors',true);
ini_set('error_reporting',E_ALL);
require_once ('wp-admin/includes/admin.php');
@dtbaker
dtbaker / create-quote.php
Last active June 2, 2018 20:23
Create a quote in UCM from a remote url
<?php
chdir('/path/to/ucm/folder/on/webhost/');
include('init.php'); // the UCM init code.
// login as admin
module_security::user_id_temp_set(1);
$customer_data = array(
'customer_name' => 'Name Here',