Skip to content

Instantly share code, notes, and snippets.

View vlastachu's full-sized avatar

Vlad Chuprin vlastachu

View GitHub Profile
infix operator .? : NilCoalescingPrecedence
func .?<ARG, RES> (fn: (ARG) -> RES, arg: ARG?) -> RES? {
if let arg = arg {
return fn(arg)
}
return nil
}
func .?<ARG0, ARG1, RES> (fn: (ARG0, ARG1) -> RES, arg: (ARG0?, ARG1?)) -> RES? {
@vlastachu
vlastachu / type_operators.swift
Created September 22, 2016 11:26
can't do anything with this
enum Either<A,B> {
case left(A)
case right(B)
}
func |<A,B>(left: A.Type, right: B.Type) -> Either<A, B>.Type {
return Either<A, B>.self
}
# -*- coding: utf-8 -*-
import json
from subprocess import *
from collections import Counter
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from scipy.interpolate import splev, splrep, InterpolatedUnivariateSpline
import datetime
import time
/*
Copyright 2005-2016 Intel Corporation. All Rights Reserved.
This file is part of Threading Building Blocks. Threading Building Blocks is free software;
you can redistribute it and/or modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation. Threading Building Blocks is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details. You should have received a copy of
the GNU General Public License along with Threading Building Blocks; if not, write to the
//...
// change instance property setter to custom at runtime
let type = self.view.superview!.superview!.superview!.dynamicType
if String.fromCString(class_getName(type)) != "runtimeUIView" {
let newtype = objc_allocateClassPair(type, "runtimeUIView", 0)
let imp = class_getMethodImplementation(ViewController.self, #selector(ViewController.fakeFrameSetter(_:)))
let types = method_getTypeEncoding(class_getInstanceMethod(ViewController.self, #selector(ViewController.fakeFrameSetter(_:))))
class_addMethod(newtype, Selector("setFrame:"), imp, types)
object_setClass(self.view.superview!.superview!.superview!, newtype)
}
@vlastachu
vlastachu / zipWithIterNum.hs
Created March 8, 2016 18:43
version of zipWith with number of iteration
zipWithIterNum :: (Integer -> a -> b -> c) -> [a] -> [b] -> [c]
zipWithIterNum fun l r = zipWithIterNum' 0 l r
where n = length l
zipWithIterNum' _ [] _ = []
zipWithIterNum' _ _ [] = []
zipWithIterNum' i (x:xs) (y:ys) = (fun i x y):(zipWithIterNum' (i + 1) xs ys )
module Main (main) where
import Control.Concurrent (forkIO, threadDelay)
import Control.Concurrent.Chan (Chan, newChan, writeChan, readChan)
import Control.Monad (forM_, replicateM)
baseDelay = 2000
writerDelay = 1 * baseDelay
readerDelay = 2 * baseDelay
package com.company;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
// http://ideone.com/ZmrJtE
#include <iostream>
#include <functional>
using namespace std;
using namespace std::placeholders;
template <typename A, typename B, typename C>
function<C(B)> operator^(A a, function<C(A,B)> fun){
// from https://news.ycombinator.com/item?id=8024116
function checkType(f) {
return function(a) {
var type = f.toString().match(/\/\/(.*)\n/)[1].trim();
if(type !== typeof(a)) throw new Error('Invalid type');
return f(a);
}
}