Skip to content

Instantly share code, notes, and snippets.

@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}
@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 / 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
}
@elhardoum
elhardoum / test.sh
Last active May 20, 2020 16:02
Testing your load balancer servers for downtime, ignores SSL errors assuming you're testing the core of your web service
#!/usr/bin/env sh
host="www.example.com"
ips=(
93.184.216.34
)
for ip in "${ips[@]}"; do
curl -H "Host: $host" "https://$ip/" -kIs |grep 200\ OK >/dev/null && (
echo "\033[0;32m[✓] $ip\t(passed)"
<?php
// temporarily disable post_title matching for wp query search
add_filter('posts_where_paged', $disablePostTitleSearch=function( string $sql )
{
return str_replace('.post_title LIKE ', '.post_content LIKE ', $sql);
});
// now query posts
$posts = query_posts([
@elhardoum
elhardoum / upload.js
Last active August 12, 2020 14:25
Handle file uploads in node.js without express
// call fileUploadRequestHandler( req, res ) from http.createServer callback context
// change ./files references to your files directory name
async function fileUploadRequestHandler( req, res )
{
const fs = require(fs), path = require('path')
// update the file name/ext here to a random or dynamic one (e.g supplied from querystring)
const filename = 'example.txt'
@elhardoum
elhardoum / game.js
Created December 4, 2020 15:26
Simple Connect 4 Game with JavaScript
const game_elem = document.getElementById('game')
, game = JSON.parse(JSON.stringify(new Array(game_elem.childElementCount-1).fill(
new Array(game_elem.children[0].childElementCount).fill(null)
)))
const colors = { 1: 'red', 2: 'green' }
, color_style = document.getElementById('bg-styles')
, status = document.getElementById('status')
let current_player = 1
@elhardoum
elhardoum / linode-cpu-stats.js
Last active January 20, 2021 04:24
fetch Linode servers last CPU percentage usage with JavaScript since the official CLI doesn't support this yet.
(async () =>
{
/*
* Remember to login to linode dashboard, and from there open the devtools > console and run this code.
*/
console.log('Fetching linodes...')
const linodes = await fetch('https://cloud.linode.com/api/v4/linode/instances/?page_size=100', {
headers: {
authorization: localStorage.getItem('authentication/token'),
@elhardoum
elhardoum / nodebalancer-automated-setup.js
Created January 20, 2021 19:10
Automatically add servers to your Linode nodebalancer. It's painful to do it manually when you have dozens of servers to add
/**
* Please change your nodebalancer configuration in `payload` line 6, and clusters configurations
* in lines 13 and 19
*
* This must be run within cloud.linode.com/ dashboard, ideally via DevTools > Console (or snippets)
*/
const payload = { "protocol": "tcp", "proxy_protocol": "none", "algorithm": "source", "stickiness": "table", "check": "none", "check_interval": 5, "check_timeout": 3, "check_attempts": 2, "port": 443, "check_passive": true, "cipher_suite": "recommended", "nodes": [] }
, ips = [] // a list of your IP addresses
, promises = []