Skip to content

Instantly share code, notes, and snippets.

@Cosmologist
Cosmologist / windows-schedule-unschedule-task-example.ps1
Created December 3, 2024 21:02
PowerShell: Schedule and unschedule task example (Windows cron)
$TASKNAME = "my-python-task"
$PYTHON = Resolve-Path -Path ".\venv\Scripts\python.exe"
$MAIN = Resolve-Path -Path ".\main.py"
$WORKINGDIR = Resolve-Path -Path ".\"
# Schedule
$Action = New-ScheduledTaskAction -Execute $PYTHON -Argument $MAIN -WorkingDirectory $WORKINGDIR
$Trigger = New-ScheduledTaskTrigger -Daily -At 3am
$Settings = New-ScheduledTaskSettingsSet
@Cosmologist
Cosmologist / js-open-binary-pdf-in-browser.js
Created November 26, 2024 19:23
JavaScript: How to display binary data like pdf (ie from XmlHttpRequest response) in the browser
// This required xhr.responseType="blob"
window.open(URL.createObjectURL(new Blob([xhr.response], {type: xhr.getResponseHeader('content-type')})));
@Cosmologist
Cosmologist / skype-bot-example.php
Created August 5, 2024 13:18
Simple Skype-bot to post messages to the Skype chat
<?php
/**
* Simple Skype-bot to post messages to the Skype chat
*
* <code>
* composer require "botman/botman" "botman/driver-botframework"
* </code>
*
* https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-quickstart?view=azure-bot-service-4.0
#!/bin/bash
echo "Show running mode (UEFI or BIOS) of your system."
echo "@see https://askubuntu.com/a/947856"
echo ""
mode=$(test -d /sys/firmware/efi && echo UEFI || echo BIOS)
echo "System runnging in mode: $mode"
#!/bin/bash
echo "List USB devices with associated device file (/dev/*)."
echo "@see lsusb"
echo ""
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
<?php
/**
* Add the specified HTTP header to the prepared request
*/
function addHeader(Symfony\Component\BrowserKit\Client $client, string $name, $value)
{
$client->setServerParameter('http-' . $name, $value);
}
@Cosmologist
Cosmologist / Brother-Keenetic-CUPS-Cloud.md
Last active December 14, 2018 17:05
Нюансы организации беспроводного доступа к принтеру Brother DCP-7060D подключенного к роутеру Zyhel Keenetic Giga 2 с прошивкой OpenWrt.

CUPS

  • Делайте cupsd -t если что-то не работает - cupsd проанализирует конфигурационный файл и может выдать ошибки, которые потом тяжело будет отловить
  • При попытке печати тестовой страницы выдавалось No such file or directory и ничего не происходило, подробностей больше не было - помог strace - в поставке cups не было ресурса с баннером (тестовая страница) - на него он и ругался.

Драйвера

Brother распространяет драйвера для Linux в виде .deb, .rpm и .ppd (но не для всех принтеров) - 7060D как раз без .ppd. Ставим драйвера локально - у нас появится файлик DCP7060D.ppd - копируем его на роутер в /opt/etc/init.d/cups/ppd, принтер заведенный в CUPS должен называться также - DCP7060D.

int Distance = 0; // Record the number of steps we've taken
// the setup function runs once when you press reset or power the board
void setup() {
// Enable control signal pin
pinMode(11, OUTPUT);
// Dir pin
pinMode(12, OUTPUT);
import quantize
image.open('test.png')
# Quantize image with 8 colors (3-bit)
image = quantize.quantize(image, quantize.PALETTE_8_COLORS)e
image.save('test_quantize.png')
@Cosmologist
Cosmologist / scale.py
Created January 31, 2014 12:57
Convert image to black and white colors - http://pickbox.ru/edit/309
def blackwhitescale(im):
"""
Convert image to black and white colors
Each pixel to be either fully black (0, 0, 0) or fully white (255, 255, 255)
"""
# Convert to grayscale
gray = im.convert('L')
# Scale to white or black (whichever is closest).