Skip to content

Instantly share code, notes, and snippets.

View sourleangchhean168's full-sized avatar
🎯
Focusing

Sour LeangChhean sourleangchhean168

🎯
Focusing
View GitHub Profile
@sourleangchhean168
sourleangchhean168 / RootCalculate.c
Created May 12, 2017 06:36
C program to Find all Roots of a Quadratic equation
#include <stdio.h>
#include <math.h>
int main()
{
double a, b, c, determinant, root1,root2, realPart, imaginaryPart;
printf("Enter coefficients a, b and c: ");
scanf("%lf %lf %lf",&a, &b, &c);
@sourleangchhean168
sourleangchhean168 / UIColorExension.swift
Created May 12, 2017 06:41
iOS: My Favorite UIColor Extension Swift 3.0.1
extension UIColor {
convenience init(rgb: Int, alpha: CGFloat) {
let r = CGFloat((rgb & 0xFF0000) >> 16)/255
let g = CGFloat((rgb & 0xFF00) >> 8)/255
let b = CGFloat(rgb & 0xFF)/255
self.init(red: r, green: g, blue: b, alpha: alpha)
}
convenience init(red: Int, green: Int, blue: Int) {
self.init(red: CGFloat(red), green: CGFloat(green), blue: CGFloat(blue), alpha: 1.0)
@sourleangchhean168
sourleangchhean168 / warning.sh
Created May 12, 2017 06:43
Show Warning to remind you to modify later in Xcode
TAGS="TODO:|FIXME:"
ERRORTAG="DANGER:|ERROR:"
find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/"
#find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/"
@sourleangchhean168
sourleangchhean168 / CustomActivityIndicator.swift
Created May 12, 2017 06:47
iOS customized activity indicator with Swift 3.0.2
@discardableResult
func customActivityIndicatory(_ viewContainer: UIView, startAnimate:Bool? = true) -> UIActivityIndicatorView {
let mainContainer: UIView = UIView(frame: viewContainer.frame)
mainContainer.center = viewContainer.center
mainContainer.backgroundColor = UIColor.init(netHex: 0xFFFFFF)
mainContainer.alpha = 0.5
mainContainer.tag = 789456123
mainContainer.isUserInteractionEnabled = false
let viewBackgroundLoading: UIView = UIView(frame: CGRect(x:0,y: 0,width: 80,height: 80))
@sourleangchhean168
sourleangchhean168 / phAssettoUIImage.swift
Created May 12, 2017 06:50
Convert PHAsset to UIImage: 3.0.1
func getAssetThumbnail(asset: PHAsset, size: CGFloat) -> UIImage {
let retinaScale = UIScreen.main.scale
let retinaSquare = CGSize(width: size * retinaScale, height: size * retinaScale)//(size * retinaScale, size * retinaScale)
let cropSizeLength = min(asset.pixelWidth, asset.pixelHeight)
let square = CGRect(x:0, y: 0,width: CGFloat(cropSizeLength),height: CGFloat(cropSizeLength))
let cropRect = square.applying(CGAffineTransform(scaleX: 1.0/CGFloat(asset.pixelWidth), y: 1.0/CGFloat(asset.pixelHeight)))
let manager = PHImageManager.default()
let options = PHImageRequestOptions()
var thumbnail = UIImage()
options.isSynchronous = true
@sourleangchhean168
sourleangchhean168 / screenshotAlbumCount.swift
Created May 12, 2017 06:51
Get screenshot (album) count in swift
let albumsPhoto:PHFetchResult<PHAssetCollection> = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: nil)
albumsPhoto.enumerateObjects({(collection, index, object) in
if collection.localizedTitle == "Screenshots"{
let photoInAlbum = PHAsset.fetchAssets(in: collection, options: nil)
print(photoInAlbum.count) //Screenshots albums count
}
})
extension UIButton{
func roundCorners(corners:UIRectCorner, radius: CGFloat){
let borderLayer = CAShapeLayer()
borderLayer.frame = self.layer.bounds
borderLayer.strokeColor = UIColor.green.cgColor
borderLayer.fillColor = UIColor.clear.cgColor
borderLayer.lineWidth = 10.5
let path = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
@sourleangchhean168
sourleangchhean168 / multiple_ssh_setting.md
Created October 30, 2017 17:11 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@sourleangchhean168
sourleangchhean168 / collectionViewScroll
Created March 25, 2018 18:07 — forked from genedelisa/collectionViewScroll
UICollectionView scroll to make section header visible
/**
Scroll to make the the given section header visible.
The function scrollToItemAtIndexPath will scroll to the item and hide the section header.
Swift 3.
*/
func scrollToSection(_ section:Int) {
if let cv = self.collectionView {
let indexPath = IndexPath(item: 1, section: section)
if let attributes = cv.layoutAttributesForSupplementaryElement(ofKind: UICollectionElementKindSectionHeader, at: indexPath) {
@sourleangchhean168
sourleangchhean168 / collectionView_cell_animation.swift
Created April 11, 2018 13:35
CollectionView Cell Animation in Swift 4
let cell = collectionView.cellForItem(at: indexPath)
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 5, options: [],
animations: {
cell!.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
},
completion: { finished in
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 5, options: .curveEaseInOut,
animations: {