Skip to content

Instantly share code, notes, and snippets.

View seanbehan's full-sized avatar

Sean Behan seanbehan

View GitHub Profile
@seanbehan
seanbehan / basic_auth_with_alamofire.swift
Last active September 14, 2018 17:38
basic auth with alamofire in swift
import Alamofire
let url = "https://example.com/"
let user = "me"
let pass = "pwd"
let headers: HTTPHeaders = [
"Authorization": "Basic " + ("\(user):\(pass)".data(using:.utf8)?.base64EncodedString() ?? ""),
]
@seanbehan
seanbehan / wordpress-post-tags-and-categories.sql
Created September 13, 2018 17:48
get list of wordpress post tags and taxonomies
select x.taxonomy, left(t.name, 50) name, left(p.post_title, 50) post_title from
wp_terms t,
wp_term_taxonomy x,
wp_term_relationships r,
wp_posts p
where
t.term_id = x.term_id
and
x.term_taxonomy_id = r.term_taxonomy_id
@seanbehan
seanbehan / emojis.csv
Created July 19, 2018 21:26
csv of emojis w/ invalids removed
😀 grinning face
😁 beaming face with smiling eyes
😂 face with tears of joy
🤣 rolling on the floor laughing
😃 grinning face with big eyes
😄 grinning face with smiling eyes
😅 grinning face with sweat
😆 grinning squinting face
😉 winking face
😊 smiling face with smiling eyes
@seanbehan
seanbehan / Reachability.swift
Created June 7, 2018 19:01
Reachability.swift class for detecting if network connection is available
import Cocoa
import SystemConfiguration
// Usage
// if Reachability.isConnectedToNetwork() {
// print("We're online!")
// }
public class Reachability {
class func isConnectedToNetwork() -> Bool {
guard let window = view.window else { print("Nope") ; return }
let panel = NSOpenPanel()
panel.canChooseFiles = false
panel.canChooseDirectories = true
panel.allowsMultipleSelection = false
panel.canCreateDirectories = true
panel.beginSheetModal(for: window) { (result) in
if result == NSFileHandlingPanelOKButton {
self.folderPath = panel.urls[0]
}
// Save data to file
let fileName = "Test"
let DocumentDirURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let fileURL = DocumentDirURL.appendingPathComponent(fileName).appendingPathExtension("txt")
print("FilePath: \(fileURL.path)")
let writeString = "Write this text to the fileURL as text in iOS using Swift"
do {
// Write to the file
@seanbehan
seanbehan / Base64Ext.swift
Created May 2, 2018 17:06
Encode and decode strings in base64 in swift ios
extension String {
func fromBase64() -> String? {
guard let data = Data(base64Encoded: self) else {
return nil
}
return String(data: data, encoding: .utf8)
}
func toBase64() -> String {
return Data(self.utf8).base64EncodedString()
}
@seanbehan
seanbehan / MainActivity.kt
Last active April 29, 2018 23:18
All the code you need for js/native bridge w/ html apps for android and ios (manifest and interface builder files excluded)
package com.package.name
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebView
import android.webkit.JavascriptInterface
import android.content.Context
class WebViewJsInterface(private val context: Context, private val webView: WebView) {
@JavascriptInterface
@seanbehan
seanbehan / mysql-uuid-trigger.sql
Created March 11, 2018 21:39
MySQL Trigger for Default UUID
-- if uuid is set use that, otherwise create uuid
create trigger trigger_defaults_on_users
before insert on users
for each row
set new.uuid = coalesce(nullif(new.uuid, ''), uuid())
;
@seanbehan
seanbehan / mailchimp_user_automation.php
Created March 11, 2018 01:31
Send Users to a Mailchimp List w/ Custom Fields in Pure PHP
<?php
$API_KEY = '[Mailchimp API Key Goes Here]';
$LIST_ID = "[Mailchimp List ID Here]";
$AUTH_HEADER = "Authorization: Basic ".base64_encode("anystring:".$API_KEY)."\r\nContent-type: application/x-www-form-urlencoded\r\n";
// Prob. fetched from db..
$list_of_users = [
(object)["first" => "John", "last" => "Smith", "email" => "john@example.com", "color" => "red"],
(object)["first" => "Jane", "last" => "Doe", "email" => "jane@example.com", "color" => "blue"]