Skip to content

Instantly share code, notes, and snippets.

@PotcFdk
PotcFdk / mult-persistence.lua
Last active March 21, 2019 15:15
calculating multiplicative persistence in Lua
local function per (n, steps)
steps = steps or 0
if n < 10 then return steps end
local m = 1
for d in string.gmatch (tostring (n), ".") do
m = m * tonumber (d)
end
print ("STEP #" .. steps+1 .. ": " .. n .. " -> " .. m)
return per (m, steps+1)
end
// ==UserScript==
// @name BackToOldReddit
// @namespace https://gist.github.com/PotcFdk
// @match *://www.reddit.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
var currentURL = window.document.location.toString();
if(currentURL.includes("//www")) {
var newURL = currentURL.replace("//www","//old");
@PotcFdk
PotcFdk / repo-reset.cmd
Last active May 15, 2018 10:29
Windows and Linux cross-platform shell script to reset a git or svn repo to origin's state
#!/bin/sh
:; # This file runs on both Windows and Linux. / (c) PotcFdk, 2018
:<<":GITRESET"
echo off
cls
if not exist .git goto PRESVNRESET
:GITRESET
:; if [ -d .git ]; then
echo Resetting working copy to origin/master...
git fetch && git checkout master && git reset --hard origin/master && git clean -xdf
@PotcFdk
PotcFdk / shebang.c
Created February 4, 2018 19:44 — forked from CRTified/shebang.c
Shebangs
#!/usr/bin/env sh
#if 0
TMPFILE=$(mktemp);
tail -n +10 $0 | gcc -march=native -o $TMPFILE -x c -;
$TMPFILE "${@:1}";
RETVAL=$?
rm $TMPFILE;
exit $RETVAL;
#endif
@PotcFdk
PotcFdk / callmonitor.sh
Last active December 5, 2017 19:54
FRITZ!Box Callmonitor shell script
#!/bin/bash
OLDIFS=$IFS
ask() {
# http://djm.me/ask
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
@PotcFdk
PotcFdk / status.json.lua
Last active December 5, 2017 19:54
FRITZ!Box Fon WLAN 7170 status script
<?lua
box.header("Cache-Control: no-cache\n")
box.header("Content-Type: text/plain; charset=utf-8\n")
box.header("Expires: -1\n")
box.header("Pragma: no-cache\n\n")
dofile ("/usr/www/avm/errors/kids/dkjson.lua")
?>
<?lua
while [ true ]; do
while read line; do
id=$(echo "$line" | grep Location | sed 's/^Location.*\/\/ipfs\.pics\/\([^#]*\).*$/\1/g')
if [ -n "$id" ]; then
echo -n " - "
if grep -Fxq "$id" ipfs-pics-ids.txt; then
echo ".. $id"
else
echo -n "++ "
echo "$id" | tee -a ipfs-pics-ids.txt
@PotcFdk
PotcFdk / cast-away-const.cpp
Created February 15, 2016 12:11
Casting away const.
#include <iostream>
using namespace std;
class Class
{
public:
char c = 'c';
};
/* pi-goroutines.go
* This spams Goroutines to calculate pi.
* Not a great approach, I just wanted to play around with Goroutines and channels.
*
* PotcFdk, 2015
*/
package main
import (
TEST_TABLE = {}
TEST_TABLE.value = 0xB
print (0xA .. " >= " .. TEST_TABLE.value .. ": ", 0xA >= TEST_TABLE.value)
if (0xA >= 0xB) then
print ("0xA >= 0xB") -- If this prints, your computer is insane.
elseif (0xA >= TEST_TABLE.value) then
print ("That is numberwang!") -- You have been wangernumbed.
end