Skip to content

Instantly share code, notes, and snippets.

View brandonvanha's full-sized avatar
🏠
Hello

Brandon Ha brandonvanha

🏠
Hello
  • Toronto, Canada
View GitHub Profile
@brandonvanha
brandonvanha / getAllPropertyNames.js
Last active August 29, 2015 14:07
Iterates over all properties (not just enumerable ones).
function getAllPropertyNames(obj) {
var result = [];
while (obj) {
// Add the own property names of `obj` to `result`
Array.prototype.push.apply(result, Object.getOwnPropertyNames(obj));
obj = Object.getPrototypeOf(obj);
}
return result;
}
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/Javascript">
$(document).ready(function () {
$(function () {
$('.add').on('click',function(){
var $qty=$(this).closest('p').find('.qty');
@brandonvanha
brandonvanha / settingAndGetting.js
Last active August 29, 2015 14:07
Defining Accessors via an Object Literal & Property Descriptors
// Via Object Literal
var obj = {
get foo() {
return 'getter';
},
set foo(value) {
console.log('setter: ' + value);
}
@brandonvanha
brandonvanha / EfficientCodes.txt
Last active August 29, 2015 14:08
Efficient Codes
• Apply the array method map() to a string:
> [].map.call('abc', function (x) { return x.toUpperCase() })
[ 'A', 'B', 'C' ]
Using map() generically is more efficient than using split(''), which creates an intermediate array:
> 'abc'.split('').map(function (x) { return x.toUpperCase() })
[ 'A', 'B', 'C' ]
Apply a string method to nonstrings. toUpperCase() converts the receiver to a string and uppercases the result:
> String.prototype.toUpperCase.call(true)
@brandonvanha
brandonvanha / checkSheet.js
Last active August 29, 2015 14:08
Cheat Sheet: Working with Objects
Cheat Sheet: Working with Objects
This section is a quick reference with pointers to more thorough explanations.
• Object literals (see “Object Literals” on page 198):
var jane = {
name: 'Jane',
'not an identifier': 123,
describe: function () { // method
return 'Person named '+this.name;
},
@brandonvanha
brandonvanha / sharedArrays.js
Created October 23, 2014 22:25
Be aware of sharing clearing arrays
Clearing shared arrays
You need to be aware of the fact that setting an array’s length to zero affects everybody
who shares the array:
> var a1 = [1, 2, 3];
> var a2 = a1;
> a1.length = 0;
> a1
[]
> a2
@brandonvanha
brandonvanha / Dragging.swift
Last active August 29, 2015 14:18
Dragging controls
import UIKit
class ViewController: UIViewController {
var xFromCenter: CGFloat = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
@brandonvanha
brandonvanha / Refreshing.swift
Created April 5, 2015 20:39
Pull to refresh
class UserTableViewController: UITableViewController {
var refresher: UIRefreshControl!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
refresher = UIRefreshControl()
@brandonvanha
brandonvanha / .eslintrc
Created March 24, 2017 18:02 — forked from cletusw/.eslintrc
ESLint Reset - A starter .eslintrc file that resets all rules to off and includes a description of what each rule does. From here, enable the rules that you care about by changing the 0 to a 1 or 2. 1 means warning (will not affect exit code) and 2 means error (will affect exit code).
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
@brandonvanha
brandonvanha / Install Composer using MAMP's PHP.md
Created October 23, 2017 06:12 — forked from irazasyed/Install Composer using MAMP's PHP.md
Instructions on how to change preinstalled Mac OS X PHP to MAMP's PHP Installation and then install Composer Package Management

Change default Mac OS X PHP to MAMP's PHP Installation and Install Composer Package Management


Instructions to Change PHP Installation


First, Lets find out what version of PHP we're running (To find out if it's the default version).

To do that, Within the terminal, Fire this command:

which php