Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / 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 / 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 / LogHandling.m
Created May 15, 2015 12:18
Objective-C Log Handling
#import <Foundation/Foundation.h>
#if DEBUG == 0
#define DebugLog(...)
#elif DEBUG == 1
#define DebugLog(...) NSLog(__VA_ARGS__)
#endif
int main()
{
@arslanbilal
arslanbilal / branchLog.sh
Last active August 29, 2015 14:23
Visualizing branch topology in git
git log --graph --full-history --all --color \
--pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s"
#Example Output:
* 3876a55 (origin/master, origin/HEAD, master) Merge branch 'master' of https://github.com/ArslanBilal/Instagram-Client
|\
| * 7d677fa Merge pull request #1 from ArslanBilal/develop
| |\
* | | d799dbc (HEAD, origin/develop, develop) Update README.md for new "Infinite scroll through paginated set of results" feature
* | | 88ac929 Infinite scroll through paginated set of results is added
@arslanbilal
arslanbilal / download.sh
Created February 8, 2016 16:52
Simple download shell script. Customise the file is you need something different.
#!/bin/sh
echo downloading pdf..
wget www.pdf995.com/samples/pdf.pdf
echo pdf downloaded.
echo changing the name from pdf.pdf to new-name.pdf..
mv pdf.pdf new-name.pdf

Videos