Skip to content

Instantly share code, notes, and snippets.

View cristinaITdeveloper's full-sized avatar
💻
Coding....

Cristina Developer cristinaITdeveloper

💻
Coding....
View GitHub Profile
@cristinaITdeveloper
cristinaITdeveloper / Utils.swift
Created June 25, 2017 16:08
Swift - Open link in safari from web view - iOS (use this method in viewcontroller that implement the UIWebViewDelegate protocol
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
switch navigationType {
case .linkClicked:
// Open links in Safari
guard let url = request.url else { return true }
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
// openURL(_:) is deprecated in iOS 10+.
@cristinaITdeveloper
cristinaITdeveloper / get_random_elements.php
Created May 22, 2017 11:54
PHP get random elements from array
<?php
function get_random_elements($array, $limit = 0 ) {
shuffle($array);
if ( $limit > 0 ) {
$array = array_splice($array, 0, $limit);
}
return $array;
}
?>
@cristinaITdeveloper
cristinaITdeveloper / replace_all.js
Created May 15, 2017 12:32
Javascript replace all character in string
function escapeRegExp(str) {
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}