Skip to content

Instantly share code, notes, and snippets.

View freekrai's full-sized avatar

Roger Stringer freekrai

View GitHub Profile
@freekrai
freekrai / demo.php
Last active April 13, 2024 20:48
PHP session-based rate limiter for APIs
<?php
date_default_timezone_set('America/Los_Angeles');
session_start();
include("ratelimiter.php");
// in this sample, we are using the originating IP, but you can modify to use API keys, or tokens or what-have-you.
$rateLimiter = new RateLimiter($_SERVER["REMOTE_ADDR"]);
$limit = 100; // number of connections to limit user to per $minutes
$minutes = 1; // number of $minutes to check for.
@freekrai
freekrai / Boyer-Moore-Horspool.php
Created February 24, 2012 19:32
Boyer-Moore-Horspool string matching algorithm
<?php
define('UCHAR_MAX',255);
function boyermoore_horspool_memmem($haystack,$needle){
$hlen = strlen($haystack);
$nlen = strlen($needle);
$scan = 0;
$bad_char_skip[UCHAR_MAX + 1];
if ($nlen <= 0 || !$haystack || !$needle) { return NULL; }
for ($scan = 0; $scan <= UCHAR_MAX; $scan = $scan + 1)
$bad_char_skip[$scan] = $nlen;
@freekrai
freekrai / Readme.md
Last active October 29, 2023 17:31 — forked from AceCodePt/hx-astro-view-transition.js
htmx-astro-view-transition

Add it to the body

<body hx-ext="hx-astro-view-transition">

An example

@freekrai
freekrai / keybase.md
Created October 19, 2023 20:51
keybase.md

Keybase proof

I hereby claim:

  • I am freekrai on github.
  • I am zolomongrundi (https://keybase.io/zolomongrundi) on keybase.
  • I have a public key ASA2Q6OMJSsnkl9WjhSIfoTH9X_uz7ERBWtq4r7f5ZT2Ago

To claim this, I am signing this object:

@freekrai
freekrai / Pinboard.py
Created December 3, 2012 18:52
Post to Pinboard
import console
console.show_activity()
import urllib
from urllib import urlencode
import bs4
import requests
import webbrowser
import sys
import sound
sound.load_effect('Powerup_2')
@freekrai
freekrai / gcc.sh
Last active May 28, 2023 21:34
Fedora gcc 4.8.2 Installation instructions
#!/bin/bash
echo "installing gcc"
sudo rpm --import http://ftp.scientificlinux.org/linux/scientific/5x/x86_64/RPM-GPG-KEYs/RPM-GPG-KEY-cern
wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
yum install -y devtoolset-2-gcc-4.8.2 devtoolset-2-gcc-c++-4.8.2 devtoolset-2-binutils devtoolset-2-libstdc++-devel-4.8.2
sleep 2
ln -s /opt/rh/devtoolset-2/root/usr/bin/* /usr/local/bin/
hash -r
gcc --version
@freekrai
freekrai / fasting.js
Last active February 15, 2023 00:43
Intermittent fasting timer widget for scriptable
/*
Copy this to scriptable
When creating a widget, add the hours you start fasts and eating time (ie 19:00,8:00)
Also set fastingInterval to the number of hours your eating time has.
*/
const canvSize = 282;
const canvTextSize = 40;
const canvas = new DrawContext();
canvas.opaque = false
@freekrai
freekrai / directus-example
Last active August 16, 2022 14:25
Shell script to download Directus examples from GitHub without having to clone entire repo
#! /usr/bin/env bash
if [ -z "$1" ]; then
echo USAGE: "$0" EXAMPLE
exit
fi
url="https://github.com/directus/examples/$1"
# default to branch master
branch=main
@freekrai
freekrai / boyer-moore.php
Created February 24, 2012 19:31
Boyer-Moore string match algorithm
<?php
define('ALPHABET_SIZE',1);
function compute_prefix($str,$size,&$result=0)
{
$result = $result[$size + 1];
$q;
$k;
$result[0] = 0;
@freekrai
freekrai / grab thumb url.php
Last active November 15, 2021 10:30 — forked from jlengstorf/grab thumb url.php
If no featured image... Grab the first image in the post content.. Or generate a thumbnail based on youtube or vimeo video if that is included instead of an image... then save the image as featured image...
<?php
/**
* Retrieves the thumbnail URL to use for a post
* @param string $text The body of the post (get_content)
* @param string $size The image size to retrieve
* @return string The image URL to use
*/
function get_thumb_url($text, $size){
global $post;
$imageurl = FALSE;