Skip to content

Instantly share code, notes, and snippets.

View tcuongtran's full-sized avatar

Cuong Tran tcuongtran

View GitHub Profile
@tcuongtran
tcuongtran / cloudSettings
Last active September 9, 2019 19:05
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-09-09T19:05:14.128Z","extensionVersion":"v3.4.2"}
@tcuongtran
tcuongtran / gist:1eea8890726bdd9070479103a0395d2b
Created May 10, 2017 18:21
IE9: D3 throw exception on setProperty
(function () {
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var d3_style_prototype = this.CSSStyleDeclaration.prototype,
d3_style_setProperty = d3_style_prototype.setProperty;
d3_style_prototype.setProperty = function (name, value, priority) {
try {
d3_style_setProperty.call(this, name, value + '', priority);
} catch (exception) {
// console.warn('d3_style_prototype.setProperty - name: ', name, ', value: ', value, ', priority: ', priority, ', exception: ', exception);
@tcuongtran
tcuongtran / index.html
Last active February 24, 2017 20:54
D3 Multi-lines Chart
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>D3 Multi-lines Graph</title>
<style>
#vis > svg {
overflow: visible;
}
</style>
@tcuongtran
tcuongtran / index.html
Last active February 24, 2017 20:55
D3 Multi-bars Charts
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>D3 Multi-bar graph</title>
<style>
#vis {
padding: 20px;
}
@tcuongtran
tcuongtran / d3.hexbin.min.js
Last active February 24, 2017 20:56
D3 Hexagon State Grid Map with Legend
!function(){d3.hexbin=function(){function u(n){var r={};return n.forEach(function(n,t){var a=s.call(u,n,t)/o,e=Math.round(a),c=h.call(u,n,t)/i-(1&e?.5:0),f=Math.round(c),l=a-e;if(3*Math.abs(l)>1){var v=c-f,g=f+(f>c?-1:1)/2,m=e+(e>a?-1:1),M=c-g,d=a-m;v*v+l*l>M*M+d*d&&(f=g+(1&e?1:-1)/2,e=m)}var j=f+"-"+e,p=r[j];p?p.push(n):(p=r[j]=[n],p.i=f,p.j=e,p.x=(f+(1&e?.5:0))*i,p.y=e*o)}),d3.values(r)}function a(r){var t=0,u=0;return n.map(function(n){var a=Math.sin(n)*r,e=-Math.cos(n)*r,i=a-t,o=e-u;return t=a,u=e,[i,o]})}var e,i,o,c=1,f=1,h=r,s=t;return u.x=function(n){return arguments.length?(h=n,u):h},u.y=function(n){return arguments.length?(s=n,u):s},u.hexagon=function(n){return arguments.length<1&&(n=e),"m"+a(n).join("l")+"z"},u.centers=function(){for(var n=[],r=0,t=!1,u=0;f+e>r;r+=o,t=!t,++u)for(var a=t?i/2:0,h=0;c+i/2>a;a+=i,++h){var s=[a,r];s.i=h,s.j=u,n.push(s)}return n},u.mesh=function(){var n=a(e).slice(0,4).join("l");return u.centers().map(function(r){return"M"+r+"m"+n}).join("")},u.size=function(n){return arg
@tcuongtran
tcuongtran / activityindicator.swift
Created September 20, 2015 03:14
Swift Activity Indicator
let indicator:UIActivityIndicatorView = UIActivityIndicatorView (activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
indicator.color = UIColor.blackColor()
indicator.frame = CGRectMake(0.0, 0.0, 10.0, 10.0)
indicator.center = self.view.center
self.view.addSubview(indicator)
indicator.bringSubviewToFront(self.view)
indicator.startAnimating()
@tcuongtran
tcuongtran / DataTableViewController.swift
Created September 17, 2015 05:09
Swift 2.0 JSON-TableView
//
// DataTableViewController.swift
// tableView
//
// Created by Cuong Tran on 9/16/15.
// Copyright © 2015 Cuong Tran. All rights reserved.
//
import UIKit
@tcuongtran
tcuongtran / app-transport-security.txt
Last active September 17, 2015 01:37
Fix for App Transport Security has blocked a cleartext HTTP
1. Navigate to the “Info” Panel in your app target.
2. Add a new key titled “NSAppTransportSecurity” with type Dictionary
3. Add a new key under the one you just created with the name “NSAllowsArbitraryLoads” with type Boolean and value YES
Source:
http://www.looneydoodle.com/2015/07/ios9-app-transport-security-policy/
@tcuongtran
tcuongtran / httprequest.playground
Last active September 21, 2015 22:39
Swift 2.0 Perform http request and parse returned data
import Foundation
import XCPlayground
// Let asynchronous code run
XCPSetExecutionShouldContinueIndefinitely()
let url = NSURL(string: "http://www.reddit.com/.json")
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url!, completionHandler: {