Skip to content

Instantly share code, notes, and snippets.

@naholyr
naholyr / function-argnames.js
Created February 19, 2012 18:30
JS Introspection: extract function parameter names
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(')') // ------^
);
@naholyr
naholyr / sftp.php
Created May 23, 2012 08:49
SFTP using SSH2 extension
<?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(