Skip to content

Instantly share code, notes, and snippets.

@uchcode
uchcode / file0.swift
Last active October 17, 2016 14:06
URLSessionの拡張(URLSession#synchronousDataTask, URLSession#retryDataTask) ref: http://qiita.com/tom-u/items/08aa3ce75dce8579686c
extension URLSession {
/*
* synchronousDataTask
*
* Httpデータを同期的に取得します。スレッドをブロックするので使用に注意してください。
*/
func dataTask(with request:URLRequest) -> (data:Data?, response:URLResponse?, error:Error?) {
let semaphore = DispatchSemaphore(value: 0)
@uchcode
uchcode / core.js
Created September 16, 2016 08:48
JXA shell kit core
// JXA shell kit.
// uchcode. - MIT Licensed
ObjC.import('stdlib');
ObjC.import('unistd');
try {
CurrentApp;
} catch(e) {
CurrentApp = Application.currentApplication();
@uchcode
uchcode / require.js
Created September 16, 2016 08:31
require() for jxa
function require(path) {
if(!path) throw new Error("require: missing argument: path")
function ItemPath(path) {
let p = $(path).stringByStandardizingPath.js
if ( !FileManager.fileExistsAtPath(p) ) {
if ( FileManager.fileExistsAtPath(p+'.js') ) {
return p+'.js'
} else {
return null
}
@uchcode
uchcode / JXA.scpt
Created September 16, 2016 08:21
JXA library
function read(fname, inDirectory) {
var d = inDirectory || '~/Library/Script Libraries'
var p = $(`${d}/${fname}`).stringByStandardizingPath
var u = $.NSUTF8StringEncoding
var e = $()
var c = $.NSString.stringWithContentsOfFileEncodingError(p, u, e).js
if (e.js) {
throw new Error($.NSString.stringWithFormat('%@', e).js)
}
return c
@uchcode
uchcode / currency-converter.js
Created September 16, 2016 07:13
Currency Converter
ObjC.import('Cocoa')
////////////////////////////////////////////////////////////////////////////////
// View
////////////////////////////////////////////////////////////////////////////////
class Window {
constructor(x, y, width, height) {
let f = $.NSMakeRect(x, y, width, height)
let s = $.NSTitledWindowMask | $.NSClosableWindowMask | $.NSMiniaturizableWindowMask
@uchcode
uchcode / jxa-hello-world.js
Created September 5, 2016 10:52
JXA Hello world
ObjC.import('Cocoa')
GreetButton = $.NSButton.alloc.initWithFrame($.NSMakeRect(10, 10, 110, 80))
GreetButton.title = 'Hello!'
GreetButton.bezelStyle = $.NSRegularSquareBezelStyle
GreetButton.sound = $.NSSound.alloc.initWithContentsOfFileByReference('/System/Library/Sounds/Tink.aiff', true)
GoodbyeButton = $.NSButton.alloc.initWithFrame($.NSMakeRect(130, 10, 110, 80))
GoodbyeButton.title = 'Goodbye!'
GoodbyeButton.bezelStyle = $.NSRegularSquareBezelStyle
@uchcode
uchcode / jxa-mvc.js
Created August 10, 2016 14:06
Javascript for Automation: MVC pattern example
ObjC.import('Cocoa')
////////////////////////////////////////////////////////////////////////////////
// View
////////////////////////////////////////////////////////////////////////////////
function Window(x, y, w, h) {
let f = $.NSMakeRect(x, y, w, h)
let s = $.NSTitledWindowMask | $.NSClosableWindowMask | $.NSMiniaturizableWindowMask// | $.NSResizableWindowMask
let b = $.NSBackingStoreBuffered
@uchcode
uchcode / hello-world.js
Created August 6, 2016 09:36
Hello world in JXA
ObjC.import('Cocoa')
function Window(x, y, w, h) {
const f = $.NSMakeRect(x, y, w, h)
const s = $.NSTitledWindowMask | $.NSClosableWindowMask | $.NSMiniaturizableWindowMask// | $.NSResizableWindowMask
const b = $.NSBackingStoreBuffered
const d = false
const win = $.NSWindow.alloc.initWithContentRectStyleMaskBackingDefer(f, s, b, d)
win.releasedWhenClosed = false
return win
@uchcode
uchcode / vue-component.html
Created July 28, 2016 14:43
Vue.js component example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Vue Component</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.12/vue.js"></script>
</head>
<body>
@uchcode
uchcode / amv-basic.html
Created July 23, 2016 13:25
Application( Model, View ) Example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>reactive</title>
</head>
<body>
<div id="contents"></div>