This file contains 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
public String escape(String valueToEscape) { | |
StringBuilder sb = new StringBuilder(); | |
String specialCharactersOfRegex = ".\\+*?[^]$(){}=!<>|:-"; | |
for (int i = 0; i < valueToEscape.length(); i++) { | |
// get character one by one | |
char currentChar = valueToEscape.charAt(i); | |
// does current character include in special characters list ? | |
if (specialCharactersOfRegex.indexOf(currentChar) != -1) { | |
sb.append("\\" + currentChar); |
This file contains 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
/// StackOverflow - http://stackoverflow.com/questions/39585492/swift-3-conversion-value-of-type-characterset-has-no-member-characterismemb | |
/// given the string, check whether each char is in characters' letters range | |
var containsAlphabets: Bool { | |
//Checks if any of the characters inside the string are alphabets | |
return self.unicodeScalars.contains {CharacterSet.letters.contains($0)} | |
} |
This file contains 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
## Build Settings -> Preprocess Macros | |
PROJECT_DIR=@\""$PROJECT_DIR"\" | |
BUILD_ROOT=@\""$(BUILD_ROOT)"\" | |
## Then you can log it directly | |
## NSLog(@"project dir=%@, BUILD_ROOT_=%@", PROJECT_DIR, BUILD_ROOT); | |
## http://stackoverflow.com/questions/8888803/find-the-project-dir-for-an-xcode-project |
This file contains 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
// http://stackoverflow.com/questions/32649039/formatting-time-of-the-day-swift-morning-afternoon-evening-any-time | |
// Same Principle as BigNerdRanch Silver Challenge | |
let hour = Calendar.currentCalendar().component(.Hour, fromDate: Date()) | |
switch hour { | |
case 6..<12 : print(NSLocalizedString("Morning", comment: "Morning")) | |
case 12 : print(NSLocalizedString("Noon", comment: "Noon")) | |
case 13..<17 : print(NSLocalizedString("Afternoon", comment: "Afternoon")) | |
case 17..<22 : print(NSLocalizedString("Evening", comment: "Evening")) | |
default: print(NSLocalizedString("Night", comment: "Night")) |
This file contains 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 UIKit | |
import WebKit | |
class WebViewController: UIViewController, WKNavigationDelegate { | |
// MARK: iVars & properties | |
var webView: WKWebView? | |
let reqUrl = "https://www.bignerdranch.com" | |
// MARK: functions | |
override func loadView() { |
This file contains 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
var _ = require("lodash"); | |
var R = require("ramda"); | |
var companies = [ | |
{ name: "tw", since: 1993 }, | |
{ name: "pucrs", since: 1930 }, | |
{ name: "tw br", since: 2009 } | |
]; | |
var r1 = _(companies).chain() |
This file contains 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://stackoverflow.com/questions/39037005/get-object-from-array-by-max-property | |
var latest = values.reduce(function(l, e){ | |
return l.startedate > e.startdate ? {value: l.value, startdate: l.startdate} : {value: e.value, startdate: e.startdate} | |
}) | |
// function | |
function latest(values){ | |
return values.reduce(function(l, e){ | |
return l.startdate > e.startdate ? {value: l.value, startdate: l.startdate} : {value: e.value, startdate: e.startdate}; | |
}); |
This file contains 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://stackoverflow.com/questions/4020796/finding-the-max-value-of-an-attribute-in-an-array-of-objects | |
Math.max.apply(Math, array.map(function(e){return e.startdate}); |
This file contains 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
FROM php:7.0.4-fpm | |
RUN apt-get update && apt-get install -y libmcrypt-dev \ | |
mysql-client libmagickwand-dev --no-install-recommends \ | |
&& pecl install imagick \ | |
&& docker-php-ext-enable imagick \ | |
&& docker-php-ext-install mcrypt pdo_mysql |
This file contains 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 | |
# Fill our vars and run on cli | |
# $ php -f db-connect-test.php | |
$dbname = 'name'; | |
$dbuser = 'user'; | |
$dbpass = 'pass'; | |
$dbhost = 'host'; | |
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'"); |
OlderNewer