Skip to content

Instantly share code, notes, and snippets.

View mashingan's full-sized avatar

mashingan

View GitHub Profile
package main
import "fmt"
func main() {
res := summedsquare(getInts(), 0)
if !(res <= 0) {
fmt.Println(res)
}
main()
function makecola(name, calories, color, sold) {
name = name || "Water";
calories = calories || 0;
color = color || "clear";
sold = sold || 0;
return {
name: name,
calories: calories,
color: color,
sold: sold
/*
* The call in console:
* $ node digitcombinatorial.js [maxnumber] [digitpattern]
*
* If maxnumber and digitpattern is not supplied in command line, it will
* fallback to the default 10000 and 14 respectively
*/
// Initial parameter definition. Since it is parameter, it's expected won't
// be changed during runtime.
@mashingan
mashingan / example.js
Created January 12, 2017 17:35
An attempt to implement cmd parser like commander.
var mycommander = require('./mycommander');
console.log(mycommander);
console.log(process.argv.slice(2));
mycommander
.option('-f, --foo i', 'Integer value for foo', parseInt, 0)
.option('-b, --bar j', 'Integer value for bar', parseInt, 0)
.option('-z, --baz', 'Boolean argument baz')
.parse(process.argv.slice(2));
input {
width: 100%;
display: block;
}
## The implementation of Sleeping Barber Problem
## https://en.wikipedia.org/wiki/Sleeping_barber_problem
## The `seatAvailable` is guarded with `queue` Lock while the barber
## explicitly acquired and released
## Using pointer math as written in this post
## https://forum.nim-lang.org/t/1188#7366
## compile and run: $ nim c -r --threads:on --threadAnalysis:off barbershop.nim
from os import sleep
from random import random, randomize
@mashingan
mashingan / wshscript-rename.js
Last active August 12, 2017 21:05
Rename files with WSH script
// run it with
// > wscript rename.js
// in the folder where the script resides
//
// or double-click it
var script = WScript.CreateObject("WScript.Shell");
var fso = WScript.CreateObject("Scripting.FileSystemObject");
for (var i = 28; i < 100; i++) {
var file = fso.GetFile('pg' + i + '.png');
@mashingan
mashingan / nim.cfg
Created August 21, 2017 10:49
Nim config
# Configuration file for the Nim Compiler.
# (c) 2017 Andreas Rumpf
# Feel free to edit the default values as you need.
# You may set environment variables with
# @putenv "key" "val"
# Environment variables can be accessed like so:
# gcc.path %= "$CC_PATH"
@mashingan
mashingan / matchmacro.nim
Created September 11, 2017 07:17
defining match syntax using Nim macro
import macros
macro match(head, body: untyped): untyped =
result = newNimNode nnkStmtList
var casenode = newNimNode nnkCaseStmt
casenode.add head
for node in body:
node.expectKind nnkInfix
@mashingan
mashingan / monitorfs.nim
Last active January 14, 2021 17:59
Monitor folder and files using in Windows
import winim
proc quit(value: DWORD) =
quit value.int
proc refreshDirectory(handle: var HANDLE) =
handle = FindFirstChangeNotification(".", false,
FILE_NOTIFY_CHANGE_FILE_NAME)
if handle == INVALID_HANDLE_VALUE:
quit GetLastError()