Skip to content

Instantly share code, notes, and snippets.

@naholyr
naholyr / sftp.php
Created May 23, 2012
SFTP using SSH2 extension
View sftp.php
<?php
// Connect to sftp server
function sftp_connect(array $config)
{
if (!function_exists('ssh2_connect')) {
throw new Exception('Extension SSH2 not installed: check server configuration');
}
$options = array_merge(array(
@naholyr
naholyr / function-argnames.js
Created Feb 19, 2012
JS Introspection: extract function parameter names
View function-argnames.js
Function.prototype.argNames = function () {
// Extract function string representation: hopefully we can count on it ?
var s = this.toString();
// The cool thing is: this can only be a syntactically valid function declaration
s = s // "function name (a, b, c) { body }"
.substring( // "a, b, c"
s.indexOf('(')+1, // ----------------^
s.indexOf(')') // ------^
);