Skip to content

Instantly share code, notes, and snippets.

View vladris's full-sized avatar
🤠

Vlad Riscutia vladris

🤠
View GitHub Profile
@vladris
vladris / scribe.py
Created December 31, 2014 03:39
Tumblr migration script to move content from a blog to another
import pytumblr
import yaml
import os
import urllib
# stolen from interactive_console.py, because I'm too lazy to oauth
# you'll need to register an app with Tumblr and use interactive_console.py for initial oauth
def create_client():
yaml_path = os.path.expanduser('~') + '/.tumblr'
@vladris
vladris / snow.scss
Created April 3, 2016 03:08
TV snow effect
@function random-gray(){
$col:random(5);
@return rgb($col * 51, $col * 51, $col * 51);
}
@function grid-dots(){
$sh:();
@for $j from 1 through 20 {
@for $i from 1 through 20 {
$sh: $sh, (($i*10px)-(10px)) (($j*10px)-(10px)) 0 random-gray();
@vladris
vladris / curry.cpp
Created October 14, 2016 06:02
Simple curry recipe
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
vladris / 24.py
Last active August 5, 2017 20:01
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:
continue
for ops in product("+-*/", repeat=3):
for exp in ["(...).(...)", "((...)..)..", "(..(...)).."]:
@vladris
vladris / XElementDynamicDeserializer.cs
Created December 3, 2017 16:59
Extension method for XElement to deserialize into a dynamic object
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
vladris / bridge.py
Last active January 6, 2018 16:29
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]
else:
@vladris
vladris / kami.py
Created April 15, 2018 16:09
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
vladris / GenericOverloading.java
Last active September 16, 2018 14:46
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
vladris / peano.h
Created August 16, 2018 01:43
Peano arithmetic in C++ type system
#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
vladris / bf.cpp
Last active June 12, 2019 10:36
Tiny Brainfuck interpreter
#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) {