Skip to content

Instantly share code, notes, and snippets.

View hryniuk's full-sized avatar
🗿

Łukasz hryniuk

🗿
View GitHub Profile
@hryniuk
hryniuk / Op.hpp
Last active March 26, 2017 13:35
Reduce
#ifndef OP_HPP
#define OP_HPP
#include <array>
#include <cmath>
#include <functional>
template <typename T1, typename T2, typename T3=void>
using _RefFunTemplate = std::function<T3(T1, T2)>;
@hryniuk
hryniuk / grok_vi.mdown
Created October 26, 2016 15:52 — forked from nifl/grok_vi.mdown
Your problem with Vim is that you don't grok vi.

Answer by Jim Dennis on Stack Overflow question http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118

Your problem with Vim is that you don't grok vi.

You mention cutting with yy and complain that you almost never want to cut whole lines. In fact programmers, editing source code, very often want to work on whole lines, ranges of lines and blocks of code. However, yy is only one of many way to yank text into the anonymous copy buffer (or "register" as it's called in vi).

The "Zen" of vi is that you're speaking a language. The initial y is a verb. The statement yy is a simple statement which is, essentially, an abbreviation for 0 y$:

0 go to the beginning of this line. y yank from here (up to where?)

@hryniuk
hryniuk / asyncio_producer_consumer.py
Created December 10, 2016 10:33
Producer with slow consumer
import aiohttp
import asyncio
async def l(event, q):
while True:
# ok, I'm ready
event.set()
# get value to process
a = await q.get()
# process it
@hryniuk
hryniuk / class_parametrization.cpp
Created December 10, 2016 10:41
Basic class parametrization example
#include <iostream>
template<typename T, typename S>
struct Citizen
{
Citizen(T k, S l) : k_{k}, l_{l} {}
T k_;
S l_;
};
@hryniuk
hryniuk / int_min_overflow.cpp
Created January 27, 2017 17:50
Overflow during negation of minimum of int
#include <iostream>
#include <limits>
int main()
{
int a = std::numeric_limits<int>::min();
std::cout << a << "\n";
std::cout << a * -1 << "\n";
}
@hryniuk
hryniuk / executing-file.md
Created January 31, 2017 12:08 — forked from jvns/executing-file.md
What happens when I run ./hello

things I don't know

I took this list from What CS majors should know.

I think it is fun to list things I don't know so I did it =D. I actually found it to be a cool exercise -- maybe I should do a fun graphics project and learn about Open GL!

i wrote this because, while i think the things on this list are potentially worth knowing, and I actually think it's an awesome list of project ideas as well as good food for thought for people developing CS curricula (many of the things I don't know are great exercises!) -- I thought it was really weird to say that every CS student should know all of them. I have a CS degree and I learned very few of the things I do know inside my degree.

I classify "do know" as anything that I have a reasonable grasp of or at least some basic experience with -- the kind of experience I'd expect a CS student to be able to get. If I say I don't know something, it means either I know pretty much nothing about it (for "gr

@hryniuk
hryniuk / descriptor.py
Created February 8, 2017 14:05
Python descriptor example
class LogCountDescriptor:
def __init__(self, log_count=0):
self.log_count = log_count
def __get__(self, obj, type=None):
print("log from {}".format(obj))
self.log_count += 1
return self.log_count
@hryniuk
hryniuk / c.cpp
Created March 29, 2017 09:51
Constructor glitch
#include <iostream>
struct A
{
A() { std::cout << "default\n"; }
A(std::string a) { std::cout << "string\n"; }
};
int main()
{
@hryniuk
hryniuk / p.py
Created March 29, 2017 09:52
Partial method application
import functools
class B():
def __init__(self, n):
self.n = n
def __call__(self):
print(self.n)
class A():