Skip to content

Instantly share code, notes, and snippets.

View sjehutch's full-sized avatar

scott hutchinson sjehutch

View GitHub Profile
@sjehutch
sjehutch / alert.swift
Created March 5, 2018 03:58
Alert helper
import Foundation
import UIKit
class Alert {
class func showBasic(title: String, message: String, vc: UIViewController) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
vc.present(alert, animated: true)
}
@sjehutch
sjehutch / EmailCheck.swift
Created March 5, 2018 03:59
Check email swift
extension String {
var isValidEmail: Bool {
let emailFormat = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
let emailPredicate = NSPredicate(format:"SELF MATCHES %@", emailFormat)
return emailPredicate.evaluate(with: self)
}
}
@sjehutch
sjehutch / Remove.cs
Created March 10, 2018 10:51
Remove Comments in a string in C#
using System.Text.RegularExpressions;
namespace test
{
class RemoveComments
{
public string removeComments(string input)
{
string multiLineCommentPattern = "(/\\*.*?\\*/)";
string singleLineCommentPattern = "(//.*(\n|\\\\n))";
@sjehutch
sjehutch / Reverse.py
Created March 12, 2018 00:11
Reverse integer python
def reverse(x):
"""
:type x: int
:rtype: int
"""
maxInt = 2 ** 31 - 1
minInt = -1 * 2 ** 31
if x < 0:
y = -1 * int(str(-x)[::-1])
else:
@sjehutch
sjehutch / axios-http.js
Created March 25, 2018 02:33
axis npm request
//run npm i axios
const axios = require("axios");
const url =
"https://maps.googleapis.com/maps/api/geocode/json?address=Florence";
axios
.get(url)
.then(response => {
console.log(
`City: ${response.data.results[0].formatted_address} -`,
`Latitude: ${response.data.results[0].geometry.location.lat} -`,
@sjehutch
sjehutch / unique-arrays.swift
Created April 27, 2018 06:34
Sorted Unique arrays swift 4
import UIKit
var nums = [0,0,1,1,1,2,2,3,3,4]
let unique = Array(Set(nums)).sorted().count
print (unique)
@sjehutch
sjehutch / test.json
Created May 12, 2018 14:49
test.json
{
"classifier_ids": [
"boxing_punch_525398221"
],
"owners": ["me"],
"threshold": 0.1
}
var https = require('https');
exports.handler = function(event, context) {
var req = https.request(event.url, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
@sjehutch
sjehutch / index.html
Created May 20, 2018 17:42
bitcoin price USD
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
<meta charset="utf-8">
@sjehutch
sjehutch / filterarrary.swift
Created May 21, 2018 20:25
Filter array with anonymous names
let array = [1,2,3,5,7,8,9]
let result = array.filter {($0 > 3)}
print (result)