Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Nicky Toh nickytoh

🎯
Focusing
View GitHub Profile
@nickytoh
nickytoh / build.gradle.kts
Created Jan 7, 2020
Generate a fat jar by Gradle Kotlin DSL.
View build.gradle.kts
// run gradle jar in the command line to get the jar
plugins {
java
application
kotlin("jvm") version "1.3.60"
}
repositories {
mavenCentral()
}
@nickytoh
nickytoh / SampleAdapter.kt
Created Nov 2, 2019
RecyclerView Adapter example.
View SampleAdapter.kt
class SampleAdapter : RecyclerView.Adapter<SampleAdapter.ViewHolder>() {
private var list: List<Sample> = listOf()
override fun getItemCount(): Int = list.size
override fun onBindViewHolder(holder: SampleAdapter.ViewHolder, position: Int) {
holder.bind(list[position])
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SampleAdapter.ViewHolder {
@nickytoh
nickytoh / MyActivity.kt
Last active Nov 2, 2019
Simple example on how to use Coroutines on Android.
View MyActivity.kt
// Activity::onCreate
val job = Job()
val coroutineScope = CoroutineScope(Dispatchers.IO + job)
coroutineScope.launch {
val json = URL("https://jsonplaceholder.typicode.com/posts?_limit=5").readText()
withContext(Dispatchers.Main) {
findViewById<TextView>(R.id.title).text = json
}
}
@nickytoh
nickytoh / MyLibrary.kt
Created Oct 20, 2019
Simple Kotlin Application with Gradle
View MyLibrary.kt
package app.smth.kotlin
data class Language(val name: String, val hotness: Int)
class MyLibrary {
fun kotlinLanguage() = Language("Kotlin", 10)
companion object {
@JvmStatic
fun main(args: Array<String>) {
@nickytoh
nickytoh / hack.js
Last active May 25, 2018
JS Hack for Grid Auto Placement in IE Implementation of CSS Grid.
View hack.js
// for each element
this.style['-ms-grid-column'] = Math.floor(i % 4) + 1; // 4 is the column number per row
this.style['-ms-grid-row'] = Math.floor(i / 4) + 1; // 4 is the column number per row
@nickytoh
nickytoh / nginx.conf
Created Apr 20, 2018 — forked from nrollr/nginx.conf
NGINX config for SSL with Let's Encrypt certs
View nginx.conf
# Advanced config for NGINX
server_tokens off;
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options nosniff;
# Redirect all HTTP traffic to HTTPS
server {
listen 80;
server_name www.domain.com domain.com;
return 301 https://$host$request_uri;
@nickytoh
nickytoh / Startup.cs
Last active Aug 29, 2015
Super minimal ASP.NET 5 MVC WebApi Project Template!
View Startup.cs
using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection;
namespace WebApi
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
@nickytoh
nickytoh / native.main.css
Created Jul 24, 2015
Custom light yellow background color for the light theme in Visual Studio Code editor.
View native.main.css
/* Code/app-0.5.0/resources/app/client/vs/monaco/ui/workbench/native/native.main.css */
.monaco-editor.vs,
.monaco-editor.vs .zone-widget .monaco-editor {
background-color: #fdf6e4;
}
.monaco-editor,
.monaco-editor-background {
background-color: #fdf6e4;
@nickytoh
nickytoh / iCloud API Demo in Node.js
Last active Aug 8, 2018
Request Contact List From iCloud
View iCloud API Demo in Node.js
var uuid = require('node-uuid'),
https = require('https');
function iCloud(appleId, password) {
this.urls = {
"version" : "https://www.icloud.com/system/version.json",
"validate": "/setup/ws/1/validate?clientBuildNumber={0}&clientId={1}",
"login": "/setup/ws/1/login?clientBuildNumber={0}&clientId={1}"
}
View proxy_with_balance_file.js
var fs = require('fs'),
sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
checkBalanceFile(req, res);
}).listen(8000);
function checkBalanceFile(req, res) {
fs.stat("balance", function(err) {