Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Brandon Ha brandonvanha

  • Toronto, Canada
View GitHub Profile
@brandonvanha
brandonvanha / FTPUpload.swift
Created Jul 24, 2018 — forked from Nirma/FTPUpload.swift
Upload a file via FTP on iOS or macOS
View FTPUpload.swift
import Foundation
import CFNetwork
public class FTPUpload {
fileprivate let ftpBaseUrl: String
fileprivate let directoryPath: String
fileprivate let username: String
fileprivate let password: String
@brandonvanha
brandonvanha / RAILS_CHEATSHEET.md
Created Jul 14, 2018 — forked from mdang/RAILS_CHEATSHEET.md
Ruby on Rails Cheatsheet
View RAILS_CHEATSHEET.md

Ruby on Rails Cheatsheet

Architecture

Create a new application

Install the Rails gem if you haven't done so before

View Simple Alamofire Calls in Swift 4
import Alamofire
func makeGetCallWithAlamofire() {
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1"
Alamofire.request(todoEndpoint)
.responseJSON { response in
// check for errors
guard response.result.error == nil else {
// got an error in getting the data, need to handle it
print("error calling GET on /todos/1")
View typescript_singleton.ts
class MyClass
{
private static _instance: MyClass;
private constructor()
{
//...
}
public static get Instance()
View generics_and_protocols.swift
protocol Numeric {
func *(lhs: Self, rhs: Self) -> Self
}
extension Double: Numeric {}
extension Float: Numeric {}
extension Int: Numeric {}
func genericMultiplier<T: Numeric>(lhs: T, rhs: T) -> T {
return lhs * rhs
@brandonvanha
brandonvanha / .swiftlint.yml
Created Jan 17, 2018 — forked from milanpanchal/.swiftlint.yml
SwiftLint's configuration rules example
View .swiftlint.yml
# Find all the available rules by running:
# swiftlint rules
disabled_rules: # rule identifiers to exclude from running
# - colon
# - comma
- control_statement
# - trailing_whitespace
opt_in_rules: # some rules are only opt-in
- empty_count
View getMinOrMaxFromJson.js
// Return min or max key's value
// calendar_date is just an example placeholder.
// result.recordet is array of JSON Object.
var minNum = Math.min.apply( Math, result.recordset.map( function ( o ) { return o.calendar_date; } ) );
var maxNum = Math.max.apply( Math, result.recordset.map( function ( o ) { return o.calendar_date; } ) );
// Return entire JSON Object.
@brandonvanha
brandonvanha / mailchimp-popup-for-wordpress.md
Created Dec 12, 2017 — forked from nickcernis/mailchimp-popup-for-wordpress.md
MailChimp Popup Script that works with WordPress sites
View mailchimp-popup-for-wordpress.md

MailChimp's default popup scripts can break on WordPress sites that use jQuery/jQuery UI unless you include their embed code as the final elements before the closing body tag.

Including them in this way isn't always possible or easy with WordPress.

The code below is an alternative implementation of the loader that forces MailChimp's popup scripts to appear below all other scripts upon page load.

To use it, modify the baseUrl, uuid, and lid attributes with the ones from the original popup script that MailChimp supplies.

<script>
View ConvertSecondsToHHMMss.sql
DECLARE @SecondsToConvert int
SET @SecondsToConvert = 23651
-- Declare variables
DECLARE @Hours int
DECLARE @Minutes int
DECLARE @Seconds int
DECLARE @Time datetime
-- Set the calculations for hour, minute and second
@brandonvanha
brandonvanha / cssversioner.php
Created Nov 7, 2017 — forked from vidluther/cssversioner.php
Add a query string to the end of the theme's style.css when WordPress is loaded.
View cssversioner.php
<?php
/**
* Add a filter to stylesheet_uri, which appends a query string to it automagically.
*/
add_filter('stylesheet_uri', 'zk_css_versioner');
/**
* the goal of this method is to append a query string to the css url for the site.
* the query string currently is determined by the last time the css file was modified
You can’t perform that action at this time.