Skip to content

Instantly share code, notes, and snippets.

View fluency03's full-sized avatar

Chang Liu fluency03

  • London
View GitHub Profile
@fluency03
fluency03 / encryption.js
Created November 18, 2018 01:24 — forked from vlucas/encryption.ts
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bytes (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', new Buffer(ENCRYPTION_KEY), iv);
@fluency03
fluency03 / Eyeballing-This.md
Created November 4, 2018 16:00 — forked from zcaceres/Eyeballing-This.md
Understanding Binding and 'this' in Javascript

How to Eyeball Your ‘This’ Context in Javascript

The early programmer struggles with the Javascript keyword this. But understanding your this context is easier than it seems.

This is all about where a function is invoked. Often, early programmers worry about where the function was declared. Perhaps the function was declared in a specific file or a particular object. Surely this changes it's this!

Nope.

To understand this, we need to see where it is invoked. Nothing else matters, with one exception which we'll cover in a moment.

@fluency03
fluency03 / Mail.scala
Created August 27, 2018 12:44 — forked from mariussoutier/Mail.scala
Sending mails fluently in Scala
package object mail {
implicit def stringToSeq(single: String): Seq[String] = Seq(single)
implicit def liftToOption[T](t: T): Option[T] = Some(t)
sealed abstract class MailType
case object Plain extends MailType
case object Rich extends MailType
case object MultiPart extends MailType
@fluency03
fluency03 / build.sbt
Created October 28, 2017 13:02 — forked from paulp/build.sbt
/** Your task is to reason your way to which compiler
* options which will be passed for each of
* 1) sbt root/compile
* 2) sbt p1/compile
*/
scalacOptions := Seq("-DSBT")
scalacOptions in ThisBuild += "-D0"
scalacOptions in Global += "-D1"
@fluency03
fluency03 / KafkaProducerIT.java
Created September 25, 2017 07:56 — forked from asmaier/KafkaProducerIT.java
Simple java junit test of an apache kafka producer (works with Kafka 0.10.0.0) (see also https://github.com/asmaier/mini-kafka)
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Properties;
import org.I0Itec.zkclient.ZkClient;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
@fluency03
fluency03 / KafkaMostBasicTest
Created September 25, 2017 07:45 — forked from benstopford/KafkaMostBasicTest
Kafka Testing at its Most Simple
package com.confluent.benstopford;
import kafka.consumer.*;
import kafka.javaapi.consumer.ConsumerConnector;
import kafka.message.MessageAndMetadata;
import kafka.serializer.StringDecoder;
import kafka.server.KafkaConfig;
import kafka.server.KafkaServerStartable;
import org.apache.curator.test.TestingServer;
import org.apache.kafka.clients.producer.KafkaProducer;
@fluency03
fluency03 / elasticsearch-cheatsheet.txt
Created September 6, 2017 12:52 — forked from stephen-puiszis/elasticsearch-cheatsheet.txt
Elasticsearch Cheatsheet - An Overview of Commonly Used Elasticsearch API Endpoints and What They Do
# Elasticsearch Cheatsheet - an overview of commonly used Elasticsearch API commands
# cat paths
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/indices
/_cat/indices/{index}

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a
/**
* $java Test
* 1 == 1: true
* 100 == 100: true
* 127 == 127: true
* new 127 == new 127: false
* 128 == 128: false
* 1000 == 1000: false
*/
/**
* http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.13.1
*/
import java.util.ArrayList;
import java.util.List;
public class Foo {