This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# New article polling script for a pikabu.ru page that notifies via a Telegram | |
# bot or any other BASH command. | |
# | |
# Syntax: | |
# python3 pikabu.py | |
# ./pikabu.py [after `chmod +x pikabu.py`] | |
# | |
# Requirements: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IceDragon on 07-Feb-2018 */ | |
import kotlin.coroutines.experimental.buildSequence | |
fun permutations(items: List<Any?>, qty: Int): Sequence<List<Any?>> = buildSequence { | |
if (items.size < qty || qty == 0) | |
return@buildSequence | |
val availableIndices = Array<Int?>(items.size, { it }) | |
val iterators = Array<Iterator<Int>>(qty, { (0 until availableIndices.size).iterator() }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IceDragon on 06-Feb-2018 */ | |
import kotlin.coroutines.experimental.buildSequence | |
fun product(vararg lists: Iterable<Any?>): Sequence<List<Any?>> = buildSequence { | |
if (lists.isEmpty()) | |
return@buildSequence // no combinations | |
val iterators = Array(lists.size, { i -> lists[i].iterator() }) | |
if (iterators.any { !it.hasNext() }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
def watch_fp(fp, delim: str = "\n"): | |
buf = [] | |
while True: | |
raw_input = fp.read() | |
if raw_input != "": | |
buf.append(raw_input) | |
if delim in raw_input: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####################################################################### | |
# Implements a topological sort algorithm. | |
# | |
# Copyright 2014 True Blade Systems, Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_system_busy(threshold=0.5): | |
""" | |
:param float threshold: relative threshold (load_15min/num_cpus) past which the system is considered busy | |
:return: True if the system is considered busy; False otherwise | |
:rtype: bool | |
""" | |
from psutil import cpu_count | |
from os import getloadavg | |
load_1, load_5, load_15 = getloadavg() | |
return load_15 / cpu_count() >= threshold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
#include <assert.h> | |
/*** Factorial ***************************************************************/ | |
#define FACT_LIMIT 17 | |
bool fact_initialized = false; | |
unsigned long long G_FACTORIAL[FACT_LIMIT]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[loggers] | |
keys=root, other | |
[logger_root] | |
level=DEBUG | |
handlers=hand01 | |
[logger_other] | |
qualname=util.other | |
level=DEBUG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# /etc/ssh/sshrc | |
TELEGRAM=$HOME/bin/telegram | |
HOST=$(hostname) | |
DATE=$(date) | |
MSG="SSH Login: *$USER@$HOST* | |
Conn: *$SSH_CONNECTION* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Based on the guide here: | |
# https://www.forsomedefinition.com/automation/creating-telegram-bot-notifications/ | |
TOKEN="################################" | |
CHAT_ID="12345678" | |
URL="https://api.telegram.org/bot$TOKEN/sendMessage" | |
TIME=10 | |
TEXT="$1" |