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
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
nirlanka / simple-html-tokeniser.js
Last active Apr 24, 2020
Simple tokenizer examples
View simple-html-tokeniser.js
`<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 Mar 29, 2020
Simple & clean web component inner-element handling
View index.html
<!DOCTYPE html>
<html>
<body>
<x-one></x-one>
<script src="./x-one.js"></script>
</body>
</html>
@nirlanka
nirlanka / index.html
Created Jan 2, 2020
Web component experiment
View index.html
<!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 Dec 23, 2019
Nim on Windows (e.g.)
View README.md

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

nim-eg

@nirlanka
nirlanka / simple-csharp-parser.py
Last active Dec 9, 2019
A quick & simple high-level parser for C# code (C# code that's standard-formatted)
View simple-csharp-parser.py
lines = '''
using Abc.Def;
namespace Abc.Hijk
{
public class Haha: ILaugh
{
public Haha()
{
// Constructor
@nirlanka
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
nirlanka / csharp-code-replace-eg.py
Created Dec 5, 2019
An example script for replacing code in a C# project
View csharp-code-replace-eg.py
## // 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 Nov 20, 2019 — forked from stephenhardy/git-clearHistory
Steps to clear out the history of a git/github repository
View git-clearHistory.sh
# 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 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.