Skip to content

Instantly share code, notes, and snippets.

@nexpr
nexpr / hjml.js
Last active January 22, 2017 10:20
HJML: Hyper Javascript Markup Language Convert xml to js
!function(){
var tags = {
// [stmt/exp]
// make function
function(elem){
var body = prv.block(elem)
var name = elem.getAttribute("j:name") || ""
var arguments_name = elem.getAttribute("j:arguments")
var args
if(arguments_name){
@nexpr
nexpr / doIf.js
Created January 23, 2017 16:12
do if
function doIf(cond_fn){
return do_fn =>
(...args) =>
typeof cond_fn === "function" && typeof do_fn === "function"
&& cond_fn(...args)
&& do_fn(...args)
}
var doIfTrue = doIf(e => e)
var doIfFalse = doIf(e => !e)
@nexpr
nexpr / showInherit.js
Created February 4, 2017 09:49
show inherit of prototype
function showInherit(obj){
while(obj = obj.__proto__){
console.log(obj.constructor)
}
}
function showInheritFn(fn){
var obj = fn.prototype
do{
console.log(obj.constructor)
} while(obj = obj.__proto__)
@nexpr
nexpr / asyncnize.js
Created February 5, 2017 08:45
asyncnize
Function.prototype.async = function(pos){
return (...args) =>
new Promise((resolve, reject) => {
var iidx = Object.is(-0, pos) ? args.length : pos
var cb = (...cbarr) => resolve(cbarr)
args.splice(iidx, 0, cb)
this(...args)
})
}
@nexpr
nexpr / lib.js
Created February 5, 2017 14:58
One expression js code. Convert a string like a url in html to a-tag.
function eif(exp, ift, iff){
return exp ? ift : iff
}
function let(...args){
const fn = args.pop()
if(typeof fn !== "function") throw new TypeError("Last argument must be a function.")
return fn.apply(this, args)
}
@nexpr
nexpr / textarea-indent.html
Last active June 18, 2017 11:07
indent supporter for textarea.
<!doctype html>
<textarea id="input"></textarea>
<script>
input.onkeydown = function(eve){
if(eve.keyCode === 13){
eve.preventDefault()
var str = this.value
var ss = this.selectionStart
var se = this.selectionEnd
@nexpr
nexpr / ip2id.js
Created February 13, 2017 14:16
make id from ip
const ip2id = ip =>
ip.split(".")
.map(e => String.fromCharCode(e))
.map(e => btoa(e))
.map(e => e.replace(/=+$/g, ""))
.join("")
@nexpr
nexpr / Window00.xaml
Created May 2, 2017 04:13
wpf: split grid vertical/horizontal
<Window x:Class="wpf_testproj.Window00"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:wpf_testproj"
mc:Ignorable="d"
Title="Window00" Height="600" Width="600"
PreviewKeyDown="Window_PreviewKeyDown">
<Grid x:Name="root_grid">
@nexpr
nexpr / repl.example.txt
Created May 26, 2017 13:51
repl for JScript (windows10 only)
C:\Users\user\Desktop>cscript //E:{1b7cd997-e5ff-4932-a7a6-2a9e636da385} repl.js
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
> if(true){\
> 1\
> }
1
> var a = 10
undefined
@nexpr
nexpr / jsconsole.example.txt
Created May 26, 2017 13:55
repl2 for JScript (windows10 only)
C:\Users\user\Desktop>cscript jsconsole.js //E:{1b7cd997-e5ff-4932-a7a6-2a9e636da385}
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
> var a = 1
> a
1
> const b = 2