Skip to content

Instantly share code, notes, and snippets.

@tluyben
tluyben / explainquery.pl
Created January 15, 2020 12:09
explain all mysql queries in log
#!/usr/bin/perl
# enable query log for mysql
open(F, "tail -f ~/query.log|");
while(<F>){
chomp;
if (/\d+\s+Execute\s+(select.*)$/igsm) {
print "\n\nQuery: $1 : \n";
$qry = $1;
$qry =~ s/\`/\\\`/isgm;
@tluyben
tluyben / ListView.cs
Created December 12, 2019 15:10
ListView with Checkbox - not working
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Data;
using Avalonia.Controls.Templates;
using Avalonia.Controls.Primitives;
using System;
namespace Playground
@tluyben
tluyben / ListView.cs
Created December 12, 2019 09:51
Avalonia dynamic list (with Dictionary)
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Data;
using Avalonia.Controls.Templates;
namespace Playground
{
public class ListItem
public static string PrintStructure(this VisualElement obj, string indent = "")
{
if (obj == null) return "";
var ot = obj.GetType().GetTypeInfo();
var s = indent + ot.Name + " [";
if (obj.StyleId != null && obj.StyleId.Length > 0)
{
@tluyben
tluyben / backup.sh
Created March 10, 2019 09:17
automatically update wp
#!/bin/bash
export PATH=/usr/local/wp-cli/bin:$PATH
[[ $@ =~ ^\/home\/(.*?)\/www ]];
cp updatewp_user.sh $@
cd $@
echo $@
chown -R ${BASH_REMATCH[1]}.${BASH_REMATCH[1]} .
iptables -I INPUT -p tcp ! -s x.x.x.x --dport 8545 -j DROP
@tluyben
tluyben / FindType.cs
Created September 9, 2018 01:53
Type.GetType(string t) without having the full name
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{
foreach(var _t in a.GetTypes())
{
if (_t.Name == t)
{
return _t;
}
}
}
@tluyben
tluyben / Forth1.cs
Last active April 7, 2024 22:00
A minimal Forth implementation in C#
/*
* Minimal .NET Forth implementation. Just an experiment. Do not use for anything serious.
* by Tycho Luyben (https://github.com/tluyben)
*
* The only 'primitive' (built-in) is an foreign function interface word which allows you to define
* whatever is needed, for example:
*
* hello System.String System.Console.WriteLine ffi
*
* will print hello.
@tluyben
tluyben / cli.go
Created May 5, 2018 16:18
Calculate WIF from a private key
package main
import (
"fmt"
"os"
"encoding/hex"
"github.com/mr-tron/base58/base58"
)
func main() {
@tluyben
tluyben / background.cs
Last active November 30, 2017 18:56
Hangfire actions without all the serialization issues (won't survive server restart or multiple servers, but easier to make that work as well)
Random r = new Random();
static ConcurrentDictionary<int, Action> actions = new ConcurrentDictionary<int, Action>();
public static void ExecuteAction(int i)
{
Action a;
actions.Remove(i, out a);
a();
}