Skip to content

Instantly share code, notes, and snippets.

@jbnv
Created September 11, 2017 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbnv/3d3d4e7a7b789620b81140dbbec82bc8 to your computer and use it in GitHub Desktop.
Save jbnv/3d3d4e7a7b789620b81140dbbec82bc8 to your computer and use it in GitHub Desktop.
Atom Snippets
'.source.js':
'alert':
'prefix':'//a'
'body': """
//BEGIN TEMP
alert($1);
//END TEMP
"""
'console.log':
'prefix':'//c'
'body': """
//BEGIN TEMP
console.log($1);
//END TEMP
"""
'.source.php':
'null':
'prefix':'n'
'body':'null'
'true':
'prefix':'t'
'body':'true'
'false':
'prefix':'f'
'body':'false'
'this':
'prefix':'_'
'body':'$this->_'
'<>':
'prefix':'<>'
'body':'<? $1 ?>'
'<=':
'prefix':'<='
'body':'<?= $1 ?>'
'long divider':
'prefix':'////'
'body':'////////////////////////////////////////////////////////////////////////////////'
'short divider':
'prefix':'///'
'body':'///////////////////'
'exception':
'prefix':'exc'
'body':'throw new Exception(__CLASS__.\'::\'.__METHOD__.\'(\'.__LINE__.\'): \'."$1");'
'__construct':
'prefix':'_c'
'body': """
/**
* Constructor function for this class.
*
* @since
* @author Jay Bienvenu
* @link http://php.net/manual/en/language.oop5.decon.php
*
* @uses
*
* @param mixed ...
* @param type $var Description.
* @param type $var Optional. Description. Default.
*/
public function __construct($1) {
$2
}
"""
'__invoke':
'prefix':'_i'
'body': """
/**
* Function for calling this class object as a function. Call with $1().
*
* @since
* @author Jay Bienvenu
* @link http://php.net/manual/en/language.oop5.magic.php#object.invoke
*
* @uses
*
* @param mixed ...
* @param type $var Description.
* @param type $var Optional. Description. Default.
*/
public function __invoke($2) {
$3
}
"""
'__call':
'prefix':'_call'
'body': """
/**
* Triggered when invoking inaccessible methods in an object context.
*
* @since
* @author Jay Bienvenu
* @link http://php.net/manual/en/language.oop5.overloading.php#object.call
*
* @uses
*
* @param string $name Name of the method being called.
* @param array $arguments Enumerated array containing the parameters passed to the method.
*/
public function __call($name,$arguments) {
$1
}
"""
'__callStatic':
'prefix':'_calls'
'body': """
/**
* Triggered when invoking inaccessible methods in an static context.
*
* @since
* @author Jay Bienvenu
* @link http://php.net/manual/en/language.oop5.overloading.php#object.call
*
* @uses
*
* @param string $name Name of the method being called.
* @param array $arguments Enumerated array containing the parameters passed to the method.
*/
public function __callStatic($name,$arguments) {
$1
}
"""
'__toString':
'prefix':'_s'
'body': """
/**
* Function for treating this object like a string.
*
* @since
* @author Jay Bienvenu
* @link http://php.net/manual/en/language.oop5.magic.php#object.tostring
*
* @uses
*/
public function __toString($) {
$1
}
"""
'__get':
'prefix':'_get'
'body': """
/**
* Triggered when attempting to get an inaccessible property.
*
* @since
* @author Jay Bienvenu
* @link http://php.net/manual/en/language.oop5.overloading.php#object.get
*
* @uses
*
* @param string $name Name of the property being called.
*/
public function __get($name) {
$1
}
"""
'__set':
'prefix':'_set'
'body': """
/**
* Triggered when attempting to set an inaccessible property.
*
* @since
* @author Jay Bienvenu
* @link http://php.net/manual/en/language.oop5.overloading.php#object.set
*
* @uses
*
* @param string $name Name of the property being called.
* @param any $value Value being passed to the property.
*/
public function __set($name,$arguments) {
$1
}
"""
'if':
'prefix':'if'
'body':'if ($1) {$2} else {3}'
'file & line':
'prefix':'_fl'
'body': '__FILE__.\':\'.__LINE__'
'print_r_block':
'prefix':'printr'
'body': """
//BEGIN TEMP
<pre><? print_r($1); ?></pre>
//END TEMP
"""
'public function':
'prefix':'pf'
'body': """
/**
* Summary.
*
* Description.
*
* @since
* @author Jay Bienvenu
* @group fluent
*
* @uses
* @global type $varname Description.
* @see Cross-referenced element or website
*
* @param mixed ...
* @param type $var Description.
* @param type $var Optional. Description. Default.
* @return type Description.
* @return self
*/
public function $1($2) {
$this->check(''); // can except
$this->_ = ;
return $this;
}
"""
'public static function':
'prefix':'psf'
'body': """
/**
* Summary.
*
* Description.
*
* @since
* @author Jay Bienvenu
* @group
*
* @uses
* @global type $varname Description.
* @see Cross-referenced element or website
*
* @param mixed ...
* @param type $var Description.
* @param type $var Optional. Description. Default.
* @return type Description.
*/
public static function $1($2) {
return $3;
}
"""
'function':
'prefix':'fn'
'body': 'function $1($2) {$3}'
'func_num_args':
'prefix':'fna'
'body': 'if (func_num_args() == $1) {$2}'
'func_num_args':
'prefix':'fna0'
'body': 'if (func_num_args() == 0) return $1;'
'func_get_arg':
'prefix':'fa'
'body': 'func_get_arg($1)'
'func_get_args':
'prefix':'fas'
'body': 'func_get_args()'
'can except':
'prefix':'//x'
'body': '// can except'
'temp':
'prefix':'//t'
'body': """
//BEGIN TEMP
echo '['.__FILE__.':'.__LINE__.'] '.__METHOD__.'(): '.print_r($1,true)."\\\\n";
//END TEMP
"""
'temp (html)':
'prefix':'//th'
'body': """
//BEGIN TEMP
echo '<p>['.__FILE__.':'.__LINE__.'] '.__METHOD__.'(): <pre>'.print_r($1,true)."</pre></p>\\\\n";
//END TEMP
"""
'class':
'prefix':'class'
'body': """
//c
class $1 { $2 }
"""
'for count':
'prefix':'forc'
'body': 'for($i = 0; $i < $count; $i++) {$1}'
'for each method argument':
'prefix':'forarg'
'body': 'foreach (func_get_args() as $argument) {$1}'
'documentation block for file':
'prefix':'//file'
'body':"""
/**
* Defines the $1 class.
*
* @copyright COPYRIGHT
* @category
* @package
* @subpackage
*
* @since $2
* @author Jay Bienvenu
*/
"""
'documentation block for class':
'prefix':'//c'
'body':"""
/**
* $1.
*
* $2.
*
* @copyright COPYRIGHT
* @category
* @package
* @subpackage
*
* @since $3
* @author Jay Bienvenu
*/
"""
'documentation block for function':
'prefix':'//f'
'body':"""
/**
* INCOMPLETE Summary.
*
* INCOMPLETE Description.
*
* @since
* @author Jay Bienvenu
* @group fluent
*
* @uses func_get_arg
* @uses func_get_args
* @uses func_num_args
* @global type $varname Description.
* @see Cross-referenced element or website
*
* @param mixed ...
* @param type $var Description.
* @param type $var Optional. Description. Default.
* @return type Description.
* @return self
*/
"""
'add case':
'prefix':'addcase'
'body':'$data->addCase($1);'
'unit test function':
'prefix':'ut'
'body':"""
/**
* INCOMPLETE
* Tests class::yyy() with xxx.
* Tests class::yyy() against cases that should produce xxx.
*
* @testSubject class::yyy()
* @testObject A set of parameters to the method and an expected result.
*
* @since
* @author Jay Bienvenu
*
* @uses class::yyy()
* @uses self::assert()
*
* @covers class::yyy
* @group class
* @group class::yyy
* @dataProvider data
*
* @param array $arguments
* @param mixed $expected
*/
public function test$1($arguments,$expected)
{
$actual = call_user_func_array(class::class.'::yyy',$arguments);
$this->assertEquals($expected,$actual);
}
"""
'Property docblock':
'prefix':'//v'
'body':'/** @var $1 */'
'getX()':
'prefix':'get'
'body': """
/**
* Gets the value of $1.
*
* @since
* @author Jay Bienvenu
*
* @return mixed
*/
public function get$2() {$3}
"""
'setX()':
'prefix':'set'
'body': """
/**
* Sets the value of $1.
*
* @since
* @author Jay Bienvenu
*
* @param mixed $value
* @return self
*/
public function set$2($value) {
$3
return $this;
}
"""
'checkX()':
'prefix':'check'
'body': """
/**
* Checks that the given value is a valid $1.
*
* @since
* @author Jay Bienvenu
*
* @param mixed $value
* @return boolean
*/
public static function check$2(value) {
return $3;
}
"""
'validateX()':
'prefix':'validate'
'body': """
/**
* Checks that the given value is a valid $1.
*
* @since
* @author Jay Bienvenu
*
* @param mixed $value
* @return boolean
*/
public static function validate$2(value) {
return $3;
}
"""
'flatten':
'prefix':'flat'
'body':'$flat = array(); array_walk_recursive($source, function ($value,$key) use (&$flat) { $flat[$key] = $value; });'
'flatten function arguments':
'prefix':'flatarg'
'body':'$unflat_arguments = func_get_args();$arguments = array(); array_walk_recursive($unflat_arguments, function ($value,$key) use (&$arguments) { $arguments[key] = $value; });'
'walk':
'prefix':'walk'
'body':'array_walk_recursive($1, array($this,\'$2\'));'
'walk function arguments':
'prefix':'walkarg'
'body':'$args=func_get_args();array_walk_recursive($args, array($this,\'$1\'));'
'callable':
'prefix':'callable'
'body':'array($this,\'$1\')'
'call user function':
'prefix':'cufa'
'body':'call_user_func_array(array($this,\'$1\'),fas);'
'header for magic functions':
'prefix':'//magic'
'body':"""
////////////////////////////////////////////////////////////////////////////////
// Magic functions
// Alphabetize all functions in this section.
"""
'header for public functions':
'prefix':'//public'
'body':"""
////////////////////////////////////////////////////////////////////////////////
// Public methods
// Alphabetize all functions in this section.
"""
'skip test':
'prefix':'skip'
'body':"""
//BEGIN TEMP
$this->markTestSkipped('Skipped for debugging.');
//END TEMP
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment