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
@vlastachu
vlastachu / sample.hs
Created August 4, 2013 16:22
operator to change function and argument order
-- such functionality already exist in Control.Lens in '&' operator
-- '|>' alreade used in Data.Sequence
module Main where
(|>) :: a -> (a -> b) -> b
(|>) a fun = fun a
infixl 1 |>
main = print $ [1..10] |> map (*2) |> filter (>5) |> foldr1 (+)
-- have idea to improve that function: print $ [1..10] |> map (*2) |> filter (>5) |> foldr1 (+)
@vlastachu
vlastachu / main.cpp
Created May 18, 2013 20:52
simulate mouse action on winapi
#include <Windows.h>
#include <WinUser.h>
#include <iostream>
using namespace std;
int main(){
//0..65535,0..65535
int x =30000, y = 3000;
mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
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;