Skip to content

Instantly share code, notes, and snippets.

@elhardoum
elhardoum / WordPress Transients - Helper Class.php
Created August 28, 2016 14:19
WordPress Transients - Helper Class - for handling WordPress Transients and caching data and keeping things simple as they should
<?php
/**
* WordPress Transients - Helper Class
*
* Makes it easier to store transients and call them and all in like 4 lines of code
* Helps you save large amounts of data (arrays) without the confusing proccess of
* chunking data into batches, and joining later upon getting all the data and also
* deleting all of these batches correctly. This class does it all for you.
*
<?php
/**
* Get the user country code with package
*
* Requires geoiplookup package installed
* @link http://manpages.ubuntu.com/manpages/trusty/man1/geoiplookup.1.html
* @param $ip user IP string
* @param $args Array (optional parameters)
*/
@elhardoum
elhardoum / folder-live-sync.sh
Created January 19, 2020 13:51
Live sync of your local project with a remote using rsync and monitoring file changes
#!/usr/bin/env sh
function syncfunc(){
[ -f ./livesync.lock ] && exit -1
touch /tmp/livesync.lock
command -v say > /dev/null && say synchronizing || echo synchronizing
rsync -r -a -v -e "ssh -p22" --delete ./ user@host-or-ip:/path/to/remote/folder/eg/root/project1
command -v say > /dev/null && say synchronized || echo synchronized
rm -f /tmp/livesync.lock
}
<?php
require __DIR__ . '/vendor/autoload.php';
use \DrewM\MailChimp\MailChimp;
$mc = new MailChimp('<your-mailchimp-api-key>');
// list ID
// When a user unsubscribes from the list, they cannot be subscribed again
// via the API, so use a unique list for this mailing purpose
@elhardoum
elhardoum / Icon.js
Created June 28, 2019 09:04
OpenWeatherMap SVG icons for React Native
import React from 'react'
import { G, Path } from 'react-native-svg'
import SvgIcon from 'react-native-svg-icon'
export const SvgIcons = {
wi01d: {
svg: <G><Path d="M22.749,35c-6.755,0-12.25-5.495-12.25-12.25s5.495-12.25,12.25-12.25 s12.25,5.495,12.25,12.25S29.504,35,22.749,35L22.749,35z M22.749,14.5c-4.549,0-8.25,3.701-8.25,8.25S18.2,31,22.749,31 s8.25-3.701,8.25-8.25S27.298,14.5,22.749,14.5L22.749,14.5z"/><Path d="M22.999,7c-0.829,0-1.5-0.672-1.5-1.5v-4c0-0.828,0.671-1.5,1.5-1.5 c0.828,0,1.5,0.672,1.5,1.5v4C24.499,6.328,23.827,7,22.999,7L22.999,7z"/><Path d="M14.342,9.186c-0.519,0-1.022-0.269-1.3-0.75l-2-3.463 c-0.415-0.717-0.169-1.635,0.549-2.049c0.717-0.415,1.635-0.169,2.049,0.549l2,3.463c0.415,0.717,0.169,1.635-0.549,2.049 C14.855,9.121,14.597,9.186,14.342,9.186L14.342,9.186z"/><Path d="M7.934,15.408c-0.254,0-0.512-0.064-0.749-0.201l-3.464-2 c-0.717-0.414-0.963-1.331-0.549-2.049s1.331-0.964,2.049-0.549l3.464,2c0.717,0.414,0.963,1.331,0.549,2.049 C8.957,15.14,8.453,15.408,7.934,15.408L7.934,15.408z
@elhardoum
elhardoum / README.md
Last active June 11, 2019 17:22
Capture handles from Twitter

This is a workaround for Twitter search API being limited to only tweets from the past week.

Open Twitter on your favourite browser, open dev-tools, then go to console.

Make sure you are on Twitter search page, searching for your mentioned handle or hashtag or whatever.

Enter the code, it will only capture the handles but you can alter it to capture more data of your choosing.

It will attempt to adjust the page scroll to reach the bottom, in order to load more tweets, until you reach the end.

@elhardoum
elhardoum / chrome-extension-font-reset.css
Created January 25, 2019 10:18
Prevent Chrome from shrinking your extension pages by reducing font-size and forcing a specific font-family
body{font-family:inherit;font-size:initial}
var start = +new Date, d, chrono
setInterval(function()
{
d = new Date( +new Date - start )
chrono = (''+d).match( /\d+:\d+(?= )/g )[0] + ':' + Math.floor(d.getMilliseconds()/100)
document.body.innerHTML = chrono.replace(/(\d+)/g, '<span>$1</span>').replace(':', '\'').replace(':', '"')
}, 100)
<?php
use Predis\Client as PredisClient;
include __DIR__ . '/vendor/autoload.php';
function redis() {
global $Redis;
if ( !isset($Redis) || !$Redis instanceof PredisClient ) {