Skip to content

Instantly share code, notes, and snippets.

View nickytoh's full-sized avatar
🎯
Focusing

Nicky Toh nickytoh

🎯
Focusing
View GitHub Profile
@nickytoh
nickytoh / build.gradle.kts
Created January 7, 2020 04:32
Generate a fat jar by Gradle Kotlin DSL.
// 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 November 2, 2019 18:08
RecyclerView Adapter example.
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 November 2, 2019 16:39
Simple example on how to use Coroutines on Android.
// 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 October 20, 2019 17:21
Simple Kotlin Application with Gradle
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 04:49
JS Hack for Grid Auto Placement in IE Implementation of CSS Grid.
// 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 April 20, 2018 05:09 — forked from nrollr/nginx.conf
NGINX config for SSL with Let's Encrypt certs
# 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 August 29, 2015 14:27
Super minimal ASP.NET 5 MVC WebApi Project Template!
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 July 24, 2015 13:47
Custom light yellow background color for the light theme in Visual Studio Code editor.
/* 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 September 6, 2021 03:11
Request Contact List From iCloud
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}"
}
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) {