Skip to content

Instantly share code, notes, and snippets.

View virtualsafety's full-sized avatar

virtualsafety virtualsafety

View GitHub Profile
@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;
@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 / 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

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 / 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
@virtualsafety
virtualsafety / HelloQuasiquotes.scala
Last active April 9, 2017 12:56
下面的例子演示了如何利用Quasiquotes来实现Code Generation:
import scala.reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox
object HelloQuasiquotes {
def main(args: Array[String]): Unit = {
val universe: scala.reflect.runtime.universe.type = scala.reflect.runtime.universe
import universe._
val toolbox = currentMirror.mkToolBox()
@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 / reflect_1.scala
Created April 15, 2017 13:38
查看 Scala 语法树的方法
import scala.reflect.runtime._
import scala.tools.reflect.ToolBox
val cm = universe.runtimeMirror(getClass.getClassLoader)
val tb = cm.mkToolBox()
tb.parse("for(i <- List(1,2,3) ) {println(i)}")
@virtualsafety
virtualsafety / ScalaJson.scala
Last active July 8, 2021 06:27
利用json4s解析json数据
import org.json4s._
import org.json4s.jackson.JsonMethods._
object ScalaJson {
def main(args: Array[String]): Unit = {
implicit val formats = DefaultFormats
case class Model(hello: String, age: Int)
@virtualsafety
virtualsafety / AlertActiveSessionTuple.scala
Created May 4, 2017 01:43
read json from kafka , parse json to case class , and then convert case class to tuple.
package com.test.flink
import java.util.Properties
import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer09
import org.apache.flink.streaming.util.serialization.SimpleStringSchema
import org.apache.flink.streaming.api.windowing.time.Time
import org.json4s._
import org.json4s.jackson.JsonMethods._