Skip to content

Instantly share code, notes, and snippets.

@phplaw
phplaw / Basic.ts
Last active June 4, 2019 19:01
Learn TypeScript
let title: string = 'Hello World';
// or let title = $('#user_name').val();
(title as string).split(' ');
(<string>title).split(' ');
// fix window issue
// Element implicitly has an 'any' type because type 'Window' has no index signature?
declare global {
interface Window { MyNamespace: any; }
@phplaw
phplaw / startRCServer.sh
Last active January 3, 2019 19:56
Bash Script Utilities
#!/bin/bash
UP=$(pgrep mysql | wc -l);
if [ "$UP" -ne 1 ];
then
echo "Turn Mysql Server On.";
# sudo service mysql start
#/Library/Application\ Support/appsolute/MAMP\ PRO/db/mysql56
nohup /Applications/MAMP/Library/bin/mysqld_safe --default_time_zone=Australia/Sydney --port=3306 --user=root --datadir=/Library/Application\ Support/appsolute/MAMP\ PRO/db/mysql56 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log &>/dev/null &
sleep 2 && ./rc.sh reload server development
else
@phplaw
phplaw / database.promise.js
Created December 10, 2018 17:59
NodeJS development Tips & Tricks
const doQuery = function(db, sql, parameters) {
if (parameters === void(0)) {
parameters = [];
}
return new Promise(function(resolve, reject) {
db.driver.execQuery(sql, parameters, function(err, result) {
resolve(result);
});
});
};
@phplaw
phplaw / doubleclick.js
Created September 10, 2018 22:42 — forked from mauriciosoares/doubleclick.js
rxjs double click example
let clickStream = Rx.Observable.fromEvent(document.getElementById('link'), 'click');
clickStream
.buffer(clickStream.debounce(250))
.map(list => list.length)
.filter(x => x === 2)
.subscribe(() => {
console.log('doubleclick');
})
@phplaw
phplaw / .bash_profile
Created August 21, 2018 03:46 — forked from natelandau/.bash_profile
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
@phplaw
phplaw / domains.md
Created August 13, 2018 12:33
Node Error Handling and Domains

Node Error Handling and Domains

"Occurrences in this domain are beyond the reach of exact prediction because of the variety of factors in operation, not because of any lack of order in nature." - Albert Einstein

"Master of my domain" - Larry David

Error handling in an asynchronous language works in a unique way and presents many challenges, some unexpected. This tutorial reviews the various error handling patterns available in node, and explains how domains can be used to improve it.

There are four main error handling patterns in node:

  • Error return value
@phplaw
phplaw / use $compile outside a directive in Angularjs
Last active July 10, 2018 11:46 — forked from shengoo/use $compile outside a directive in Angularjs
use $compile outside a directive in Angularjs
$(function() {
// myApp for test directive to work, ng for $compile
var $injector = angular.injector(['ng', 'myApp']);
$injector.invoke(function($rootScope, $compile) {
$('body').prepend($compile('<div ng-attr-tooltip="test">Cancel</div>')($rootScope));
});
});
/**
@phplaw
phplaw / ng-repeat-complete.htm
Created April 12, 2018 11:26 — forked from bennadel/ng-repeat-complete.htm
Hooking Into The Complete Event Of An ngRepeat Loop In AngularJS
<!doctype html>
<html ng-app="Demo">
<head>
<meta charset="utf-8" />
<title>
Hooking Into The ngRepeat Completion Event In AngularJS
</title>
<style type="text/css">
@phplaw
phplaw / angularjs_directive_attribute_explanation.md
Created March 6, 2017 03:21 — forked from CMCDragonkai/angularjs_directive_attribute_explanation.md
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
<?php
function time2str($ts) {
if(!ctype_digit($ts)) {
$ts = strtotime($ts);
}
$diff = time() - $ts;
if($diff == 0) {
return 'now';
} elseif($diff > 0) {
$day_diff = floor($diff / 86400);