Skip to content

Instantly share code, notes, and snippets.

@jackliusr
jackliusr / GeoIP Block NGINX Ubuntu 20.04.md
Created September 16, 2022 03:23 — forked from dunderrrrrr/GeoIP Block NGINX Ubuntu 20.04.md
Allow or block GeoIP in Nginx on Ubuntu 20.04

GeoIP Block NGINX Ubuntu 20.04

Block or filter IPs based on location in Nginx (tested on 1.18.0) on Ubuntu 20.04.

Install Nginx modules

To make use of the geographical filtering, we must first install the Nginx GeoIP module as well as the GeoIP database containing the mappings between visitors’ IP addresses and their respective countries. To do so, let’s execute:

$ sudo apt install libnginx-mod-http-geoip geoip-database
{
"$schema": "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json",
"awards": [ ],
"basics": {
"email": "jack.liu.s.r@gmail.com",
"image": "",
"label": "Solutions Architect at Bidot Technology",
"location": {
"address": "Yishun,Singapore",
"countryCode": "SG"
@jackliusr
jackliusr / vega-lite-realtime.json
Created January 19, 2021 13:09
vega-lite to visualize real-time data from api.data.gov.sg
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"width": 500,
"height": 300,
"data": {
"url": "https://api.data.gov.sg/v1/environment/2-hour-weather-forecast",
"format": { "type": "json","property": "area_metadata"}
},
"projection": {
"type": "equalEarth"
@jackliusr
jackliusr / ckan-vega-lite-sample.json
Created January 19, 2021 12:45
vega-lite visualize ckan data
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {
"url": "https://data.gov.sg/api/action/datastore_search?resource_id=4ad866a7-c43a-4645-87fd-fc961c9de78a",
"format": { "type": "json","property": "result.records"}
},
"mark": "line",
"encoding": {
"x": {"field": "year", "type": "nominal"},
"y": {"field": "enrolment", "type": "quantitative"}
@jackliusr
jackliusr / keybase.md
Created October 22, 2020 08:16
keybase.md

Keybase proof

I hereby claim:

  • I am jackliusr on github.
  • I am jackliusr (https://keybase.io/jackliusr) on keybase.
  • I have a public key ASAclF7K6ROgP0Ubzeq8Wa5_UqzUP9FE75PCKzc7xvDjYAo

To claim this, I am signing this object:

@jackliusr
jackliusr / Sherlock and Queries.scala
Created August 11, 2014 15:41
hackerrank Sherlock and Queries in scala
object Solution {
def main(args: Array[String]) = {
val lines = io.Source.stdin.getLines.toList
val nums = lines.map( l => l.split("\\s+").map(s => s.toLong))
var a = nums(1).toArray
val b = nums(2).toArray
val c = nums(3).toArray
val n = (nums(0)(0) -1).intValue
val m = (nums(0)(1) -1).intValue
val mod = scala.math.pow(10,9).toInt + 7
@jackliusr
jackliusr / Angry Children.scala
Last active August 29, 2015 14:05
Hackerran angry children in scala
object Solution{
def main(args: Array[String]) ={
val lines = io.Source.stdin.getLines.drop(1).toList
val k = lines(0).toInt
val kNumsSets = lines.drop(1).map( l => BigInt(l)).sorted.toArray
var unfairness = kNumsSets.last
for(i <- 0 to kNumsSets.size -k -1){
val diff= kNumsSets(i + k-1 ) - kNumsSets(i)
if( diff < unfairness) unfairness = diff
}
@jackliusr
jackliusr / Is Fibo.scala
Created August 7, 2014 15:07
Hackerrank Is Fibo in scala
import scala.math.BigInt
object Solution {
def main(args: Array[String]) = {
def fibFrom(a: BigInt, b: BigInt): Stream[BigInt] = a #:: fibFrom(b, a + b)
val lines = io.Source.stdin.getLines.drop(1).toList
val nums:List[BigInt] = lines.map( l => BigInt(l))
def isFib(n: BigInt):String = {
val fs = fibFrom(0,1).takeWhile(f => f <= n).toList
if (fs.last < n ) "IsNotFibo" else "IsFibo"
}
@jackliusr
jackliusr / Sherlock and GCD.scala
Created August 6, 2014 14:48
Sherlock and GCD
object Solution {
def main(args: Array[String])={
val lines = io.Source.stdin.getLines.drop(1)
def gcd(a: Int, b: Int) : Int = if(b == 0) a else gcd(b, a % b)
val tcs = lines.grouped(2).map( v => v(1)).map(l=>l.split("\\s+").map( s => s.toInt))
val results = tcs.map(c => c.reduceLeft(gcd))
results.foreach( r => println(if( r > 1) "NO" else "YES" ))
@jackliusr
jackliusr / Sherlock and The Beast.scala
Created August 4, 2014 05:32
Hackerrank Sherlock and The Beast implementation in Scala
import scala.math.BigInt
object Solution {
def main(args: Array[String]) {
val lines = io.Source.stdin.getLines().drop(1).toList
val nums = lines.map(l => l.toInt)
def decentNum(n: Int) : String ={
for( i <- (n to 0 by -1) ) {
if( i % 3 ==0 && (n -i) % 5 ==0 ) return ("5" * i + "3" * (n-i))
}
return "-1";