Skip to content

Instantly share code, notes, and snippets.

View n3tr's full-sized avatar

Jirat Ki. n3tr

View GitHub Profile
const typedef = `
interface Character {
name: String
}
type Human implements Character {
name: String
}
type Robot implements Character {
@n3tr
n3tr / createModelLoader.js
Created April 5, 2018 08:39
Create Sequelize Model Facebook DataLoader
const _ = require('lodash')
const { Op } = require('sequelize')
const DataLoader = require('dataloader')
// eslint-disable-next-line
const createModelLoader = (Model, inField) => {
return new DataLoader(async (keys) => {
// Create id:index map for further use
const idIndexMap = keys.reduce((map, key, index) => {
map[key] = index
@n3tr
n3tr / .block
Last active January 26, 2018 08:16
Film Flowers, Single Starter Code
license: gpl-3.0
@n3tr
n3tr / .block
Last active January 26, 2018 06:25
Film Flowers Petal Starter Code
license: mit
@n3tr
n3tr / App.js
Last active June 21, 2018 02:25 — forked from woraperth/webSocket.js
JavaScript Singleton to connect to WebSocket (originally for React project)
// App.js
import { getWebSocket } from './webSocket'
let ws = getWebSocket()
ws.send(...)
ws.onmessage = ev => { console.log(ev.data) }
node packages/create-react-app/index.js my-app-0.8.3 --scripts-version 0.8.3
Creating a new React app in /Users/n3tr/Code/js/create-react-app/my-app-0.8.3.
Installing packages. This might take a couple minutes.
Installing react, react-dom, react-scripts...
yarn add v0.17.10
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
@n3tr
n3tr / ViewController.swift
Created November 5, 2016 12:44
counterLabel
// ViewController.swift
class ViewController: NSViewController {
@IBOutlet weak var counterLabel: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
counterLabel.bind("stringValue", to: self, withKeyPath: #keyPath(currentCounter), options: nil)
}
}
@n3tr
n3tr / ViewController.swift
Created November 5, 2016 12:19
touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItemIdentifier) -> NSTouchBarItem?
// ViewController.swift
extension ViewController: NSTouchBarDelegate {
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItemIdentifier) -> NSTouchBarItem? {
switch identifier {
// Increase Item
case NSTouchBarItemIdentifier.increase:
let button = NSButton(title: "+", target: self, action: #selector(ViewController.increaseCounter))
let increaseItem = NSCustomTouchBarItem(identifier: identifier)
@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
@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
}
}