Skip to content

Instantly share code, notes, and snippets.

@m13z
m13z / twitter_oauth_curl.php
Last active November 22, 2018 02:41
Super simple PHP twitter oauth request without user context (https://dev.twitter.com/docs/auth/application-only-auth)
/*
* using curl
*/
$key = 'YOUR_KEY_HERE';
$secret = 'YOUR_SECRET_HERE';
$api_endpoint = 'https://api.twitter.com/1.1/users/show.json?screen_name=marcosfernandez'; // endpoint must support "Application-only authentication"
// request token
$basic_credentials = base64_encode($key.':'.$secret);
@gregrickaby
gregrickaby / wordpress-transient-caching.php
Last active January 2, 2019 10:45
WordPress Transient Caching
<?php
/**
* Setup wp_query arguments for the loop. Cache the results for 4 hours.
*
* @link http://codex.wordpress.org/Transients_API
*/
// Check for transient
if ( false === ( $my_query = get_transient( 'foo_featured_posts' ) ) ) {
@Abban
Abban / cookie.php
Last active January 4, 2019 21:48
WP Config for multiple environments. Code is for this blog post: http://abandon.ie/wordpress-configuration-for-multiple-environments/
Failed attempts by username:
grep "Invalid user " /var/log/auth.log | cut -d' ' -f8 | awk '{a[$0]++}END{for(i in a)print i,a[i]}' | sort -k 2 -n -r | head -n 100
IP address of each attempt:
grep "Invalid user " /var/log/auth.log | cut -d' ' -f10 | awk '{a[$0]++}END{for(i in a)print i,a[i]}' | sort -k 2 -n -r | head -n 100
Filter for brute-force interactive SSH logins:
grep sshd.\*Failed /var/log/auth.log | less
Look for failed connections (i.e. no login attempted, could be a port scanner, etc.):
@kisabelle
kisabelle / wp-assign-parent-template.php
Created January 22, 2014 19:04
WordPress: Automatically Apply Parent Page Template to Child Pages by Matovu Richard
<?php
function switch_page_template() {
global $post;
// Checks if current post type is a page, rather than a post
if (is_page())
{
// Checks if page is parent, if yes, return
if ($post->post_parent == 0)
return true;
else if ($post->post_parent != $post->ID)
@SaneMethod
SaneMethod / ajaxCachePrefilter.js
Last active May 3, 2019 13:01
Ajax prefilter for caching, based on paul irish's work at https://github.com/paulirish/jquery-ajax-localstorage-cache, made to work with jqXHR Deferred Promises when paired with an appropriate ajaxTransport.
/**
* Prefilter for caching ajax calls - adapted from
* https://github.com/paulirish/jquery-ajax-localstorage-cache, made to work with jqXHR Deferred Promises.
* See also $.ajaxTransport.
* New parameters available on the ajax call:
* localCache : true, // required if we want to use the cache functionality
* cacheTTL : 1, // in hours. Optional
* cacheKey : 'post', // optional
* isCacheValid : function // optional - return true for valid, false for invalid
* @method $.ajaxPrefilter
@cosenary
cosenary / index.php
Last active June 17, 2019 15:04
Instagram API login (with sessions)
<?php
require '../src/Instagram.php';
use MetzWeb\Instagram\Instagram;
session_start();
if (isset($_SESSION['access_token'])) {
// user authentication -> redirect to media
header('Location: success.php');
@carlosleopoldo
carlosleopoldo / select-users.sql
Last active September 12, 2019 23:09
Select users in WordPress without specific user meta key and user id upper than...
-- Select users in WordPress without specific user meta key
-- * Replace meta_name for your meta key
-- * Replace > 0 for the minimum user ID
SELECT wp_users.ID
FROM wp_users
WHERE wp_users.ID > 0
AND wp_users.ID NOT IN (
SELECT DISTINCT user_id FROM wp_usermeta WHERE meta_key = 'meta_name'
)
@isuke01
isuke01 / custom-wp.ajax
Last active November 18, 2019 18:12
Custom WP ajax, capable of using SHORTINIT, and much faster than standard WP
<?php
/*
If you use short init by passing argument shortinit.
You have base and a bit more wp components loaded, like get_meta, current user .. etc.
*/
if (!isset( $_POST['action']))
die('-1');
if ( isset( $_POST['shortinit']) ){
$type = trim($_POST['shortinit']);
@mynameispj
mynameispj / dropdown.html
Last active December 22, 2019 16:05
Simple jQuery dropdown boxes that disappear when you click outside of them
<a class="drop-down-toggle">Click me to reveal drop down box below...</a>
<div class="drop-down-wrapper">
Hello, I will be revealed!
</div>