Skip to content

Instantly share code, notes, and snippets.

View v6ak's full-sized avatar

Vít Šesták v6ak

View GitHub Profile
@v6ak
v6ak / run-once-gui
Last active August 29, 2015 14:15
Starts a GUI application if not running. If it is running, it switches to it. It is unlikely to work well with multiwindow applications without modification because it focuses all of application's windows. Does not work well with "minimize to tray", because it can't find the app's window.
#!/bin/bash
set -u
set -e
set -o pipefail
# Settings
NAME=GQueues
COMMAND=firefox-gqueues
#!/bin/bash
# Intended for installing the corresponding VirtualBox Extension Pack with secure verification. (A local network adversary can't forge the installed package.)
# This version uses a temporary directory.
#
# It is written to be as fail-safe and fail-secure as possible, but no warranty is provided.
#
# safety settings
set -u # Not strictly needed, but it is safer
set -e # NEEDED for safety and security!

Tak ukážu příklad v jazyce Scala. Nedávno jsem psal nějaké zpracování akordama označkovaného textu a konverzi do PDF. Controller by v imperativní verzi (tj. s callbacky) mohl vypadat zhruba takto:

def processChordbook(songText: String) {
	convertToPdf(songText).onSuccess{ pdfData =>
		setHeader("Content-type"->"application/pdf")
		out.write(pdfData)
		out.close()
	}
}
@v6ak
v6ak / sum.scala
Last active August 29, 2015 14:20
scala> import scala.concurrent._
import scala.concurrent._
scala> // Nadefinujeme funkci plus. Ta chce kromě hodnot ke sčítání také ExecutionContext, který určuje,
//kde se to vykoná.
scala> def plus(x: Int, y: Int)(implicit ec: ExecutionContext) = Future{x+y}
plus: (x: Int, y: Int)(implicit ec: scala.concurrent.ExecutionContext)scala.concurrent.Future[Int]
scala> // Podobně nadefinujeme i sum. Bude pracovat se spojovými seznamy. Bacha při kopírování na
My main partition:
% grep 99999999 /mnt/q/var/log/boot.log
Starting Cryptography Setup for luks-99999999-8888-7777-6666-555555555555...
[ OK ] Found device /dev/mapper/luks-99999999-8888-7777-6666-555555555555.
[ OK ] Started Cryptography Setup for luks-99999999-8888-7777-6666-555555555555.
Expecting device dev-disk-by\x2duuid-99999999\x2d8888\x2d7777\x2d6666\x2d555555555555.device...
Expecting device dev-mapper-luks\x2d99999999\x2d8888\x2d7777\x2d6666\x2d555555555555.device...
[ OK ] Found device /dev/mapper/luks-99999999-8888-7777-6666-555555555555.
………
# I pressed Ctrl+Alt+Delete
<?php
function lacyConnection() {
$conn = null;
return function() use (&$conn) {
if ($conn!==null) {
return $conn;
}else{
return connect(…);
}
}
<?php
function lacyConnection() {
$conn = null;
return function() use (&$conn) {
if ($conn===null) {
$conn = connect(…);
}
return $conn;
}
};
<?php
function lacyConnection() {
$conn = null;
return function() use (&$conn) {
if ($conn!==null) {
return $conn;
}else{
$comm = connect(…);
return $comm;
}
$ yum --installroot /var/lib/qubes/dom0-updates --config=/etc/yum.conf check-update -v
Loading "langpacks" plugin
Loading "post-transaction-actions" plugin
Loading "yum-qubes-hooks" plugin
Adding en_US to language list
Config time: 0.011
Yum version: 3.4.3
rpmdb time: 0.000
Building updates object
Setting up Package Sacks
#!/bin/bash
old=""
while true; do
new="$(xdotool getwindowfocus)"
if [ "$old" != "$new" ]; then
echo a
# Tried both windowfocus and windowactivate
xdotool \
search --onlyvisible --class '^Plasma$' \
windowfocus --sync \