This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// getting an event's target | |
function getElementByEvent(event){ | |
console.log(event.target); | |
} | |
// get the target | |
var element = document.getElementsByClassName('element')[0]; | |
//adding event listener to target | |
element.addEventListener('click', function(event){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var newHTML = [ | |
'<div class="foo">', | |
'<p>Readable HTML in JavaScript.</p>', | |
'</div>' | |
].join(''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'), | |
jade = require('gulp-jade'), | |
data = require('gulp-data'), | |
fs = require('fs'); | |
gulp.task('jade', function(){ | |
return gulp.src('src/jade/*.jade') | |
.pipe(data( function(file) { | |
return JSON.parse(fs.readFileSync('src/data.json')); | |
} )) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).keyup(function(e) { //keydown can be used as well. | |
switch(e.which) { | |
case 37: //left; any keycode can be used for each case. | |
alert('keycode: '+e.which); | |
break; | |
default: return; // exit this handler for other keys | |
} | |
e.preventDefault(); // prevent the default action (scroll / move caret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
exec("$command 2>&1 &", $output); | |
foreach ($output as $line) { | |
echo "$line\n"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simple tag getting fn | |
var getTag = function(tag){ | |
return document.getElementsByTagName(tag); | |
} | |
// wanted: elements we want to get by tag. | |
// caught: tags caught; where we will put the wanted elements, if they exist. | |
// missing: if tag not present in document, list here. | |
var textCatcher = { | |
wanted : ['p','ul','ol','li','a','span','strong','i','b','h1','h2','h3','h4','h5','h6'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
util = require('util'), | |
exec = require('child_process').exec, | |
json = JSON.parse(fs.readFileSync('data.json')); | |
function puts(error, stdout, stderr){console.log(stdout, stderr)} | |
for (var i in json.array){ | |
exec('echo '+json.array[i], puts); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# concat.sh | |
cat \ | |
file1 \ | |
file3 \ | |
> file3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
read input; | |
while true; do clear; $input; sleep 2; clear; done; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
read input; | |
git add .; git commit -m "$input"; git push; |
OlderNewer