Skip to content

Instantly share code, notes, and snippets.

View stanlemon's full-sized avatar

Stan Lemon stanlemon

View GitHub Profile
@stanlemon
stanlemon / UpgradeJourneyFinder.java
Last active April 22, 2023 14:00
Upgrade interview question: Find the valid 'journeys' for src/dest including connecting flights.
package com.stanlemon;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
@stanlemon
stanlemon / CreateShareV2.swift
Last active January 29, 2023 18:23
Attempting to create a zone share for a CoreData object via just CloudKit
func createShareV2(_ object: NSManagedObject, title: String) async -> CKShare? {
Logger.shared.notice("Creating share for object")
guard let record = persistentCloudKitContainer.record(for: object.objectID) else {
Logger.shared.info("Could not find CKRecord for object to share")
return nil
}
let container = CKContainer.default()
let database = container.privateCloudDatabase
@stanlemon
stanlemon / migrate_db.sql
Created December 6, 2014 01:30
Migrate tables from one database to another
DROP PROCEDURE IF EXISTS migrate_db;
DELIMITER //
CREATE PROCEDURE migrate_db(IN dbnameFrom CHAR(255), IN dbnameTo CHAR(255))
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE tableName CHAR(255);
DECLARE tableCursor CURSOR FOR SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = dbnameFrom;
OPEN tableCursor;
@stanlemon
stanlemon / func_speed.php
Last active April 6, 2024 04:03
Test the speed of calling a function in various ways in PHP.
<?php
function fooBar($hello, $world) {
// Nothing to see here...
}
$results = array();
// TEST 1: call_user_func
@stanlemon
stanlemon / puppet-percona.pp
Created March 16, 2013 21:31
A sample puppet manifest for configuring Percona with the mysql module.
yumrepo { "Percona":
name => "Percona",
descr => "Percona Server",
baseurl => "http://repo.percona.com/centos/\$releasever/os/\$basearch/",
enabled => 1,
gpgcheck => 0,
}
file { '/etc/init.d/mysqld':
ensure => 'link',
@stanlemon
stanlemon / deploy
Created March 16, 2013 19:31
A sample ./.openshift/action_hooks/deploy for Red Hat's OpenShift platform to install composer dependencies upon deployment.
#!/bin/bash
# This deploy hook gets executed after dependencies are resolved and the
# build hook has been run but before the application has been started back
# up again. This script gets executed directly, so it could be python, php,
# ruby, etc.
export COMPOSER_HOME="$OPENSHIFT_DATA_DIR/.composer"
if [ ! -f "$OPENSHIFT_DATA_DIR/composer.phar" ]; then
curl -s https://getcomposer.org/installer | /usr/local/zend/bin/php -- --install-dir=$OPENSHIFT_DATA_DIR