Skip to content

Instantly share code, notes, and snippets.

View harryworld's full-sized avatar
🏠
Working from home

Harry Ng harryworld

🏠
Working from home
  • Hong Kong
View GitHub Profile
@harryworld
harryworld / google_map.md
Created October 28, 2014 07:00
Add Google Map in Rails

Google Map for Rails

Gmaps4rails is developed to simply create a Google Map with overlays (markers, infowindows…).

Requirements

  1. Create an empty repository in GitHub, named googlemaps, select the READM, license, and rails .gitignroe file
  2. Clone the repository to local workspace folder
  3. cd googlemaps
  4. rails _4.1.6_ new . -BGT
  5. git add -A
@harryworld
harryworld / nested_resources.md
Last active August 29, 2015 14:08
Nested Resources

Nested Resources

class Post < ActiveRecord::Base
  has_many :comments
end
 
class Comment < ActiveRecord::Base
  belongs_to :post
end
@harryworld
harryworld / json_api_quiz.md
Created November 12, 2014 21:43
JSON API Quiz

Here are the questions:

  1. How to keep my current changes, but also get the latest code from owner repository?

  2. How many routes do we have right now? (Hint: rake routes)

  3. What is the URL pattern for the routes?

  4. What do the status code 200, 201, 404, 500 mean?

@harryworld
harryworld / sorting.md
Last active August 29, 2015 14:10
Sorting Algorithm

Sort the following sequence

[69,81,30,38,9,2,47,61,32,79]

Some common sorting algorithms

//
// ShiftClickGestureRecognizer.swift
//
// Created by Harry Ng on 27/1/2016.
// Copyright © 2016 STAY REAL. All rights reserved.
//
import Cocoa
class ShiftClickGestureRecognizer: NSClickGestureRecognizer {
# Uncomment this line to define a global platform for your project
platform :osx, '10.11'
use_frameworks!
target 'AppName' do
end
target 'AppNameTests' do
#if os(OSX)
import Cocoa
#endif
#if os(iOS)
import UIKit
#endif
#if os(iOS)
import Cocoa
public struct HNColor {
public static var DarkGray: UIColor = UIColor(white: 36/255, alpha: 1)
public static var DeepGray: UIColor = UIColor(white: 27/255, alpha: 1)
}
#endif
@harryworld
harryworld / CABasicAnimation.swift
Last active August 10, 2016 14:21
Comparing iOS vs macOS animation
func animateView() {
CATransaction.begin()
CATransaction.setCompletionBlock { [unowned self] in
self.removeFromSuperview()
}
let rotationAtStart = view.layer?.valueForKeyPath("transform.rotation.x") as? NSNumber
let rotate = CABasicAnimation(keyPath: "transform.rotation.x")
rotate.duration = 0.3
@harryworld
harryworld / NSCollectionView.swift
Created August 17, 2016 14:26
Animate NSCollectionViewItem during dragging
func collectionView(collectionView: NSCollectionView, draggingSession session: NSDraggingSession, willBeginAtPoint screenPoint: NSPoint, forItemsAtIndexPaths indexPaths: Set<NSIndexPath>) {
if let indexPath = draggingIndexPaths.first,
item = collectionView.itemAtIndexPath(indexPath) {
draggingItem = item // draggingItem is temporary instance variable of NSCollectionViewItem
}
}
func collectionView(collectionView: NSCollectionView, draggingSession session: NSDraggingSession, endedAtPoint screenPoint: NSPoint, dragOperation operation: NSDragOperation) {
draggingItem = nil