Gabrielyan
Gabrielyan
Reputation Top 5%
Sergo Gabrielyan
2 Snippets
Published
1 Channel
Created
1 Channel
Following
57 points
Reputation
Junior Code Generator
Junior Publisher
Junior Trend Maker
Junior Judge
Junior Popular Coder
Junior Autobiographer
Master Autobiographer
Junior Famous Coder

Recent Snippets See all snippets by Gabrielyan

public by Gabrielyan  2056  0  6  1

Quick link checker with CasperJS

casper = require("casper").create()
errors = []

errorHandler = (url, status, msg)->
    errors.push {url: url, status: status, msg: msg}; 


if casper.cli.has(0)
    url = casper.cli.get(0)
else 
    casper.echo "Missing url argument", "ERROR"
    casper.exit()

#----------------------------------------------------

casper.start url, (res)->  
    if not res.status or res.status isnt 200 
        errorHandler(url, res.status, res.statusText or 'Something Wrong')
        
    links = @getElementsAttribute('a', 'href')
    
    links = links.filter (link)-> # if need...
        link isnt '#'
        
    @each links, (self, link) ->
        self.thenOpen link, (res) ->
            if res.status and res.status is 200
                @echo "#{link} - #{res.status} #{res.statusText}", 'INFO'
            else
                errors.push {url: link, status: res.status, msg: res.statusText}
    
.run ->
    if errors.length > 0
        @echo "Errors: #{errors.length}"
        for error in errors 
            @echo "url: #{error.url},  status: #{error.status},  msg: #{error.msg}", 'ERROR'
    else 
        @echo "All Done!", "INFO"
            
    @exit()
;

public by  2365  0  5  2

Simple NodeJS Server

var http = require('http'); 

var s = http.createServer(function(req, res){
  res.writeHead(200, {"Content-Type":"text/plain"}); 
  res.write('Hello, Snip2Code!');
}); 

s.listen(3000, function(){
  console.log("App run on 3000..."); 
}); 
;