Skip to content

Instantly share code, notes, and snippets.

View vilicvane's full-sized avatar
🌏

vilicvane vilicvane

🌏
View GitHub Profile
@vilicvane
vilicvane / format-number.js
Last active August 29, 2015 14:12
Format number with leading zeros
// relatively safe
function formatSafely(num, digits) {
return (Array(digits).join('0') + Math.floor(num)).substr(-digits);
}
// or quick
function formatQuickly(num, digits) {
return (Array(digits).join('0') + num).substr(-digits);
}
@vilicvane
vilicvane / lexer.ts
Last active February 19, 2020 09:58
A lexer (behave like Angular expression lexer) written with the help of regular expression.
/**
* A test using regular expression for lexing
* by vilicvane<https://vilic.github.io/>
*
* It turns out to be 50% faster comparing to original Angular lexer before JIT Compilation, but 50% slower then (in Chrome).
* And only 1/3 of the original lexer counting the core code lines.
* Though it's because the regular expressions are doing most of the work.
*
* Note: The regular expression and related enum declaration are managed by https://github.com/vilic/regex-tools/.
*/
@vilicvane
vilicvane / cargo-shell.js
Last active April 13, 2020 22:56
Show rust build errors in Visual Studio Code.
var ChildProcess = require('child_process');
var task = process.argv[2];
var cargo = ChildProcess.exec('cargo ' + task);
cargo.stdout.on('data', function (data) {
process.stdout.write(data);
});
@vilicvane
vilicvane / ip-info.ts
Last active August 29, 2015 14:27
Node.js. Get server IPs (v4) information (WAN/LAN IPs).
/*
Server IP Information Utils
by VILIC VANE <https://github.com/vilic>
MIT License
*/
import * as OS from 'os';
export interface IPInfo {
lanIP: string;
@vilicvane
vilicvane / snake.html
Created September 9, 2015 15:47
Snake game written on Nokia 6120c in 2009
<body></body>
<script>
try{
var w=20, h=20;
var s=10;
var t=2500;
var sl=5;
var lx=1, ly=0;
var ax=1, ay=0;
@vilicvane
vilicvane / settings.json
Last active April 16, 2016 05:26
VS Code settings
{
"window.zoomLevel": -0.5,
"editor.insertSpaces": true,
"editor.folding": false,
"files.autoSave": "afterDelay",
"files.trimTrailingWhitespace": true,
"files.eol": "\n",
@vilicvane
vilicvane / prism.css
Created August 14, 2017 16:14
prism.js for blog
/* http://prismjs.com/download.html?themes=prism-twilight&languages=markup+css+clike+javascript+aspnet+c+csharp+cpp+css-extras+handlebars+java+json+less+typescript */
/**
* prism.js Twilight theme
* Based (more or less) on the Twilight theme originally of Textmate fame.
* @author Remy Bach
*/
code[class*="language-"],
pre[class*="language-"] {
color: white;
background: none;
@vilicvane
vilicvane / track-by.directive.ts
Created September 27, 2017 09:48
Angular: "track by" structural directive for single component/element
import {
Directive,
EmbeddedViewRef,
Input,
OnInit,
TemplateRef,
ViewContainerRef,
} from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
# Save this file as $PROFILE (run `echo $PROFILE` in powershell)
Set-Alias gh Get-Help;
Set-Alias cd Push-Location -Option AllScope;
Set-Alias cdb Pop-Location -Option AllScope;
Set-PSReadLineOption -HistoryNoDuplicates;
# For `cdp` (cd project)
$ProjectDirectory = 'C:\Projects';