Skip to content

Instantly share code, notes, and snippets.

Avatar

Pofat pofat

View GitHub Profile
@pofat
pofat / NetworkLab8.md
Last active Apr 20, 2016
整合Firmata 與Express,供NDHU network lab 8 的教學說明 (2016.4.20.)
View NetworkLab8.md

在Express中整合Firmata與socketIO

  1. 用Express生成一個新專案
  2. 整合socket.io 與UI(參考這裡)
  3. 安裝firmata npm install firmata --save
  4. 在project根目錄下,新增一檔案 firmataConnector.js
  5. 在 bin/www 裡使用 firmataConnector 與連接
/* Firmata */
View firmataConnector.js
var firmata = require('firmata');
var debug = require('debug')('networkLab8:firmataConnector');
/**
* firmataConnector.js
*
* Connect to the Arduino via the Firmata protocol.
*
*/
View fuckoffATS.sh
/usr/libexec/PlistBuddy -c "Add:NSAppTransportSecurity:NSAllowsArbitraryLoads bool true" ./Info.plist
@pofat
pofat / MyUITextField.swift
Created Jul 28, 2016
Padding for UITextField
View MyUITextField.swift
MyUITextField: UITextField {
// Whatever you like
let padding = UIEdgeInsets(top: 5, left: 5, bottom: 6, right: 6);
// Paddging for place holder
override func placeholderRectForBounds(bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, padding)
}
// Padding for text
override func textRectForBounds(bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, padding)
@pofat
pofat / BattleShip.swift
Last active Sep 1, 2016
Battleship in OOP and FP
View BattleShip.swift
typealias Distance = Double
/// A struct to represent real position of the ship
struct Position {
var x: Double
var y: Double
}
extension Position {
/// Calculate if this position lies in the given range
@pofat
pofat / .vimrc
Last active Oct 21, 2016
Config file for my vim
View .vimrc
set nocompatible " Make vim behave more usefule way
so ~/.vim/plugins.vim " Manage plugins by vundle
"-------------- Indentation ------------
set tabstop=4 " Number of space per tab
set shiftwidth=4 " Indent 4 columns for << and >> operations
set expandtab " Replace tab with space
set autoindent " Indent at the same level of the previous line
"-------------- Searching --------------
@pofat
pofat / .gvimrc
Created Oct 21, 2016
Config file for my MacVime
View .gvimrc
"-------------- Color config --------------
colorscheme atom-dark " My Vim GUI color scheme
"--------------------UI tweaks--------------------
set vb t_vb= " Disable bell after GUI startemd
" Some tweaks of the atom-dark theme
" Normal fg and bg color
hi Normal guifg=#eeeeee guibg=#252b3a
" fg and bg color of visual mode
@pofat
pofat / plugins.vim
Created Oct 21, 2016
My Vundle config file
View plugins.vim
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
" All of your Plugins must be added before the following line
Plugin 'tpope/vim-vinegar'
@pofat
pofat / address_of_struct_Swift3.swift
Last active Oct 30, 2016
Print struct address in Swift 3
View address_of_struct_Swift3.swift
// Get array address
func getBufferAddress<T>(of array: [T]) -> String {
return array.withUnsafeBufferPointer { buffer in
return String(describing: buffer.baseAddress)
}
}
// Realize copy-on-write
var fiverInts = [1,2,3,4,5]
let copyFive = fiverInts
@pofat
pofat / bytes_handler.swift
Created Nov 1, 2016
A method to retrieve byte array and bit array from Data in Swift 3
View bytes_handler.swift
// Using UInt8 as Byte
typealias Byte = UInt8
enum Bit: Int {
case zero, one
}
extension Data {
var bytes: [Byte] {
var byteArray = [UInt8](repeating: 0, count: self.count)
self.copyBytes(to: &byteArray, count: self.count)