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 / ledger_graph.rb
Last active July 1, 2021 01:44
Script to visualize your expenses and assets using Ledger
#!/usr/bin/env ruby
# encoding: utf-8
require 'date'
def bad_usage
puts "Usage: ledger_graph <output.svg> month_expenses <limit> [<year> <month>]"
puts " or: ledger_graph <output.svg> last_assets <months>"
exit
end
@cypok
cypok / excelsior-quiz-at-jbreak.markdown
Last active June 13, 2021 12:39
Excelsior Quiz @ JBreak / 4 марта 2018
@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 / 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 / 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 / issue.md
Last active January 3, 2016 07:49
Speaker Deck: lack of support for cyrillic fonts

The problem was fixed in less than a day after publication of this page.

The problem

Speaker Deck uses nice OpenSans font. However some characters are rendered using other fonts, e.g. cyrillic characters.

So if you mix in description both latin and cyrillic characters it looks bad. Latin characters are rendered using [lite 300 OpenSans

@cypok
cypok / Absents.java
Created January 14, 2014 13:02
Strange methods of Java arrays. Guess what will be printed in run.sh? Explanation here: https://gist.github.com/cypok/f9d09aaa913c94006aab
public class Absents {
public static void main(String args[]) {
try { callClone(null); } catch (Throwable e) { System.out.println(e); }
try { callToString(null); } catch (Throwable e) { System.out.println(e); }
}
static void callClone(Fail[] arr) {
arr.clone();
}
@cypok
cypok / tabs-spaces.md
Last active December 26, 2015 09:49
Post about mixing tabs and spaces

Original post at Coursera's proglang discussion forum is here.

After reviewing code of other students I formulated one very common problem: mixing tabs and spaces.

If student writes his code in editor which inserts tabs as is (as '\t' character) it is OK. However when student starts to add extra formatting with spaces (e.g. align if, then and else) his code becomes a problem. Look at the example with tab width 4 (tabs are shown as -&gt;, spaces as spaces):