Skip to content

Instantly share code, notes, and snippets.

@xianny
xianny / AppScriptCalendarSync.gs
Last active September 3, 2021 19:59
Google Apps Script to sync personal calendar with work calendar
/**
Google Drive > New > Apps Script
Paste below into Code.gs file
On the left sidebar, look for triggers menu to add a time-based trigger.
*/
const ID = "" // FILL IN secondary calendar ID
const EVENT_NAME = "busy (autosync)" // change event name
const DAYS_TO_SYNC = [1,2,3,4,5] // add 6, 7 to monitor weekends too
const DAYS_BUFFER = 14 // how many days in advance to monitor
@xianny
xianny / tictactoe.go
Created March 17, 2017 14:42
Tic Tac Toe in Go with Minimax AI
package main
import (
"errors"
"fmt"
"math"
"strconv"
)
func playerToken(b bool) (c string) {
@xianny
xianny / Board.scala
Created February 28, 2017 21:41
General purpose board for grid-based board games
package com.xianny.gameutils
/*
1 2 3
1 (1,1) (2,1) (3,1)
2 (1,2) (2,2) (3,2)
3 (1,3) (2,3) (3,3)
*/
// object BoardTest {
@xianny
xianny / jekyll-new
Last active February 28, 2017 07:43
jekyll-new-post
#!/bin/bash
# This script creates a new post or draft in jekyll with pre-filled front matter
# ./script some title for your post
# use -d option for draft
FILEDIR="_posts/"
while getopts "d" opt; do
case $opt in
d)
import scala.io.StdIn
object Game {
val cols = Seq("1", "2", "3")
val rows = Seq("A", "B", "C")
val default = "_"
def token(player: Boolean) = if (player) "X" else "O"
/* Small script for edge contraction of graphs. I was reading about
randomised algorithms, which led to Karger's algorithm for finding
min-cut of a graph, which led to reading about graphs and cutsets,
and then wanting to find out how graphs and edge contraction can be
represented in code...
To run, just do `node edge-contraction.js` */
var graph =
[ ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],

Scaladays

Scaladays Keynotes

Scala 2.12 is the new big thing! It has 33 near features, but more importantly it contains optimizations for Java 8 using Java 8 language features such as lambdas and default methods, while still being backwards compatible with Java 6.

Scala 2.13 more focused on improving scala’s built-in libraries, including the collections library. Particularly, it will become more inline with spark collections and more have more robust lazy collection support. There are also plans to separate Scala into a core and platform module.

Neat things happening with Scala:

  • Scala.js
  • Scala native

Poppin' Bottles

You've just been hired at Lighthouse Markets, a reputable (and thoroughly fictional) grocery store chain. One of the primary features of Lighthouse Markets is their recycling program on pop bottles. Here is how the program works:

  • For every two empty bottles, you can get one free (full) bottle of pop
  • For every four bottle caps, you can get one free (full) bottle of pop
  • Each bottle of pop costs $2 to purchase

Given these parameters, write a program so that you can figure out how many total bottles of pop can be redeemed given a customer investment.