Skip to content

Instantly share code, notes, and snippets.

@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 ->, spaces as spaces):

@cypok
cypok / student.sml
Last active December 25, 2015 18:09
Incorrect tabs and spaces usages
(*
---> means tab
. means space
*)
(* Student 1 write like this and assumes ts=4 ... *)
fun get_nth (s: string list, n: int)=
....if n=0
....then ""
....else
@cypok
cypok / truecolor.rb
Last active December 25, 2015 10:39 — forked from NIA/truecolor.rb
#!/usr/bin/env ruby
# Usage example: sml hw1test.sml | truecolor.rb
require 'colorize'
true_pat = /\btrue\b/
false_pat = /\bfalse\b/
true_count = 0
@cypok
cypok / test.cpp
Last active December 23, 2015 20:09
Interesting C++
#include <iostream>
#include <stdexcept>
using namespace std;
class A {
public:
/**
@cypok
cypok / Tree.scala
Last active December 22, 2015 03:18 — forked from vkostyukov/Tree.scala
import scala.annotation.tailrec
object TestRun extends App {
val tree = Leaf.add(10).add(5).add(7)
println(tree.valuesByBreadth mkString ", ")
}
abstract sealed class Tree[+A] {
import Ordered._
@cypok
cypok / gist:5958995
Created July 9, 2013 16:43
Fun extension for cuttable string
scala> implicit class CutString (self: String) {
| def cutTo(sz: Int) = if (self.length > sz) self.substring(0, sz) else self
| }
defined class CutString
scala> "abc".cutTo(5)
res6: String = abc
scala> "abcdef".cutTo(5)
res7: String = abcde
@cypok
cypok / main.c
Created July 2, 2013 11:26
Compile & run C-program from another C-program
#include <stdio.h>
#include <Windows.h>
// Pay attention to "^"
#define MSVC_PATH "C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio^ 10.0\\VC"
#define APP_C "hello.c"
#define APP_EXE "hello.exe"
// This function generates simple C-program.
@cypok
cypok / convexhull.hs
Last active December 18, 2015 14:29
Graham scan algorithm.
-- Algorithm description: http://en.wikipedia.org/wiki/Graham_scan
-- Task from Real World Haskell: http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html#id588205
data Direction = DirLeft | DirRight | DirStraight
deriving(Show)
data Point = Point { pointX :: Double, pointY :: Double }
deriving(Show,Eq)
subPoints a b = Point ((pointX a) - (pointX b)) ((pointY a) - (pointY b))