Skip to content

Instantly share code, notes, and snippets.

View n3tr's full-sized avatar

Jirat Ki. n3tr

View GitHub Profile
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-workerw.js').then(function(registration) {
// register success
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
}
import React from 'react'
const Button = (props) => {
return <button className="button" {...props} />
}
function isStateless(component) {
return !(component.prototype && component.prototype.render);
}
@n3tr
n3tr / id.swift
Last active October 30, 2016 15:27
WindowController.swift
fileprivate extension NSTouchBarCustomizationIdentifier {
static let windowBar = NSTouchBarCustomizationIdentifier("com.n3tr.countertouchbar.touchbar")
}
fileprivate extension NSTouchBarItemIdentifier {
static let label = NSTouchBarItemIdentifier("com.n3tr.countertouchbar.label")
}
class WindowController: NSWindowController {
// ...
class WindowController: NSWindowController {
// ..
override func makeTouchBar() -> NSTouchBar? {
let touchBar = NSTouchBar()
touchBar.delegate = self
touchBar.customizationIdentifier = .touchBar
touchBar.defaultItemIdentifiers = [.label]
return touchBar
}
}
extension WindowController: NSTouchBarDelegate {
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItemIdentifier) -> NSTouchBarItem? {
switch identifier {
case NSTouchBarItemIdentifier.label:
// Create custom touch bar Item
let custom = NSCustomTouchBarItem(identifier: identifier)
custom.customizationLabel = "Label Title"
// Create label as NSTextField
let label = NSTextField(labelWithString: "Hello, TouchBar")
fileprivate extension NSTouchBarCustomizationIdentifier {
static let windowBar = NSTouchBarCustomizationIdentifier("com.n3tr.countertouchbar.touchbar")
}
fileprivate extension NSTouchBarItemIdentifier {
static let label = NSTouchBarItemIdentifier("com.n3tr.countertouchbar.label")
}
class WindowController: NSWindowController {
// ...
@n3tr
n3tr / WindowController.swift
Created November 5, 2016 11:54
Add OtherItemsProxy
override func makeTouchBar() -> NSTouchBar? {
let touchBar = NSTouchBar()
touchBar.delegate = self
touchBar.customizationIdentifier = .touchBar
touchBar.defaultItemIdentifiers = [.label, .fixedSpaceSmall, .otherItemsProxy]
return touchBar
}
@n3tr
n3tr / ViewController.swift
Last active November 5, 2016 11:59
TouchBarItemsIdentifier
// ViewController.swift
fileprivate extension NSTouchBarCustomizationIdentifier {
static let counterTouchBar = NSTouchBarCustomizationIdentifier("com.n3tr.countertouchbar.counter")
}
fileprivate extension NSTouchBarItemIdentifier {
static let increase = NSTouchBarItemIdentifier("com.n3tr.countertouchbar.increase")
static let decrease = NSTouchBarItemIdentifier("com.n3tr.countertouchbar.decrease")
static let counter = NSTouchBarItemIdentifier("com.n3tr.countertouchbar.counter")
}
@n3tr
n3tr / ViewController.swift
Last active November 5, 2016 12:05
makeTouchBar()
class ViewController: NSViewController {
// ...
override func makeTouchBar() -> NSTouchBar? {
let touchBar = NSTouchBar()
touchBar.delegate = self
touchBar.customizationIdentifier = .counterTouchBar
touchBar.defaultItemIdentifiers = [.increase, .counter, .decrease]
return touchBar
}
}
@n3tr
n3tr / ViewController.swift
Last active November 5, 2016 12:14
dynamic and action handler
// ViewController.swift
class ViewController: NSViewController {
// (1)
dynamic var currentCounter = 0
// ...
// (2)
func increaseCounter() {
currentCounter += 1