Skip to content

Instantly share code, notes, and snippets.

@huytd
huytd / package.json
Created September 8, 2016 20:25 — forked from dghuy/package.json
Webpack Babel React SCSS PostCSS
"dependencies": {
"autoprefixer": "^6.4.1",
"babel": "^6.5.2",
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"css-loader": "^0.25.0",
"node-sass": "^3.9.3",
"postcss-loader": "^0.13.0",
@huytd
huytd / websocket.go
Created September 9, 2016 18:58
WebSocket in Go
package main
import (
"log"
"net/http"
"github.com/gorilla/websocket"
)
type Message struct {
@huytd
huytd / pause.m
Last active September 10, 2016 20:38
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not enough memory" message:@"Guy! Look like your device doesn't have enough memory to run me! I'm gone now!" delegate:nil cancelButtonTitle:@"OK Bye!" otherButtonTitles:nil];
[alert show];
while ((!alert.hidden) && (alert.superview != nil))
{
[[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
}
lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentContainer(name: “YOUR_CORE_DATA”)
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
let context = (UIApplication.shared.delegate as! AppDelegate).persistenContainer.viewContext
lazy var applicationDocumentsDirectory: NSURL = {
let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return urls[urls.count-1] as NSURL
}()
lazy var managedObjectModel: NSManagedObjectModel = {
let modelURL = Bundle.main.url(forResource: "YOUR_CORE_DATA", withExtension: "momd")!
return NSManagedObjectModel(contentsOf: modelURL)!
}()
func saveContext() {
if managedObjectContext.hasChanges {
do {
try managedObjectContext.save()
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
// iOS 10 only
let ferrari = Subaru(context: managedObjectContext)
ferrari.model = "Honda CRV"
// :(
let ferrari = NSEntityDescription.insertNewObject(forEntityName: "Subaru", into: managedObjectContext) as! Subaru
ferrari.model = "Honda CRV"
@huytd
huytd / iosMakefile.mk
Created October 7, 2016 18:20
Makefile to build Cocoapods project and run with iPhone Simulator
PROJECT_NAME = ePPMobile
SCHEME_NAME = ePPMobile
BUILD_DIR = ./build
DEVICE_TYPE = iPad-Air-2, 10.0
all: build run
build: clean
xcodebuild -arch i386 -sdk iphonesimulator10.0 -workspace $(PROJECT_NAME).xcworkspace -scheme $(SCHEME_NAME) -derivedDataPath $(BUILD_DIR)
clean:
$ rustc binary_tree.rs -o binary_tree
error[E0072]: recursive type `Node` has infinite size
--> walkthrough_binary_tree.rs:1:1
|
1 | struct Node {
| ^ recursive type has infinite size
|
= help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `Node` representable