Skip to content

Instantly share code, notes, and snippets.

View vlastachu's full-sized avatar

Vlad Chuprin vlastachu

View GitHub Profile
@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);
@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 (+)
/*
* BakerMemoryManager.cpp
*
* Implementation of BakerMemoryManager class
*
* LLST (LLVM Smalltalk or Low Level Smalltalk) version 0.2
*
* LLST is
* Copyright (C) 2012-2013 by Dmitry Kashitsyn <korvin@deeptown.org>
* Copyright (C) 2012-2013 by Roman Proskuryakov <humbug@deeptown.org>
#lang racket
(define operators (hash '+ 5 '- 5 '* 10 '/ 10))
(define (priority operator)
(hash-ref operators operator 0))
(define (operator? operator)
(hash-has-key? operators operator))
module Main where
import Text.ParserCombinators.Parsec
import Control.Applicative ((<*>), (*>), (<*), (<$>), pure)
import Data.Functor
import Data.List
data CompilerState = CompilerState { commands :: [VMCommand],
errors :: [String],
variables :: [(String, Int)] } --Map
deriving (Eq, Show)
// 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);
}
}
// 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){
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;
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 / 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 )