Skip to content

Instantly share code, notes, and snippets.

@mcaskill
mcaskill / wp-ajax.php
Last active May 6, 2024 16:20 — forked from yllus/admin-ajax.php
WordPress : A drop-in replacement for admin-ajax.php that is optimized for visitor-only AJAX requests.
<?php
/**
* WordPress Ajax Process Execution
*
* This file is a near-identical copy of {@see wp-admin/admin-ajax.php} from WordPress v6.3.0.
*
* Differences:
* 1. Constant `WP_ADMIN` is set to FALSE, by default.
* 2. WordPress action 'admin_init' is replaced with custom action 'ajax_init'.
* 4. Custom actions hooked on 'admin_init' are not executed.
@rwilkes
rwilkes / TOSStrategyTemplate.ts
Created March 22, 2020 07:15
ThinkScript: Code Template for Writing Strategjes
# thinkscript strategy template
##############################################################
####################### Strategy Setup #####################
##############################################################
# Common settings for studies
input length = 14;
input over_sold = 20;
input over_bought = 80;
@wrighter
wrighter / download_bars.py
Last active May 5, 2025 10:32
A command line utility to download historical data from Interactive Brokers
#!/usr/bin/env python
import os
import sys
import argparse
import logging
from datetime import datetime, timedelta
from typing import List, Optional
from collections import defaultdict
@sserbest
sserbest / ssh-notes.md
Last active January 28, 2019 19:09
SSH’ing to different machines with the same IP

Like a lot of people, I ditched my desktop in 2007 and moved to a laptop as my main computer. I take my Macbook Pro to work everyday and it’s also my personal computer at home.

To make life simpler I have an almost identical network set up at home as we do in the office, using the same DHCP range and gateway address (our dev server is also our gateway in the office). So the development server I SSH into at work has the same IP as my home linux box. At work we have internal DNS set up, I’m a little more lazy at home and just refer to my linux box by IP.

A problem arises doing this though; since I connected to the office development server with SSH first, it got first place in my known_hosts file, consequently when I connect to my home linux server (with the same internal IP address) I’m presented with a warning ‘REMOTE HOST IDENTIFICATION HAS CHANGED!’ and I that I could be subject to a ‘man in the middle attack’.

SSH warning - remote host identification changed Oh noes! Of course this isn’t really the case

@villesiltala
villesiltala / get_post_by_slug.php
Last active February 12, 2025 18:54
WordPress - Get a post by its post name (slug) and cache results.
<?php
/**
* Get a post object by its post name (slug).
*
* @param string $slug The post name value.
* @param string $post_type The post type to fetch from. Default: 'post'.
*
* @return \WP_Post|bool The post object if found, false if not.
*/
@holmberd
holmberd / php-pools.md
Last active April 29, 2025 08:29
Adjusting child processes for PHP-FPM (Nginx)

Adjusting child processes for PHP-FPM (Nginx)

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?

Determine if the max_children limit has been reached.

  • sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log
@MikeNGarrett
MikeNGarrett / functions.php
Created October 13, 2017 20:11
Set cache headers on WordPress 404 pages.
<?php
/**
* Force cache headers on 404 pages and prevent WordPress from handling 404s.
*
* @param bool $preempt determines who handles 404s.
* @param obj $wp_query global query object.
*/
function change_404_headers( $preempt, $wp_query ) {
if ( ! is_admin() && ! is_robots() && count( $wp_query->posts ) < 1 ) {
header( 'Cache-Control: max-age=30000, must-revalidate' );
@sserbest
sserbest / index.html
Created June 26, 2017 02:07
Infinite scroll with scrollspy
<div class="uk-container uk-container-center" style="min-height:600px">
<h1>Infinite list</h1>
<ul class="uk-list uk-list-line" id="infinite-list"></ul>
<div id="scrollspy" data-uk-scrollspy="{topoffset: 200, repeat: true}" class="uk-text-center">
<i class="uk-icon-refresh uk-icon-spin uk-hidden"></i>
</div>
<script type="text/listtemplate">
@AustinGil
AustinGil / functions.php
Last active September 14, 2020 11:56
JSON-LD for WordPress posts
/**
* Remove hentry from post_class
* This is important to not get schema errors
*/
function visceral_remove_hentry_class( $classes ) {
$classes = array_diff( $classes, array( 'hentry' ) );
return $classes;
}
add_filter( 'post_class', 'visceral_remove_hentry_class' );
@cecilemuller
cecilemuller / letsencrypt_2020.md
Last active January 9, 2025 12:22
How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SSL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SLL rating)


Virtual hosts

Let's say you want to host domains first.com and second.com.

Create folders for their files: