Skip to content

Commit

Permalink
fix css_block
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcWeber committed Oct 12, 2013
1 parent b4c26c4 commit 6a38707
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 5 deletions.
8 changes: 3 additions & 5 deletions snippets/html_minimal.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@ snippet img
snippet css_file
<link rel="stylesheet" href="${1:style.css}" type="text/css" media="${2:all}">
snippet css_block
<link rel="stylesheet" href="${1:style.css}" type="text/css" media="${0:all}">
</link>

<style type='text/css'>
</style>
snippet script_block
<script type="text/javascript" charset="utf-8">
</script>
snippet script_file
<script type="text/javascript" charset="utf-8">
</script>
<script src="${1}" type="text/javascript"></script>
145 changes: 145 additions & 0 deletions snippets/php.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ snippet if
if (${1:/* condition */}) {
${0}
}
snippet ifn
if (!${1:/* condition */}) {
${2}
}
snippet ifil
<?php if (${1:/* condition */}): ?>
${0}
Expand Down Expand Up @@ -412,3 +416,144 @@ snippet static_var
if (is_null($$1)){
$$1 = ${2};
}

snippet CSVWriter
<?php

class CSVWriter {
public function __construct($file_or_handle, $sep = "\t", $quot = '"'){
$args = func_get_args();
$mode = isset($opts['mode']) ? $opts['mode'] : 'w';

$this->f =
is_string($file_or_handle)
? fopen($file_or_handle, $mode)
: $file_or_handle;

$this->fputcsv_args = array($this->f, null, $sep, $quot);

if (!$this->f) throw new Exception('bad file descriptor');
}

public function write($row){
$this->fputcsv_args[1] =& $row;
call_user_func_array('fputcsv', $this->fputcsv_args);
}

public function close(){
if (!is_null($this->f))
fclose($this->f);
$this->f = null;
}

public function __destruct(){
$this->close();
}

}

snippet CSVIterator

// http://snipplr.com/view.php?codeview&id=1986 // modified
class CSVIterator implements Iterator
{
private $f;
private $curr;
private $rowCounter;

/* opts keys:
* row_size
* escape
* enclosure
* delimiter
*/
public function __construct( $file_or_handle, $opts = array(4096, ',') )
{
$d = function($n) use(&$opts){ return isset($opts[$n]) ? $opts[$n] : false; };

$this->combine = $d('combine');
$this->headers = $d('headers');
$this->headerCheckFunction = $d('header_check_function');

$this->f =
is_string($file_or_handle)
? fopen( $file_or_handle, 'r' )
: $file_or_handle;
if (!$this->f) throw new Exception('bad file descriptor');
$this->fgetcsv_args = array(
$this->f,
isset($opts['row_size']) ? $opts['row_size'] : 4096,
isset($opts['delimiter']) ? $opts['delimiter'] : ',',
isset($opts['enclosure']) ? $opts['enclosure'] : '"',
isset($opts['escape']) ? $opts['escape'] : '\\',
);
$this->start();
}

protected function readRow(){
$this->curr = call_user_func_array('fgetcsv', $this->fgetcsv_args );
$this->rowCounter++;
if ($this->rowCounter == 1){
$this->processHeader();
} elseif ($this->curr) {
$this->processRow();
}
}

public function processHeader(){
if ($this->headers || $this->combine){
$this->header = $this->curr;
if ($this->headerCheckFunction){
$f = $this->headerCheckFunction;
$f($this->header);
}
$this->readRow();
}
}

public function processRow(){
if ($this->combine)
$this->curr = array_combine($this->header, $this->curr);
}

public function start(){
$this->rowCounter = 0;
rewind( $this->f );
$this->readRow();
}

public function rewind()
{
$this->start();
}

public function current()
{
$curr = $this->curr;
$this->readRow();
return $curr;
}

public function key()
{
return $this->rowCounter;
}

public function next()
{
return $this->curr;
}

public function valid(){
if( !$this->next() )
{
fclose( $this->f );
return FALSE;
}
return TRUE;
}

} // end class

snippet is
isset($1{VISUAL})
6 changes: 6 additions & 0 deletions snippets/ruby.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ snippet deft
def test_${1:case_name}
${0}
end
snippets descendants
class Class
def descendants
ObjectSpace.each_object(::Class).select {|klass| klass < self }
end
end
snippet if
if ${1:condition}
${0}
Expand Down

0 comments on commit 6a38707

Please sign in to comment.