Skip to content

Instantly share code, notes, and snippets.

View daansari's full-sized avatar

Danish A. Ansari daansari

  • Intuit
  • Mumbai
View GitHub Profile
let myTable = MLDataTable(...)
// Fetch the price column (and all it's values)
let priceColumn = myTable["price"]
// Create a new column that contains values that are the result of
// price * bedroom for each row
let priceTimesBedroomsColumn = myTable["price"] * myTable["bedrooms"]
// Remove rows that contain less that 2 bedrooms
@daansari
daansari / SelfSizingTableHeaderAndTableFooterViews.swift
Created July 27, 2020 17:16 — forked from smileyborg/SelfSizingTableHeaderAndTableFooterViews.swift
How to manually self-size UITableView tableHeaderView/tableFooterView in iOS 11
// For the best results, your tableHeaderView/tableFooterView should be a UITableViewHeaderFooterView with your content inside the contentView.
let tableHeaderView = UITableViewHeaderFooterView()
let fittingSize = CGSize(width: tableView.bounds.width - (tableView.safeAreaInsets.left + tableView.safeAreaInsets.right), height: 0)
let size = tableHeaderView.systemLayoutSizeFitting(fittingSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
tableHeaderView.frame = CGRect(origin: .zero, size: size)
tableView.tableHeaderView = tableHeaderView
// When you set this view to the tableHeaderView/tableFooterView on the table view, the table view will preserve the existing size of its frame.
// If you need to change the size, remove the tableHeaderView/tableFooterView, set a new frame on it, then re-set it on the table view again.
@daansari
daansari / Mac OSX Setup - Brew
Created March 14, 2019 09:56 — forked from jbelke/Mac OSX Setup - Brew
Mac OSX Setup - Brew and Cask
# Get Sudo.
if [ $EUID != 0 ]; then
sudo "$0" "$@"
exit $?
fi
# Install Xcode first - https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12
# Install Xcode command line tools.
xcode-select --install
self.cntView.layer.cornerRadius = 13.0
self.cntView.layer.shadowColor = UIColor.lightGray.cgColor
self.cntView.layer.shadowOpacity = 0.5
self.cntView.layer.shadowRadius = 10.0
self.cntView.layer.shadowOffset = .zero
self.cntView.layer.shadowPath = UIBezierPath(rect: self.cntView.bounds).cgPath
self.cntView.layer.shouldRasterize = true
//Note:- cntView is an IBOutlet
@daansari
daansari / isModal.swift
Created February 12, 2019 13:43 — forked from edenwaith/isModal.swift
Swift function to check if a view controller is being presented modally.
func isModal() -> Bool {
return self.presentingViewController?.presentedViewController == self
|| (self.navigationController != nil && self.navigationController?.presentingViewController?.presentedViewController == self.navigationController)
|| self.tabBarController?.presentingViewController is UITabBarController
}
@daansari
daansari / .swift
Created May 26, 2018 04:14 — forked from rd13/.swift
Copy database file from bundle to documents in Swift 3
func copyDatabaseIfNeeded() {
// Move database file from bundle to documents folder
let fileManager = FileManager.default
let documentsUrl = fileManager.urls(for: .documentDirectory,
in: .userDomainMask)
guard documentsUrl.count != 0 else {
return // Could not find documents URL
@daansari
daansari / Count lines of code in Xcode project
Created October 24, 2017 17:37 — forked from Tokuriku/Count lines of code in Xcode project
Count lines of code in SWIFT Xcode project
1. Open Terminal
2. cd to your Xcode project
3. Execute the following when inside your target project:
find . -name "*.swift" -print0 | xargs -0 wc -l
@daansari
daansari / registrations_controller.rb
Created November 1, 2016 15:51 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
import UIKit
import AsyncDisplayKit
var calculatedWidth: CGFloat = 0
class ViewController: UIViewController {
// MARK: Properties
private let containerNode: WidthTestContainerNode
@daansari
daansari / _form.html.erb
Created March 13, 2016 17:39 — forked from angelacode/_form.html.erb
Getting jquery token to work with acts-as-taggable-on
- semantic_form_for @question do |f|
= f.input :title, :label => "Type Your Question",
:wrapper_html => {:style => "list-style-type:none"},
:input_html => {:class => 'main_question'}
= f.input :body, :input_html => {:class => 'autogrow', :rows => 5},
:wrapper_html => {:style => "list-style-type:none"},
:label => "Question Details (optional)"
= f.input :tag_list, :class => 'larger widest', :"data-pre" => @question.tags.map(&:attributes).to_json,
:wrapper_html => {:style => "list-style-type:none"}