Skip to content

Instantly share code, notes, and snippets.

View andyg2's full-sized avatar
🎯
Focusing

Andy Gee andyg2

🎯
Focusing
View GitHub Profile
@andyg2
andyg2 / parse_nestable.php
Last active July 8, 2023 02:16
Full circle nestable js structure to flat array and back to nested.
<?php
$json = '[{
"id": 8,
"text": 8,
"children": [{
"id": 3,
"text": 3,
"children": [{
"id": 1,
"text": 1,
@andyg2
andyg2 / parse_jquery_sortable.php
Created August 27, 2019 08:55
Full circle jquery sortable structure to flat array and back to nested.
<?php
//updated gist for additional array wrapping and empty children arrays (required)
$json = '[{
"name": "Item 1",
"id": 0,
"children": [
[]
]
@andyg2
andyg2 / jsTable.js
Last active May 29, 2021 06:43
Generates an HTML table from an arbitrary JavaScript object
function render_jsTable(jsTable) {
// build arbitrary HTML table from object
var html = [];
var table = $("<table>");
var thead = $("<thead>").appendTo(table);
var tbody = $("<tbody>").appendTo(table);
if (jsTable.tableData.table) {
$.each(jsTable.tableData.table, function (key, val) {
@andyg2
andyg2 / watermark-image-uploads.php
Created October 2, 2021 04:35 — forked from Viper007Bond/watermark-image-uploads.php
Watermark WordPress Image Uploads
<?php
/*
* Plugin Name: WordPress.com Watermark Image Uploads
* Author: Alex Mills
* Author URI: http://automattic.com/
*/
class WPcom_Watermark_Uploads {
public $watermark;
@andyg2
andyg2 / index.html
Created March 10, 2022 08:26
Vector Connect
<html>
<head>
<!-- Load the Paper.js library -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.11.5/paper-full.js"></script>
<!-- Define inlined PaperScript associate it with myCanvas -->
<script type="text/paperscript" canvas="myCanvas">
var myPath = new Path();
myPath.strokeColor = 'black';
@andyg2
andyg2 / grid.php
Created March 11, 2022 22:04
Grid to Coordinates / Coordinates to Grid
<?php
// 10 pixel per grid
define('IMAGE_WH', 25); // Pixels
define('SQUARE_RC', 5); // Columns/Rows
define('IMAGE_SQ_RATIO', IMAGE_WH / SQUARE_RC); //10
function cellToCoords($cell) {
$x = (($cell - 1) % SQUARE_RC) + 1;
$y = ceil($cell / SQUARE_RC);
@andyg2
andyg2 / readstream.php
Created March 15, 2022 09:17
Write Stream to File
<?php
$ip = '192.168.2.113';
// 192.168.2.114
// 192.168.2.120
$path = './'.$ip.'-stream-'.date('Y-m-d-H-i-s').'.xml';
$url = 'http://'.$ip.'/clickit/analyticsdata.cgi?timeout=100000';
do_capture($url, $path);
@andyg2
andyg2 / jq-click-message.js
Created December 14, 2022 12:50
Add a bouyant message on click
var a_idx = 0;
$(document).on("click", function (e) {
var a = new Array("Click!". "Another Click!", "Add loads");
var $i = $("<span/>").text(a[a_idx]);
a_idx = (a_idx + 1) % a.length;
var x = e.pageX,
y = e.pageY;
$i.css({
"z-index": 999999999999,
"top": y - 20,
@andyg2
andyg2 / spawn-restart-scripts.php
Last active December 14, 2022 20:20
Script to spawn a bunch of CLI scripts in the background and restart any that fail.
<?php
$scripts = [];
$scripts[] = 'ping google.com > google.txt';
$scripts[] = 'ping msn.com > msn.txt';
function spawn_scripts($scripts) {
$pids = [];
// iterate scripts, building list of indexed PIDs
@andyg2
andyg2 / bookmarklet.js
Last active March 24, 2023 17:48
Bookmark-let to summarize a web page using GPT-3 - written by GPT-3
javascript: (function () {
var text = document.body.innerText;
var spl = text.split(" ");
if (spl.length > 3000) {
text = spl.slice(0, 3000).join(" ");
}
fetch('https://api.openai.com/v1/completions', {
method: 'POST',
headers: {