Skip to content

Instantly share code, notes, and snippets.

View andreconghau's full-sized avatar

andre andreconghau

  • Software Engineer
  • việt nam
View GitHub Profile
@andreconghau
andreconghau / loadimage_kingfisher.swift
Last active October 14, 2020 06:36
Kingfisher download image and caching in memory. can be show progress bar downloading
// https://github.com/onevcat/Kingfisher/wiki/Installation-Guide
// https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet
import UIKit
import Kingfisher
class example {
func viewDidLoad {
// Apply KingFisher
let resource = ImageResource(downloadURL: imgUrl!)
@andreconghau
andreconghau / missing_field_struct.swift
Last active October 12, 2020 09:17
Swift 5.3 Json Convert
// Missing Field Key thì thêm ?
struct CourseMisingFied: Decodable {
let id: Int?
let name: String?
let link: String?
let imageUrl: String?
}
@andreconghau
andreconghau / swift_http_request.swift
Created October 9, 2020 07:01
Call API Method GET with URLSession in Swift 5
let url = URL(string: "https://jsonplaceholder.typicode.com/posts")!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!)
}
task.resume()
@andreconghau
andreconghau / async.swift
Last active October 9, 2020 07:02
GCD in Swift 5
let queue = DispatchQueue(label: "queue_action_1")
queue.async {
for i in 1...5 {
print("async=" + String(i))
}
}
for i in 1...5 {
print("sync=" + String(i))
}
@andreconghau
andreconghau / SWIFT-UIImageView-Cache.swift
Last active October 9, 2020 07:02
apply Caching for Image Loading to enhance performance in Swift 5
extension UIImageView {
/// Loads image from web asynchronosly and caches it, in case you have to load url
/// again, it will be loaded from cache if available
func load(url: URL, placeholder: UIImage?, cache: URLCache? = nil) {
let cache = cache ?? URLCache.shared
let request = URLRequest(url: url)
if let data = cache.cachedResponse(for: request)?.data, let image = UIImage(data: data) {
self.image = image
} else {
self.image = placeholder
@andreconghau
andreconghau / scrapy_insert_mysql.py
Created December 3, 2019 01:44
Scrapy Mysql upset (update if existed, else insert)
import sys
import MySQLdb
import hashlib
from datetime import datetime
from scrapy.exceptions import DropItem
from scrapy.http import Request
class EmptyItemPipeline(object):
def process_item(self, item, spider):
@andreconghau
andreconghau / ig_convert_media_id_to_url
Created September 18, 2019 06:06
Instagram Convert Media ID to Post URl
// based on ggwarpig stackoverflow anwser to
// "Where do I find the Instagram media ID of a image"
// @ https://stackoverflow.com/a/37246231
function instagram_id_to_url($instagram_id){
$url_prefix = "https://www.instagram.com/p/";
if(!empty(strpos($instagram_id, '_'))){
@andreconghau
andreconghau / hashtag.php
Created August 22, 2019 06:31
get HashTag
<?php
function convertAll($str) {
$regex = "/[@#](\w+)/";
$hrefs = [
'#' =&gt; 'hashtag?tag',
'@' =&gt; 'profile?username'
];
$result = preg_replace_callback($regex, function($matches) use ($hrefs) {
@andreconghau
andreconghau / install-mongodb-mamp
Created August 10, 2019 09:22
How to install mongodb php extension in Mamp Pro MacOS
brew install autoconf
php -m
php -v
which php
pecl install mongodb
Check Folder
/Applications/MAMP/bin/php/php7.0.15/lib/php/extension/no-debug-non-zts
update template php.ini to add ext
extension=mongodb.so
@andreconghau
andreconghau / Install Composer using MAMP's PHP.md
Created June 17, 2019 09:28 — forked from irazasyed/Install Composer using MAMP's PHP.md
Instructions on how to change preinstalled Mac OS X PHP to MAMP's PHP Installation and then install Composer Package Management

Change default Mac OS X PHP to MAMP's PHP Installation and Install Composer Package Management


Instructions to Change PHP Installation


First, Lets find out what version of PHP we're running (To find out if it's the default version).

To do that, Within the terminal, Fire this command:

which php