Skip to content

Instantly share code, notes, and snippets.

View simrandotdev's full-sized avatar

Simran simrandotdev

View GitHub Profile
@simrandotdev
simrandotdev / Shape.js
Created October 7, 2019 15:12
Shape.js
function Shape(){
let shape = [];
//shape.totalVolume = totalVolume;
/* Added the function add the shape in the 'shape' array. */
shape.addShape = function (newShape) {
shape.push(newShape);
}
if let fileURL = Bundle.main.url(forResource: "filename", withExtension: "txt") {
if let fileContents = try? String(contentsOf: fileURL) {
// we loaded the file into a string!
}
}
@simrandotdev
simrandotdev / AndroidXMLProperties.md
Created January 4, 2020 04:07
XML Properties in Android

Android Manifest

android:screenOrientation="portrait"

This property is used in AndroidManifest file inside the activity tag to fix the orientation of the activity at all times.

android:theme="@style/AppTheme.NoActionBar"

This property will set a custom theme to the app or the Activity it is applied to.

android:windowSoftInputMode="adjustResize"

This will adjust the window size when the keyboard appears.

@simrandotdev
simrandotdev / UIViewBasics.swift
Created July 20, 2020 06:52
Adding views in other views and checking which view is contained in what UIView
func basicsOfViews() {
let v = UIView(frame: CGRect(x: 100, y: 100, width: 150, height: 150))
v.backgroundColor = .red
self.view.addSubview(v)
v.layer.masksToBounds = true
let v2 = UIView(frame: CGRect(x: 130, y: 140, width: 150, height: 150))
v2.backgroundColor = .yellow
self.view.addSubview(v2)
@simrandotdev
simrandotdev / settingViewsFrames.swift
Created July 20, 2020 06:53
Setting a Custom UIView inside other UIView
func settingViewsFrames() {
let v1 = UIView(frame: CGRect(x: 113, y: 111, width: 132, height: 194))
v1.backgroundColor = UIColor(red: 1, green: 0.4, blue: 1, alpha: 1)
v1.clipsToBounds = true
let v2 = UIView(frame: CGRect(x: 10, y: 10, width: 112, height: 174))
v2.backgroundColor = UIColor(red: 0.5, green: 1, blue: 0, alpha: 1)
let v3 = UIView(frame: CGRect(x: 43, y: 197, width: 160, height: 230))
v3.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1)
func boundsAndCenter() {
// Do any additional setup after loading the view.
let v1 = UIView(frame: CGRect(x: 110, y: 110, width: 130, height: 200))
v1.backgroundColor = .green
let v2 = UIView(frame: v1.bounds.insetBy(dx: 10, dy: 10))
v2.backgroundColor = .red
view.addSubview(v1)
v1.addSubview(v2)
func boundsAndCenter() {
// Do any additional setup after loading the view.
let v1 = UIView(frame: CGRect(x: 110, y: 110, width: 130, height: 200))
v1.backgroundColor = .green
let v2 = UIView(frame: v1.bounds.insetBy(dx: 10, dy: 10))
v2.backgroundColor = .red
view.addSubview(v1)
v1.addSubview(v2)
func transformations() {
let v1 = UIView(frame: CGRect(x: 113, y: 111, width: 132, height: 194))
v1.backgroundColor = .red
let v2 = UIView(frame: v1.bounds.insetBy(dx: 10, dy: 10))
v2.backgroundColor = .yellow
view.addSubview(v1)
v1.addSubview(v2)
v1.transform = CGAffineTransform(scaleX: 4, y: 2)
v2.transform = CGAffineTransform(scaleX: 4, y: 5)
lass UIViewBasicsController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor(named: "myColor")
// Get the color value of system Colors through TraitCollection
let yellow = UIColor.systemYellow
let light = UITraitCollection(userInterfaceStyle: .light)
@simrandotdev
simrandotdev / transformToDataExtensionFinalCode.swift
Last active August 15, 2020 00:45
Final Code for video transformTo from a data object to Codable Models
import UIKit
let url = URL(string: "https://reqres.in/api/users/2")!
URLSession.shared.dataTask(with: url) { (data, response, error) in
if error != nil {
print("Request failed with error: \(error?.localizedDescription)")
return
}