Skip to content

Instantly share code, notes, and snippets.

View andreyvit's full-sized avatar

Andrey Tarantsov andreyvit

View GitHub Profile

SHELESNAKE

Ресурсы на планете Шелезяка подходят к концу, и роботы были вынуждены перейти на питание упавшими частицами метеоритов. Через несколько дней ожидается большой метеоритный дождь, поэтому вам поручили написать программу для небольшой серии из трех роботов, позволяющую им в сумме собрать максимальное число метеоритных осколков.

Поверхность планеты представляет собой плоский круг, по которому раскидано 100 метеоритных осколков. Как роботы, так и осколки считаются точками. Когда робот подходит к осколку на расстояние 1.0 или ближе, он подбирает осколок, а с неба в произвольное место планеты падает новый (таким образом, количество осколков всегда ровно 100).

Действия роботов разделены на такты. У вас всего есть 5000 тактов, чтобы собрать максимальное количество осколков.

@andreyvit
andreyvit / LoggingPolicy.md
Last active May 24, 2016 14:54
Proposal for a Michigan Logging Policy

Logging Policy

What's this, and why is it needed?

People often pick log levels randomly, making them fairly useless. I've recently seen a very useful definition of log levels, and I liked it very much. So here we go.

Log Levels

  • Notice: notable events that should be aggregated and reviewed by the system administrator or development team regularly. This is a good fit for something that's normal in moderation, but may represent a problem if it starts happening too often.
@andreyvit
andreyvit / raid.h
Created August 10, 2015 06:41
One of the finer pieces of code I have ever written
#ifndef _RAID_H_
#define _RAID_H_
#define RAID_LEVEL 3
#define RAID_WRITE(stat) do {int raidi; for(raidi = 0; raidi < RAID_LEVEL; ++raidi) stat;} while(0)
#define raidwr raid[raidi]
#define raidrd raid[0]
GlobalState raid[RAID_LEVEL];
{
init: function(elevators, floors) {
var DIR_UP = 1, DIR_DOWN = -1, DIR_IDLE = 0;
var FLOOR_NINF = -1, FLOOR_PINF = 1000;
var floorUpRequests = [];{
init: function(elevators, floors) {
var DIR_UP = 1, DIR_DOWN = -1, DIR_IDLE = 0;
var FLOOR_NINF = -1, FLOOR_PINF = 1000;
@andreyvit
andreyvit / wwdc-2014-summaries.md
Last active August 29, 2015 14:06
WWDC 2014 Summaries

A Look Inside Presentation Controllers (228)

TODO.

A Strategy for Great Work (237)

  1. “Know a good idea when you see it”: a demo of KHTML running on a Mac, made in 2 days, helped them pick it for Safari.

  2. “Don't try to solve every problem at once”: was extracting KHTML from KDE, had no idea how it worked, just compiled one file at a time, and stubbed missing functions one at a time.

@andreyvit
andreyvit / ObservationPlayground.swift
Last active August 29, 2015 14:04
Code from “In search of a clean closure-based observation API in Swift” on Apple Dev Forums
import Foundation
func weakify<T: AnyObject>(object: T, block: (T) -> Void) -> () -> Void {
weak var weakObject = object
return {
if let strongObject = weakObject {
block(strongObject)
}
}
}
#import <Cocoa/Cocoa.h>
// NSTextField has alignmentRectInsets = {.left=.right=3, .top=.bottom=0}, so
// when autolayout aligns NSTextField to its container's side margin (e.g. to x=0),
// the actual x position is -3, and the label gets clipped.
//
// ATUnclippedTextField compensates for that by overriding drawRect to extend
// the clipping rect by alignmentRectInsets.
//
<?php
require_once 'pdflib/fpdf.php';
require_once 'pdflib/fpdi.php';
// FPDI extension that preserves hyperlinks when copying PDF pages.
//
// (c) 2012, Andrey Tarantsov <andrey@tarantsov.com>, provided under the MIT license.
//
// Published at: https://gist.github.com/2020422
//
// GorillaScript as of 2013-07-08
macro assert-equals(x, y)
@maybe-cache x, #(set-x, x)
@maybe-cache y, #(set-y, y)
AST
if $set-x != $set-y
throw new Error("assert-equals failed: " & $x & " != " & $y)
macro assert-deep-equals(x, y)
@andreyvit
andreyvit / DualNibViewController.h
Last active December 17, 2015 09:29
An old code fragment demonstrating the use of a separate landscape .nib in a UIViewController (the view hierarchies of the two .nib files must match exactly, and only the frames are adjusted when going into landscape, although you can obviously add more properties to the save/restore code).
#import <Foundation/Foundation.h>
@interface DualNibViewController : UIViewController {
NSDictionary *_viewStates;
}
@end