Skip to content

Instantly share code, notes, and snippets.

View gering's full-sized avatar

Robert Gering gering

View GitHub Profile
@gering
gering / stripchars.lua
Created March 21, 2018 10:02
Remove chars from a string
function stripchars(str, chrs)
local s = str:gsub("["..chrs:gsub("%W","%%%1").."]", '')
return s
end
@gering
gering / tprint.lua
Last active March 28, 2018 10:36
Print a Lua table
function tprint(t, s)
for k, v in pairs(t) do
local kfmt = '["' .. tostring(k) ..'"]'
if type(k) ~= 'string' then
kfmt = '[' .. k .. ']'
end
local vfmt = '"'.. tostring(v) ..'"'
if type(v) == 'table' then
tprint(v, (s or '')..kfmt)
else
@gering
gering / MainQueue.cs
Last active May 3, 2017 08:35
Handle execution on main thread in Xamarin projects
using Xamarin.Forms;
namespace System.Threading.Tasks {
public static class MainQueue {
static int mainThreadId = int.MinValue;
public static void Init() {
Init(Environment.CurrentManagedThreadId);
}
@gering
gering / Toolkit
Last active January 25, 2024 12:32
persitent data path handling in Unity with fallback
private static string[] _persistentDataPaths;
public static bool IsDirectoryWritable(string path) {
try {
if (!Directory.Exists(path)) return false;
string file = Path.Combine(path, Path.GetRandomFileName());
using (FileStream fs = File.Create(file, 1)) {}
File.Delete(file);
return true;
} catch {
@gering
gering / gist:4223970adb86a26c2161
Last active August 29, 2015 14:22
Remove Bash History
# delete history
history -cw
# or
cat /dev/null > ~/.bash_history && history -c && exit
@gering
gering / docker-rm-all.sh
Last active August 29, 2015 14:21
Remove all Docker Container and Images
#!/bin/bash
# Stop all containers
docker stop $(docker ps -a -q)
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@gering
gering / install-docker.sh
Created May 22, 2015 10:30
Install Docker
#!/bin/sh
# Install Docker
curl -sSL https://get.docker.com/ | sh