Skip to content

Instantly share code, notes, and snippets.

View Glutexo's full-sized avatar
🇨🇿
Wypili moją krew na hejnał

Glutexo Glutexo

🇨🇿
Wypili moją krew na hejnał
  • Frýdek, Czechia
View GitHub Profile
@Glutexo
Glutexo / current-date-and-time.applescript
Created September 14, 2014 12:48
AppleScript to get current date and time (YYYY-MM-DD HH:MM:SS). Usable as a Text Service in Mac OS X.
(*
The zero_pad function taken from:
http://www.nineboxes.net/2009/10/an-applescript-function-to-zero-pad-integers/
*)
on zero_pad(value, string_length)
set string_zeroes to ""
set digits_to_pad to string_length - (length of (value as string))
if digits_to_pad > 0 then
repeat digits_to_pad times
set string_zeroes to string_zeroes & "0" as string
@Glutexo
Glutexo / format-exponential.php
Created September 2, 2016 14:15
Converts an exponential (scientific) number notation to a decimal one using neither GMP nor BCMath module.
<?php
/**
* Converts an exponential (scientific) number notation to a decimal one.
* Uses neither GMP nor BCMath modules.
*
* @param float|int|string $value
* @return string
*/
function formatExponential($value) {
// Both upper-case “E” and lower-case “e” would work.
@Glutexo
Glutexo / getitem.py
Created September 9, 2022 10:24
__getitem__ example
from unicodedata import name
ANIMALS = (
"🐶🐱🐭🐹🐰🦊🐻🐼🐻🐨🐯🦁🐮🐷🐽🐸🐵🙈🙉🙊🐒🐔🐧🐦🐤🐣🐥🦆🦅🦉🦇🐺🐗🐴🦄🐝🪱🐛🦋🐌🐞🐜🪰🪲🪳🦟🦗🕷🕸🦂🐢🐍🦎🦖🦕🐙🦑🦐🦞🦀🐡🐠🐟🐬🐳🐋🦈🦭🐊"
"🐅🐆🦓🦍🦧🦣🐘🦛🦏🐪🐫🦒🦘🦬🐃🐂🐄🐎🐖🐏🐑🦙🐐🦌🐕🐩🦮🐈🪶🐓🦃🦤🦚🦜🦢🦩🕊🐇🦝🦨🦡🦫🦦🦥🐁🐀🐿🦔🐾🐉🐲"
)
class Emoticons:
@Glutexo
Glutexo / rounding.py
Created August 22, 2022 10:01
Rounding in Python
ANIMALS = {
"🐇": "🐰",
"🐁": "🐭",
"🐈": "🐱",
"🐕": "🐶",
"🐅": "🐯",
"🐄": "🐮",
"🐖": "🐷",
"🐒": "🐵",
"🐥": "🐤",
@Glutexo
Glutexo / combinations.exs
Created June 13, 2022 13:21
Recursive combinations with subsets
defmodule Combination do
def combine([]) do
[]
end
def combine([head | tail]) do
tail_combinations = combine(tail)
merged_combinations = Enum.map(
[[]] ++ tail_combinations,
fn c -> c ++ [head] end
@Glutexo
Glutexo / Pokemon.csv
Last active March 21, 2022 16:34
Hra na myšlenou potvoru
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Stáhněte si z https://raw.githubusercontent.com/frenzymadness/Data_analysis_workshop/master/data/Pokemon.csv.
@Glutexo
Glutexo / get_file_from_insights_archive.py
Last active March 21, 2022 16:33
Get a file from an Insights archive
from collections import namedtuple
from contextlib import contextmanager
from functools import partial
from io import BytesIO
from io import StringIO
from os.path import join
from re import escape
from re import fullmatch
from shlex import quote
from tarfile import open as tar_open
@Glutexo
Glutexo / get_core_version_from_insights_client_rpm.py
Last active February 4, 2022 20:51
Get Insights Core version from Insights Client RPM
from contextlib import contextmanager
from os.path import join
from rpmfile import open as rpm_open
from sys import argv
from zipfile import ZipFile
EGG_PATH = join(".", "etc", "insights-client", "rpm.egg")
VERSION_PATH = join("insights", "VERSION")
@Glutexo
Glutexo / .xonshrc
Last active January 21, 2022 13:32
My .xonshrc, to make my life better
# Prevent warning caused by upgrade to Python 3.10.
# See https://github.com/xonsh/xonsh//issues/4409.
import warnings
warnings.filterwarnings(
'ignore',
message='There is no current event loop',
category=DeprecationWarning,
module='prompt_toolkit',
)
@Glutexo
Glutexo / magic_cell.py
Last active November 30, 2021 20:41
A cell object that doesn’t require knowledge of any names
_NOTHING = object()
DELETE = object()
class Cell:
def __init__(self, value=_NOTHING):
if value is not _NOTHING:
self.value = value
def __call__(self, value=_NOTHING):