Skip to content

Instantly share code, notes, and snippets.

View virtualsafety's full-sized avatar

virtualsafety virtualsafety

View GitHub Profile
@virtualsafety
virtualsafety / myip.go
Created July 26, 2017 03:30 — forked from jniltinho/myip.go
Get My IP Golang
package main
/*
URL: https://github.com/mccoyst/myip/blob/master/myip.go
URL: http://changsijay.com/2013/07/28/golang-get-ip-address/
*/
import (
"net"
"os"
@virtualsafety
virtualsafety / check.go
Created July 14, 2017 03:47 — forked from mattes/check.go
Check if file or directory exists in Golang
if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) {
// path/to/whatever does not exist
}
if _, err := os.Stat("/path/to/whatever"); err == nil {
// path/to/whatever exists
}
@virtualsafety
virtualsafety / shell_output.go
Created April 10, 2017 03:39 — forked from hivefans/shell_output.go
get the realtime output for a shell command in golang
package main
import (
"bufio"
"fmt"
"io"
"os"
"os/exec"
"strings"
)
@virtualsafety
virtualsafety / libevent_test.c
Created January 29, 2017 08:49 — forked from mythosil/libevent_test.c
libevent sample (echo server)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <event.h>
#define PORT 1986
#define BACKLOG -1
#define BUFSIZE 256

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@virtualsafety
virtualsafety / Tree.scala
Created July 27, 2016 08:46 — forked from dholbrook/Tree.scala
Scala binary tree
/**
* D Holbrook
*
* Code Club: PO1
*
* (*) Define a binary tree data structure and related fundamental operations.
*
* Use whichever language features are the best fit (this will depend on the language you have selected). The following operations should be supported:
*
* Constructors
@virtualsafety
virtualsafety / c99.l
Created July 26, 2016 03:00 — forked from codebrainz/c99.l
C99 Lex/Flex & YACC/Bison Grammars
D [0-9]
L [a-zA-Z_]
H [a-fA-F0-9]
E ([Ee][+-]?{D}+)
P ([Pp][+-]?{D}+)
FS (f|F|l|L)
IS ((u|U)|(u|U)?(l|L|ll|LL)|(l|L|ll|LL)(u|U))
%{
#include <stdio.h>
@virtualsafety
virtualsafety / Queue_LinkedList.c
Created July 23, 2016 04:05 — forked from mycodeschool/Queue_LinkedList.c
Linked List implementation of Queue.
/*Queue - Linked List implementation*/
#include<stdio.h>
#include<stdlib.h>
struct Node {
int data;
struct Node* next;
};
// Two glboal variables to store address of front and rear nodes.
struct Node* front = NULL;
struct Node* rear = NULL;
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
module RedBlackTree where
data Zero
data Succ n
type One = Succ Zero
data Black
import Data.Maybe (isJust)
data Tree a = Leaf | Node (Tree a) a (Tree a)
replace :: a -> Tree a -> Tree a
replace a Leaf = Node Leaf a Leaf
replace a (Node l _ r) = Node l a r
rotateR :: Tree a -> Tree a
rotateR (Node (Node x a y) b z) = Node x a (Node y b z)