Skip to content

Instantly share code, notes, and snippets.

@arslanbilal
arslanbilal / HTTPRequest.swift
Created May 9, 2015 22:00
Getting JSON Data in the NSDictionary with HTTP GET Request
let urlString: String = "http://example.com"
var url: NSURL = NSURL(string: urlString)!
var data = NSData()
var request = NSMutableURLRequest(URL: url, cachePolicy: .UseProtocolCachePolicy, timeoutInterval: 60)
request.HTTPMethod = "GET"
var response: AutoreleasingUnsafeMutablePointer<NSURLResponse?> = nil
var error: NSErrorPointer = nil
@arslanbilal
arslanbilal / Last7Days.swift
Last active August 29, 2015 14:20
Creating "today's date and last seven days' date" in to the String array in Swift Lang.
let date = NSDate() // Today's date.
let dateFormatter = NSDateFormatter() // Creating a dateFormatter object for making readable date
var array = [String]() // Store the today's date and last 7 date.
let secondInADay: NSTimeInterval = 24 * 60 * 60 // A day NSTimeInterval
let timeInterval = date.timeIntervalSince1970 // Today's NSTimeInteval
dateFormatter.dateFormat = "EE-yyyyMMdd" // Making a dateFormat
dateFormatter.locale = NSLocale(localeIdentifier:"us") //
array.append(dateFormatter.stringFromDate(date)) // Adding today's date in to the array
@arslanbilal
arslanbilal / messageBox.cs
Created December 6, 2014 22:38
Message box with options in C#
if(MessageBox.Show("Are you sure?", "Yes", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
//code here...
}
else
{
//code here...
}
@arslanbilal
arslanbilal / textBoxKeyPress_Function.cs
Last active August 29, 2015 14:10
Entering only letters and just one " " character into the textBox in C#
private void textBoxKeyPressLetter(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar) &&
(e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
@arslanbilal
arslanbilal / textBoxKeyPress_Function.cs
Last active August 29, 2015 14:10
Entering only numbers and just one "." character into the textBox in C#
private void textBoxKeyPressNumber(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
(e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
@arslanbilal
arslanbilal / SwiftNumericLiterals.swift
Last active August 29, 2015 14:05
Swift Numeric Literals
let decimalInteger = 17
let binaryInteger = 0b10001 // 17 in binary notation
let octalInteger = 0o21 // 17 in octal notation
let hexadecimalInteger = 0x11 // 17 in hexadecimal notation
let decimalNumber = 1.25e2 // 125.0 e2 means 10^2
let decimalNumber2 = 1.25e-2 // 0.0125 e-2 means 10^-2
let hexadecimalExponent = 0xFp2 // 60.0 means 15x2^2
let hexadecimalExponent2 = 0xFp-2 // 3.75 means 15x2^-2