Skip to content

Instantly share code, notes, and snippets.

@snowshoes
snowshoes / escapeRegex.java
Last active March 8, 2017 21:25
[Java] esacpe regex special characters #tags: regex, string, char
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);
@snowshoes
snowshoes / containsAlphabets.swift
Last active March 8, 2017 21:26
[Swift] find alphabetic chars in a given string #tags: swift, objc, NSCharacterSet, unicodeScalars
/// 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)}
}
@snowshoes
snowshoes / Xcode_variable.sh
Last active March 11, 2017 07:49
[Get Project Directory displayed in Xcode] Termial Command, Tips, and Tricks #tags: xcode, objc, swift, ios
## 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
@snowshoes
snowshoes / getTImeOfDay.swift
Last active November 24, 2022 05:04
[Format time of the day Swift]find a way to get time of the day in words #tags: swift, date, time
// 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"))
@snowshoes
snowshoes / WebViewController.swift
Created March 12, 2017 11:57
[initi a simple Browser from WKWebView in iOS]Bronze Challenge of Chp6 Programmtic View Big Nerd Ranch #tags: swift3, ios, UIView, WKWebview
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() {
@snowshoes
snowshoes / foo.js
Created June 23, 2017 19:31 — forked from vvgomes/foo.js
Ramda vs Lodash
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()
@snowshoes
snowshoes / latest.js
Created August 21, 2017 09:21
find object from array by max property - js
// 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};
});
@snowshoes
snowshoes / maxvalue.js
Last active August 21, 2017 09:24
find max value of an attribute in an array of objects - js
//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});
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
@snowshoes
snowshoes / db-connect-test.php
Created August 30, 2017 18:00 — forked from chales/db-connect-test.php
Script for a quick PHP MySQL DB connection test.
<?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'");