Skip to content

Instantly share code, notes, and snippets.

View vedgar's full-sized avatar

Vedran Čačić vedgar

View GitHub Profile
import operator, types
def value(x):
return getattr(x, 'value', x)
class Cell(types.SimpleNamespace):
@property
def value(self):
@vedgar
vedgar / madlibs.py
Created January 6, 2016 15:43
youtu.be/qsMfF0d5L20 in a sane programming language
print("Welcome to the MadLibs game. If you type in words, we'll give you a story.")
name = input("Start by typing in a name: ")
noun1 = input("Give me a noun: ")
adjective1 = input("I need an adjective: ")
adjective2 = input("I really need an alpaca... just kidding, give me another adjective: ")
noun2 = input("Give me another noun: ")
adverb = input("PLEASE! I really want an adverb: ")
noun3 = input("Give me the last noun: ")
import random
@vedgar
vedgar / nonlocal.py
Created January 30, 2016 09:17
Shared context
# First example: using an explicit namespace as a shared context
from types import SimpleNamespace as Context
def f():
shared = Context(x=5)
def g():
Require Import Classical_Prop.
Variable Person : Type.
Variable Jack Anne George : Person.
Variable married : Person -> Prop.
Notation "a ^: b" := (married a /\ ~ married b) (at level 73).
Variable looksAt : Person -> Person -> Prop.
Notation "a ~> b" := (looksAt a b) (at level 72).
Hypothesis cond : Jack ~> Anne /\ Anne ~> George /\ Jack ^: George.
Theorem solution : exists p q : Person, p ~> q /\ p ^: q.
Proof. destruct (classic (married Anne)).
[I]n my wildest dreams, I never imagined I'd have to write _essays_ here on
[ ]CheckiO. Yes, I know: who's talking? Really, I've written many mind-bogg
[l]ing things here already, and I have puzzled many folks reading my soluti
[o]ns. It's only fair that I puzzle myself now. :-So, what to write? You ha
[v]e already seen enough to realize that I consider Python one of the most
[e]xcellent inventions our civilization has ever made, not only in the tier
[ ]of programming languages. It still puzzles you: why one would think so?
[P]uzzling is good, because in this jaded culture, it is one of the rare wa
[y]s ideas can still be learned. Of course, my essay won't magically enligh
[t]en you. But neither will Zen of Python by itself. Those are only small c
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
int main(void){
struct hostent *hostinfo = gethostbyname("time-a.nist.gov");
if(!hostinfo) herror("gethostbyname");
import enum, struct
class Poruka(enum.IntEnum):
LOGIN = 1
USERS = 2
USERLIST = 3
BYE = 4
NEWMESSAGE = 5
CHECKMESSAGES = 6
MESSAGE = 7
@vedgar
vedgar / balance_bots.py
Created December 10, 2016 05:38
You _can_ write readable code and still get into top100 on Advent of code. :-)
import collections
test = '''\
value 5 goes to bot 2
bot 2 gives low to bot 1 and high to bot 0
value 3 goes to bot 1
bot 1 gives low to output 1 and high to bot 0
bot 0 gives low to output 2 and high to output 0
value 2 goes to bot 2
URL: http://martinlaz.github.io/demos/cky.html
Gramatika:
Izraz -> Izraz + Član | Izraz - Član | Član
Član -> Član * Faktor | Faktor
Faktor -> broj | ( Izraz )
Gramatika ChNF:
Izraz -> Izraz PlusClan
PlusClan -> Plus Clan
from math import sin, cos, tau
import collections
class frange(collections.namedtuple('_', 'start stop step')):
def __iter__(self):
t, end, step = super().__iter__()
while t <= end:
yield t
t += step