This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/SwiftyJSON/SwiftyJSON | |
import Alamofire | |
import SwiftyJSON | |
classs ExampleSwiftyJson { | |
func jsonSwiftyJson() { | |
let user = "user" | |
let password = "password" | |
let credential = URLCredential(user: user, password: password, persistence: .forSession) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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!) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Missing Field Key thì thêm ? | |
struct CourseMisingFied: Decodable { | |
let id: Int? | |
let name: String? | |
let link: String? | |
let imageUrl: String? | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, '_'))){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function convertAll($str) { | |
$regex = "/[@#](\w+)/"; | |
$hrefs = [ | |
'#' => 'hashtag?tag', | |
'@' => 'profile?username' | |
]; | |
$result = preg_replace_callback($regex, function($matches) use ($hrefs) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |