Skip to content

Instantly share code, notes, and snippets.

View billdozr's full-sized avatar

Alen Ribic billdozr

View GitHub Profile
<div class="navbar-container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<i class="fa fa-bars"></i>
</button>
<a class="navbar-brand" href="/">
...
</a>
</div>
/**Below are 2 implementations of the same function for checking whether a binary tree is sorted. isSortedA was made by myself as an answer to an exercise in FP in Scala. isSortedB was found on github as an answer to the same exercise. I assume isSortedB is better, but can anyone tell me why (other than the fact that I left out @annotation.tailrec).*/
def isSortedA[A](as: Array[A], gt: (A, A) => Boolean): Boolean = {
def go(n: Int): Boolean = {
if (n <= 0) true
else if (!gt(as(n), as(n-1)))false
else go(n-1)
}
go(as.length-1)
}
@billdozr
billdozr / README.md
Created October 12, 2013 17:33 — forked from nikcub/README.md
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Lens
data Arc = Arc
{ _degree :: Int
, _minute :: Int
, _second :: Int } deriving Show
@billdozr
billdozr / ListOutOfLambdas.java
Last active December 16, 2015 04:39
Nice post titled "List Out of Lambda" [1] written by Steve Losh, implemented here in Java 8. Building blocks of lists: 1) Functions (lambdas) 2) `true` and `false` for empty lists .... [1] http://stevelosh.com/blog/2013/03/list-out-of-lambda/
package java8.func.abstraction;
/**
* Nice post titled "List Out of Lambda" [1] written by Steve Losh,
* implemented here in Java 8.
*
* Building blocks of lists:
* * Functions (lambdas)
* * `true` and `false` for empty lists
*
* [1] http://stevelosh.com/blog/2013/03/list-out-of-lambda/
@billdozr
billdozr / LispLikeLang.java
Last active December 16, 2015 00:38
Playing around with some Java 8 features ...
package java8.lisp;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Stack;
import java.util.function.Function;
public class LispLikeLang {
interface LExpression {
@billdozr
billdozr / java8_snippet1.java
Last active December 15, 2015 11:59
Java 8 :: Snippet 1 :: Compute product of even numbers (streams, lambda expressions, type inference, filters, reducers and optional type)
// Compute product of even numbers
OptionalInt r = Streams.intRange(1, 11) // [1..10]
.filter(n -> n % 2 == 0)
.reduce((acc, n) -> acc * n);
out.println(r.isPresent() ? r.getAsInt() : 1);
@billdozr
billdozr / .emacs.el
Last active October 10, 2015 10:57
My .emacs file
;; =============================================================================
;; Emacs Lisp Packages
;; =============================================================================
;(require 'package)
;(add-to-list 'package-archives
; '("marmalade" . "http://marmalade-repo.org/packages/") t)
;(package-initialize)
(require 'package)
(add-to-list 'package-archives
@billdozr
billdozr / distributed-ping.hs
Last active October 8, 2015 18:08
Distributed ping (with boilerplate code, i.e. without Template Haskell)
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
import System.Environment (getArgs, getProgName)
import Control.Monad (forM_, replicateM_)
import Data.Binary (Binary, encode, decode)
import Data.Typeable (Typeable)
import Data.ByteString.Lazy (ByteString)
import Control.Concurrent (threadDelay)
import Data.Rank1Dynamic (toDynamic)
import Control.Distributed.Static
( Static
@billdozr
billdozr / gist:3277051
Created August 6, 2012 17:45
Ping server
import System.Environment (getArgs, getProgName)
import Control.Concurrent (forkIO)
import Network (Socket, PortID(PortNumber), withSocketsDo,
listenOn, accept)
import System.IO (hPutStrLn, hGetLine, hFlush)
import Control.Monad (forever)
main = withSocketsDo $ do
args <- getArgs
prog <- getProgName