Skip to content

Instantly share code, notes, and snippets.

@uchcode
uchcode / file0.html
Last active June 12, 2018 04:01
Classを使用してHyperappを書いてみた ref: https://qiita.com/tom-u/items/5566fecf51fc30fff007
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script type="text/javascript" src="https://unpkg.com/hyperapp"></script>
<script>
@uchcode
uchcode / nodejs_process_stdin_on_example.js
Created September 2, 2017 04:18
nodejs_process_stdin_on_example
process.stdin.setEncoding('utf8')
process.stdout.setEncoding('utf8')
process.stderr.setEncoding('utf8')
EVENT = {
DEFAULT : Symbol('default'),
ALL : Symbol('all'),
}
EventTable = []
@uchcode
uchcode / nodejs_eventemitter_example.js
Created August 30, 2017 23:24
nodejs eventemitter example
class StdioEmitter {
constructor(encoding='utf8') {
this.EVENT = {
DEFAULT : Symbol(),
ALL : Symbol(),
}
this.encoding = encoding
this.emitter = new (require('events').EventEmitter)()
this._event_all_listener = undefined
this._regexp_listener_dictionary = {}
@uchcode
uchcode / nodejs_stdio_example.js
Last active August 30, 2017 01:47
node.js stdio example
const STDIN = {
DEFAULT : Symbol(),
ALL : Symbol(),
BEFORE_ALL : Symbol(),
AFTER_ALL : Symbol(),
}
class ProcessStdio {
constructor(encoding='utf8') {
this.encoding = encoding
@uchcode
uchcode / electron_ruby_example2.html
Last active August 28, 2017 08:45
electron ruby example2
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>if (window.module) module = window.module;</script>
<script src="http://cdn.opalrb.org/opal/current/opal.js"></script>
<script src="http://cdn.opalrb.org/opal/current/opal-parser.js"></script>
<script src="http://cdn.opalrb.org/opal/0.10.1/external/opal-jquery-0.4.2.js"></script>
<script type="text/javascript">Opal.load('opal-parser')</script>
<script type="text/javascript">
function electron_spawn(cmd,arg) {
@uchcode
uchcode / electron_ruby_example.html
Last active August 28, 2017 08:20
electron ruby example
<script type="text/javascript">
function electron_spawn(cmd,arg) {
let p = require('child_process').spawn(cmd,arg)
p.stdout.ondata=(action,listener)=>{
p.stdout.on('data',(data)=>{
let d = JSON.parse(data.toString())
if (d.action == action) listener(d)
})
}
p.on('exit',(code,signal)=>{
@uchcode
uchcode / md2code-doc.rb.md
Last active August 26, 2017 15:34
マークダウンに書かれたコードを実行する

マークダウンに書かれたコードを実行する

マークダウンはコードを手軽に表現できる書類です。それからコードだけを出力するコマンドを用意するとドキュメントからコードを生成する事が可能です。従来はコードのコメントでドキュメントを生成しますが、その逆を実現してみようというお話です。

コマンドをmd2codeと名付けてRubyで実装してみました。ソースを以下に示します。とても簡単な内容なのでRuby以外の使用環境に適した言語で実装できるかと思います。

md2code

#!/usr/bin/env ruby

@uchcode
uchcode / hypershell_example.html
Last active August 23, 2017 03:42
HyperShell example
<script type="text/javascript">
function electron_child_process_spawn(cmd = '', arg = []) {
let proc = require('child_process').spawn(cmd, arg, {detached:true})
proc.unref()
proc.stderr.on('data', (data) => {
proc.kill()
window.alert(`electron_child_process_spawn error:\n\n ${data}`)
window.close()
})
window.addEventListener('beforeunload', () => { proc.kill() })
@uchcode
uchcode / electron-asar-launcher-Info.plist
Created August 9, 2017 14:58
electron-asar-launcher
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleAllowMixedLocalizations</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
@uchcode
uchcode / electron-asar-launcher.js
Created August 9, 2017 11:29
electron-asar-launcher.js
app = Application.currentApplication()
app.includeStandardAdditions = true
se = Application('System Events')
function sh(script, opt={}) {
return app.doShellScript(script, {
administratorPrivileges: !!opt.withPrompt,
withPrompt: opt.withPrompt || '',
alteringLineEndings: opt.alteringLineEndings || false
}).replace(/\n$/,'')