Skip to content

Instantly share code, notes, and snippets.

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.*;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@cypok
cypok / wtf.py
Created April 21, 2018 17:03
Am I too old for all these dynamic stuff?..s
import gettext
lang = gettext.translation("wtf")
_ = lang.gettext
print(_("Program started")) # prints translated message
def work_hard():
print(_("Working hard")) # raises UnboundLocalError: local variable '_' referenced before assignment
#
@cypok
cypok / excelsior-quiz-at-jbreak.markdown
Last active June 13, 2021 12:39
Excelsior Quiz @ JBreak / 4 марта 2018
@cypok
cypok / Tree.java
Created November 10, 2016 04:58
IDEA inspection is not correct
import java.util.Iterator;
import java.util.NoSuchElementException;
final class Tree<T> {
private final T elem;
private final Tree<T> parent;
private Tree(T elem, Tree<T> parent) {
this.elem = elem;
@cypok
cypok / bst.c
Created October 31, 2016 16:31
Simple BST with no copy & paste
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
typedef enum eChildKind {
LEFT,
RIGHT,
} ChildKind;
@cypok
cypok / merge_pdf_2on1.sh
Created December 9, 2015 17:58
Simple script to place two PDF pages on single page with separator
if [[ -z "$1" ]]; then
echo No input file
exit
fi
input=$1
middle=`mktemp -t pdf_2on1`.pdf
if [[ -z "$2" ]]; then
name="${input%.*}"
@cypok
cypok / watch.bat
Last active August 29, 2015 14:21
Analog of watch (GNU command-line tool) for Windows
@echo OFF
REM watch is a GNU command-line tool that runs the specified command repeatedly
REM and displays the output on stdout so you can watch it change over time.
REM By default, the command is run every two seconds, although this is adjustable with the -n secs argument.
if x%1==x (call :usage %0 %* && exit /b 1)
if x%1==x-n (
if x%2==x (call :usage %0 %* && exit /b 1)
@cypok
cypok / toggle_extension.sh
Last active November 14, 2016 15:48
OS X Automator service that toggles extension showing
for f in "$@"
do
if [ "`GetFileInfo -ae "$f"`" == "0" ]
then
SetFile -a E "$f"
else
SetFile -a e "$f"
fi
done
@cypok
cypok / gist:bb6979fa535f3ab10874
Last active August 29, 2015 14:09
OpenOffice.org Calc macro ConcatenateIf: mix of CountIf and Concatenate
REM Usage example:
REM
REM | A | B |
REM --+-----+-----+
REM 1 | 111 | aaa |
REM 2 | 222 | bbb |
REM 3 | 222 | ccc |
REM 4 | 333 | ddd |
REM 5 | 333 | eee |
// Solution for http://haskell98.blogspot.ru/2014/10/blog-post_10.html
// Results at http://haskell98.blogspot.ru/2014/10/blog-post_20.html
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
typedef unsigned long long int bigint;