Skip to content

Instantly share code, notes, and snippets.

View dilumdesilva's full-sized avatar
👨‍💻
Mastering iOS and Flutter

Dilum De Silva dilumdesilva

👨‍💻
Mastering iOS and Flutter
View GitHub Profile

Understanding UIViewController Rotation

Problem

To enable the rotation of a single view controller used to display the preview of Images/Videos. It is intuitive to allow user to rotate there device and screen changes accordingly, so it feels pleasant. But to achieve this, we need to enable the (almost) all Supported Device orientations.

Ex: `Portrait`, `LandscapeLeft`, `LandscapeRight`.
@dilumdesilva
dilumdesilva / CheckDeviceMotion.swift
Created November 23, 2022 03:37 — forked from garymansted/CheckDeviceMotion.swift
Check devices motions -> pitch, roll and yaw SWIFT
import CoreMotion // Import CoreMotion (header)
// Class vars
var pitch = 0.0
var attitude: CMAttitude?
var roll = 0.0
var yaw = 0.0
let motionManager = CMMotionManager() // Create motionManager instance
@dilumdesilva
dilumdesilva / CheckDeviceMotion.swift
Created November 23, 2022 03:37 — forked from garymansted/CheckDeviceMotion.swift
Check devices motions -> pitch, roll and yaw SWIFT
import CoreMotion // Import CoreMotion (header)
// Class vars
var pitch = 0.0
var attitude: CMAttitude?
var roll = 0.0
var yaw = 0.0
let motionManager = CMMotionManager() // Create motionManager instance
@dilumdesilva
dilumdesilva / CodebleToDict.swift
Last active July 14, 2022 13:59
Useful Swift Code Snippets
extension Encodable {
/// converts a codable model to a dictionary
var dictionary: [String: Any]? {
guard let data = try? JSONEncoder().encode(self) else { return nil }
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? [String: Any] }
}
}
@dilumdesilva
dilumdesilva / HOWTODMG.md
Created February 22, 2022 05:43 — forked from jadeatucker/HOWTODMG.md
How to create a "DMG Installer" for Mac OS X

Creating a "DMG installer" for OS X

A DMG Installer is convenient way to provide end-users a simple way to install an application bundle. They are basically a folder with a shortcut to the Applications directory but they can be customized with icons, backgrounds, and layout properties. A DMG file (.dmg) is a Mac OS X Disk Image file and it is used to package files or folders providing compression, encryption, and read-only to the package.

##Creating the DMG file #Disk Utility

@dilumdesilva
dilumdesilva / Activate Office 2019 for macOS VoL.md
Created January 30, 2022 20:09 — forked from zthxxx/Activate Office 2019 for macOS VoL.md
crack activate office on mac with license file

Activate MS Office 2019/2016 for macOS - Microsoft_Office_2019_VL_Serializer

Office 2019 above

2019-06-03

Note that Office2019 DO NOT support activate via simple copy/paste plist license file which is the simplest way to activate Office 2016. Fortunately, you can also use the VL Serializer tool, just install Office 2019 and Serializer, then run Serializer to activate.

Ref

@dilumdesilva
dilumdesilva / golang_collection.go
Last active October 31, 2020 02:03
Useful golang code snippets
//Improved random number generator
source := rand.NewSource(time.Now().UnixNano())
r := rand.New(source)
newPos := r.Intn(len(slice) - 1)
@dilumdesilva
dilumdesilva / alias_collection.md
Last active February 19, 2021 18:36
This gist contains steps to make fresh macOS developer environment.

personal aliases

  • alias openzsh="open -e /Users/dilumdesilva/.zshrc"
  • alias openzsh="open -e ~/.zshrc"
  • alias reloadzsh="source ~/.zshrc"
  • alias open="open ."

git aliases

  • alias add="git add"
  • alias commit="git commit"
  • alias check="git checkout"
@dilumdesilva
dilumdesilva / add_to_session.php
Created December 16, 2019 22:54
How to send a simple ajax call from front end to a php backend (php file) to add a value to the $_SESSION
<?php
if(!isset($_SESSION)) { session_start(); }
$username = $_POST['user_name'];
$_SESSION['usernames'] = $username;
?>