Skip to content

Instantly share code, notes, and snippets.


Vlad Riscutia vladris

View GitHub Profile
vladris / prune.cmd
Created Jan 3, 2019
Prune already deleted files from git history
View prune.cmd
git log --diff-filter=D --name-only --pretty="format:" > ..\FILES
for /f "tokens=*" %%a in (..\FILES) do (
git filter-branch --tag-name-filter cat --index-filter "git rm -r --cached --ignore-unmatch %%a" --prune-empty -f -- --all
vladris / bf.cpp
Last active Jun 12, 2019
Tiny Brainfuck interpreter
View bf.cpp
#include <array>
#include <fstream>
#include <iostream>
using namespace std;
const size_t memory_size = 1024;
template <typename It>
It& skip(It&& it, char from, char to) {
vladris / peano.h
Created Aug 16, 2018
Peano arithmetic in C++ type system
View peano.h
#include <type_traits>
// Natural numbers
struct nat { };
// Typed only if T is derived from nat
template <typename T>
using nat_only = std::enable_if_t<std::is_base_of<nat, T>::value>;
// Zero is a natural number
vladris /
Last active Sep 16, 2018
Overloading methods with generic arguments
// Since generics in Java are removed at compile-time, we cannot overload methods
// based on generic types
// Below class does not compile:
// Erasure of method Foo(T1) is the same as another method in type Test<T1,T2>
// Erasure of method Foo(T2) is the same as another method in type Test<T1,T2>
class Generic<T1, T2> {
void Foo(T1 arg) {
vladris /
Created Apr 15, 2018
Python solution for Kami 2 puzzle
class Graph:
def __init__(self, nodes=dict(), edges=[]):
self.nodes = nodes
self.edges = edges
self.colors = len(set(nodes.values()))
def connected(self, node):
for edge in self.edges:
if edge[0] == node:
yield edge[1]
vladris /
Last active Jan 6, 2018
Solution for Adevent of Code 2017/Day 24
components = [tuple(map(int, line.strip().split('/'))) for line in open("input.txt").readlines()]
def best_bridge(end, components):
result = 0
for i, c in enumerate(components):
if end == c[0]:
new_end = c[1]
elif end == c[1]:
new_end = c[0]
vladris / XElementDynamicDeserializer.cs
Created Dec 3, 2017
Extension method for XElement to deserialize into a dynamic object
View XElementDynamicDeserializer.cs
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Xml.Linq;
/// <summary>
/// Provides extension method for XElement to deserialize to a dynamic object
/// The element's attributes will be stored as properties on the dynamic object.
/// The child elements will also be stored as properties on the dynamic object with the
vladris /
Last active Aug 5, 2017
24 solver
from itertools import permutations, product, zip_longest
from sys import argv
args = sum([[1, 11] if arg in "aA" else [int(arg)] for arg in argv[1:5]], [])
for xs in permutations(args, 4):
if sum(n == 1 or n == 11 for n in xs) > len(args) - 4:
for ops in product("+-*/", repeat=3):
for exp in ["(...).(...)", "((...)..)..", "(..(...)).."]:
vladris / curry.cpp
Created Oct 14, 2016
Simple curry recipe
View curry.cpp
template <typename Func, typename Arg>
struct curry_t
template <typename ...Args>
auto operator()(Args&& ...args)
return _func(_arg, std::forward<Args>(args)...);
Func _func;
vladris / snow.scss
Created Apr 3, 2016
TV snow effect
View snow.scss
@function random-gray(){
@return rgb($col * 51, $col * 51, $col * 51);
@function grid-dots(){
@for $j from 1 through 20 {
@for $i from 1 through 20 {
$sh: $sh, (($i*10px)-(10px)) (($j*10px)-(10px)) 0 random-gray();
You can’t perform that action at this time.