Skip to content

Instantly share code, notes, and snippets.

View luckydonald's full-sized avatar
👀
294 people are currently looking at this profile

Luckydonald luckydonald

👀
294 people are currently looking at this profile
  • Some basement in Equestria.
View GitHub Profile
@luckydonald
luckydonald / utf8_javascript_decode
Created May 12, 2016 23:40
utf8 javascript decode
https://jsfiddle.net/wfr4tLku/0/ # http://stackoverflow.com/a/36949791/3423324
http://jsfiddle.net/Z9pQE/44/ # http://stackoverflow.com/a/17192845/3423324
http://jsfiddle.net/3VuLx/244/ # http://stackoverflow.com/a/22373135/3423324
@luckydonald
luckydonald / image_sizer.py
Last active January 18, 2022 19:21
A script to scale images to a monitor resulution and add the best fitting background color
"""
Makes border aware sizing of desktop wallpapers.
You need to install:
$ pip install Pillow easygui joblib
"""
import glob
import os
@luckydonald
luckydonald / answer.md
Last active January 9, 2023 19:14
How to get the hostnames and informations of other hosts in the same docker scale grouping. http://stackoverflow.com/a/39895650/3423324

The way I could do it was by using the docker api. I used the docker-py package to access it.

The api exposes a labels dictionary for each container, and the keys com.docker.compose.container-number, com.docker.compose.project and com.docker.compose.service did what was needed to build the hostname.

The code below is a simplified for code I am now using. You can find my advanced code with caching and fancy stuff that at Github at luckydonald/pbft/dockerus.ServiceInfos (backup at gist.github.com).

<?php
define('BOT_TOKEN', 'XXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXX'); // place bot token of your bot here
function checkTelegramAuthorization($auth_data) {
$check_hash = $auth_data['hash'];
unset($auth_data['hash']);
$data_check_arr = [];
foreach ($auth_data as $key => $value) {
$data_check_arr[] = $key . '=' . $value;
@luckydonald
luckydonald / diff.patch
Created March 4, 2018 11:46 — forked from strazzere/diff.patch
rsakeyfinder
[35%]tstrazzere@bebop:[rsakeyfind] $ diff rsakeyfind.cpp-fixed rsakeyfind/rsakeyfind.cpp-original
colordiff 1.0.10 (http://colordiff.sourceforge.net/)
(C)2002-2012 Dave Ewart, davee@sungate.co.uk
4,5d3
<
< #include <unistd.h>
8a7
> #include <fcntl.h>
<html>
<head>
<title>Test</title>
<meta charset="utf-8" />
<meta name="apple-mobile-web-app-title" content="something" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, height=device-height">
<style>
@luckydonald
luckydonald / function.cast.php
Created July 23, 2018 21:14 — forked from borzilleri/function.cast.php
PHP function to cast an object from one class to another.
<?php
/**
* Cast an object into a different class.
*
* Currently this only supports casting DOWN the inheritance chain,
* that is, an object may only be cast into a class if that class
* is a descendant of the object's current class.
*
* This is mostly to avoid potentially losing data by casting across
* incompatable classes.
def num(n):
string = ["", "", ""]
for d in str(int(n)):
for i, l in enumerate(digit(int(d)).split("\n")):
string[i] += l
# end for
# end for
return "\n".join(string)
# end def
@luckydonald
luckydonald / gist:cfde4c8107da30390b17ddc35b964f4a
Created June 11, 2019 13:54 — forked from nerones/gist:6778719
An easy way to log session data and queries with Monolog and Hooks in codeigniter. Some of the code is taken from Profiler class in the core of CI. The hook must be post_controller or post_system
class LoggerHook
{
private $CI;
function __construct()
{
$this->CI =& get_instance();
}
public function log()
{
@luckydonald
luckydonald / python_like_exception.php
Last active March 23, 2020 21:20
python style exception trace for PHP
static function python_like_exception(
Throwable $e, bool $skip_seen = true, ?array $seen = null
): string {
if ($skip_seen && !$seen) {
$seen = array();
}
$prev = $e->getPrevious();
if ($prev) {
$result[] = self::python_like_exception($prev, $skip_seen, $seen);
$result[] = "\nDuring handling of the above exception, another exception occurred:\n";