Skip to content

Instantly share code, notes, and snippets.

Nir Lanka nirlanka

  • Embla Software Innovation
  • Chilaw/Mount-Lavinia/Peradeniya, Sri Lanka
View GitHub Profile
nirlanka / replace-static-page-content.js
Last active May 30, 2020
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.)
View replace-static-page-content.js
(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 / simple-html-tokeniser.js
Last active Apr 24, 2020
Simple tokenizer examples
View simple-html-tokeniser.js
Some text here
<h3>Lorem <a href="./abc/def.html">ipsum</a></h3>
<p>Dolor sit</p>
nirlanka / index.html
Last active Mar 29, 2020
Simple & clean web component inner-element handling
View index.html
<!DOCTYPE html>
<script src="./x-one.js"></script>
nirlanka / index.html
Created Jan 2, 2020
Web component experiment
View index.html
<!DOCTYPE html>
<p>Lorem ipsum</p>
Dolor sit amet
nirlanka /
Last active Dec 23, 2019
Nim on Windows (e.g.)

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


nirlanka /
Last active Dec 9, 2019
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 / TestOne.cs
Last active Dec 9, 2019
A simple set of macros for C# codebases
View TestOne.cs
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 /
Created Dec 5, 2019
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 /
Last active Nov 20, 2019 — 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<account>/<repo>.git
nirlanka / flags.cs
Created Nov 19, 2019
Answers to some simple C# questions I got for an interview
View flags.cs
// 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,
You can’t perform that action at this time.