Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View nirlanka's full-sized avatar

Nir Lanka nirlanka

  • SGX
  • Singapore
View GitHub Profile
@nirlanka
nirlanka / replace-static-page-content.js
Last active May 30, 2020 14:48
Replace body of current static page with another page (without reload) (Note: In this page, <header> isn't considered to change except the <title>. Also, this will mess up the back button, unless you handle window 'popstate' yourself.)
(function() {
if (fetch && Promise && document.querySelector && history) { // <-- Dependencies. Otherwise normal links will remain.
function loadPage(url) {
fetch(url).then(function (res) {
return res.text();
}).then(function(html) {
var dom = new DOMParser().parseFromString(html, 'text/html');
var title = dom.querySelector('title').innerText;
history.pushState({}, title, url);
document.title = title;
@nirlanka
nirlanka / simple-html-tokeniser.js
Last active April 24, 2020 03:31
Simple tokenizer examples
`<div>
Some text here
<div>
<h3>Lorem <a href="./abc/def.html">ipsum</a></h3>
<p>Dolor sit</p>
<p>amet</p>
</div>`
.split(/([<>\s="\/]{1})/g)
.map(s=>s.trim())
.filter(Boolean)
@nirlanka
nirlanka / index.html
Last active March 29, 2020 08:38
Simple & clean web component inner-element handling
<!DOCTYPE html>
<html>
<body>
<x-one></x-one>
<script src="./x-one.js"></script>
</body>
</html>
@nirlanka
nirlanka / index.html
Created January 2, 2020 08:32
Web component experiment
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<x-one>
<p>Lorem ipsum</p>
Dolor sit amet
</x-one>
@nirlanka
nirlanka / README.md
Last active December 23, 2019 12:49
Nim on Windows (e.g.)

This is just how Nim compilation to C looks like in Windows.

nim-eg

@nirlanka
nirlanka / simple-csharp-parser.py
Last active December 9, 2019 13:42
A quick & simple high-level parser for C# code (C# code that's standard-formatted)
lines = '''
using Abc.Def;
namespace Abc.Hijk
{
public class Haha: ILaugh
{
public Haha()
{
// Constructor
@nirlanka
nirlanka / TestOne.cs
Last active April 10, 2022 21:35
A simple set of macros for C# codebases
using Abc;
public class One
{
public void Foo()
{
// macro: set ClassName // Changes the assigned default or any value in the line below
string className = default;
Console.WriteLine(className + " Foo");
@nirlanka
nirlanka / csharp-code-replace-eg.py
Created December 5, 2019 07:24
An example script for replacing code in a C# project
## // e.g.
## MBOverlay mbOverlay = UIUtil.GetBusyOverlay(AppStrings.LoadRevision);
## --> VML.LoaderViewModel.Add($"DoorSideBar-{AppStrings.LoadRevision}", Models.ActivityType.API, message: AppStrings.LoadRevision, activitySeverity: Models.ActivitySeverity.High);
## mbOverlay.Hide();
## --> VML.LoaderViewModel.Remove($"DoorSideBar-{AppStrings.LoadRevision}");
## // AppStrings.LoadRevision, Properties..., "", messages: List<string>
import os, re
# files = [f for f in os.listdir('.') if os.path.isfile(f)]
@nirlanka
nirlanka / git-clearHistory.sh
Last active November 20, 2019 18:42 — forked from stephenhardy/git-clearHistory
Steps to clear out the history of a git/github repository
# Remove the history from
rm -rf .git
# recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"
# push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<account>/<repo>.git
@nirlanka
nirlanka / flags.cs
Created November 19, 2019 04:14
Answers to some simple C# questions I got for an interview
// Each account on a website has a set of access flags that represent a user's access.
//
// Update and extend the enum so that it contains three new access flags:
//
// [Flags]
// public enum Access
// {
// Delete = 1,
// Publish = 2,
// Submit = 3,