Skip to content

Instantly share code, notes, and snippets.

View calvinchoy's full-sized avatar

Calvin Choy calvinchoy

View GitHub Profile
@calvinchoy
calvinchoy / JS - simple jsonp call.js
Last active April 4, 2020 08:38
JS - simple jsonp call #jquery
$.ajax({
url: "url to the server processing code",
dataType: "jsonp",
contentType: "application/json",
data: JSON.stringify({}),
success: function(response) {
//response is json data returned from server side url
}
});
var $root = $('html, body');
$('a').click(function() {
var href = $.attr(this, 'href');
$root.animate({
scrollTop: $(href).offset().top
}, 500, function () {
window.location.hash = href;
});
return false;
});
@calvinchoy
calvinchoy / sh - close process on port.sh
Last active August 29, 2015 13:57
sh - close process on port
This `fuser 8080/` will print you PID of process bound on that port.
And this `fuser -k 8080/tcp` will kill that process.
Woks on Linux only. More universal is use of lsof -i4 (or 6 for IPv6).
@calvinchoy
calvinchoy / JS - Loading multiple js files async.js
Last active April 4, 2020 09:00
JS - Loading multiple js files async #jquery
$.when(
$.getScript( "/mypath/myscript1.js" ),
$.getScript( "/mypath/myscript2.js" ),
$.getScript( "/mypath/myscript3.js" ),
$.Deferred(function( deferred ){
$( deferred.resolve );
})
).done(function(){
//place your code here, the scripts are all loaded
@calvinchoy
calvinchoy / SH - CSR generation for ssl.md
Last active January 2, 2016 11:38
CSR generation for SSL

Generating a Certificate Signing Request

If you are purchasing your own security certificate, you will be asked to provide a Certificate Signing Request (CSR). To generate a CSR:

  1. Open an SSH session to your account.
  2. Enter openssl genrsa -out domain.key 2048, where domain is your domain, and press Enter. A new file, domain.key, is created.
  3. Enter openssl req -new -key domain.key -out domain.csr and press Enter. Several prompts for details about the certificate will appear. __When prompted for a Common Name, be sure to correctly enter the domain (or subdomain) for use with the __. When openssl is finished, the CSR file, domain.csr, is created.
  4. more domain.csr and press Enter. The contents of your CSR file will appear in the console.
  5. Copy and paste the contents of your CSR file to your certificate provider’s form.
@calvinchoy
calvinchoy / JS - Get load time.js
Last active April 4, 2020 08:37
[JS - Get load time] Get server performance load time using javascript
function getLoadTime() {
var now = new Date().getTime();
// Get the performance object
window.performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {};
var timing = performance.timing || {};
if (timing) {
var load_time = now - timing.navigationStart;
console.log('Load time: ' + load_time + 'ms');
}
@calvinchoy
calvinchoy / ruby gem fix macos.sh
Created November 22, 2013 08:21
Ruby gem update fix for MacOS
rvm get stable
rvm osx-ssl-certs update all
rvm rubygems latest
@calvinchoy
calvinchoy / Apple script - Fixes
Last active October 12, 2018 06:32
Apple config script codes
# Special chars on key hold
defaults write -g ApplePressAndHoldEnabled -bool false
defaults write -g ApplePressAndHoldEnabled -bool true
# fix webcam not found - resets iCam
sudo killall VDCAssistant
@calvinchoy
calvinchoy / PHP - JSONP Callback.php
Created August 16, 2013 09:17
PHP - JSONP Callback
//SERVER SIDE
<?php
$array_data = array();
$json_data = json_encode($array_data);
echo $_GET['callback'] . '(' . $json_data . ')';
?>
@calvinchoy
calvinchoy / PHP - excel to array helper function.php
Created June 20, 2013 08:46
PHP - excel to array helper function
<?php
/*
|--------------------------------------------------------------------------
| Excel To Array
|--------------------------------------------------------------------------
| Helper function to convert excel sheet to key value array
| Input: path to excel file, set wether excel first row are headers
| Dependencies: PHPExcel.php include needed
*/
function excelToArray($filePath, $header=true){