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 / code.php
Last active May 21, 2022 10:48
Add a custom control to an existing Elementor widget
// This example will add a custom "select" drop down to the "Image Box"
// This will change the class="" on the rendered image box so we can style the Image Box differently
// based on the selected option from the editor.
// The class will be "my-image-box-style-blue" or "my-image-box-style-green" based on the selected option.
add_action('elementor/element/before_section_end', function( $section, $section_id, $args ) {
if( $section->get_name() == 'image-box' && $section_id == 'section_image' ){
// we are at the end of the "section_image" area of the "image-box"
$section->add_control(
@dtbaker
dtbaker / vc_theme.php
Created September 17, 2015 02:08
Visual Composer update script for including in 3rd party themes
<?php
/**
* Visual Composer Update script for 3rd party Themes
* Details here: http://dtbaker.net/web-development/visual-composer-plugin-updates-in-3rd-party-themes/
* Author: dtbaker
*
*/
// ************* CHANGE ME *************** change me to your server side visual composer update URL
@dtbaker
dtbaker / vc_update.php
Created September 17, 2015 01:20
Server side Visual Composer update script
<?php
/**
* Visual Composer Extended License Updater
* Server Side Update Script
* Author: dtbaker
* Details: http://dtbaker.net/web-development/visual-composer-plugin-updates-in-3rd-party-themes/
*
* Upload this script to your website (e.g. yourwebsite.com/vc_update.php)
* Adjust the API key to your own
* Add the other code into your WordPress theme
@dtbaker
dtbaker / class.envato2.php
Created October 9, 2015 02:57
Using the verify-purchase endpoint of the new Envato API to validate a purchase code.
<?php
// NOTE: verify-purchase has been deprecated and it's best to use the new /author/sale endpoint as documented on http://build.envato.com/
// created by Envato user wpdreams https://forums.envato.com/t/verify-purchase-class/3526
// usage example:
$o = EnvatoApi2::verifyPurchase( $purchase_code );
@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 / 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">
@dtbaker
dtbaker / class.envato-api-basic.php
Last active December 21, 2020 06:15
Simple PHP class for interacting with the Envato API within a WordPress plugin
<?php
/**
* Exception handling class.
*/
class EnvatoException extends Exception {
}
@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 / db.php
Created July 19, 2016 02:43
Upgrade from mysql_connect() to mysqli_connect() - handle port number and socket.
// These are examples of MySQL host names that will work fine in mysql_connect() but fail in mysqli_connect()
// If you are upgrading an old script to mysqli the client may have configured these as values for their database server.
// The below script parses out port number or socket and translates that into a correct mysqli_connect() call.
define('_DB_SERVER', '1.2.3.4:3306');
define('_DB_SERVER', '1.2.3.4:/tmp/socket4');
if(function_exists('mysqli_connect')){
$server = _DB_SERVER;
$port_number = null;
$socket = null;