Skip to content

Instantly share code, notes, and snippets.

@shaosh
shaosh / gist:40cb2db191d6dc755251
Created September 16, 2014 18:30
Batch Script to Create files and folders
if not exist "reports\" (mkdir reports)
cd reports
if exist report.xml (
del "report.xml"
)
type nul >report.xml
echo ^<?xml version="1.0" encoding="UTF-8"?> >> report.xml
@shaosh
shaosh / HtmlParser
Created January 21, 2015 17:05
Simple HTML Parser
function HtmlParser(){}
function Stack(){
this.stac = [];
this.pop = function(){
return this.stac.pop();
};
this.push = function(item){
this.stac.push(item);
};
this.peek = function(){
@shaosh
shaosh / gist:0e159b9db3dc90b8c719
Last active March 17, 2016 23:53
Remove dash and capitalize the first letter
var a = document.getElementByTagName('view')
for(var i = 0; i < a.length; i++){
var b = a[i].id;
c = b.split('-');
for(var j = 0; j < c.length; j++){
c[j] = c[j].replace(/^./, c[j][0].toUpperCase());
}
var d = c.join('');
console.log(d)
@shaosh
shaosh / Gruntfile.js
Created November 18, 2015 18:57
Gruntfile.js of Grunt template
module.exports = function(grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json')
});
grunt.registerTask('default', []);
};
@shaosh
shaosh / package.json
Created November 18, 2015 18:58
package.json of Grunt template
{
"name": "",
"version": "0.1.0",
"author": "Shihuan Shao",
"devDependencies": {
"grunt": "~0.4.1",
"matchdep": "^1.0.0"
}
}
@shaosh
shaosh / logstash.conf
Last active December 1, 2015 23:07
logstash.conf file to log IIS errors in ELK
#############
# Support multiple xml files
#############
input
{
file{
path => ["C:/inetpub/logs/FailedReqLogFiles/*/*.xml"]
start_position => "beginning"
# filter is not thread safe, so have to move the multiline into the input
codec => multiline{
@shaosh
shaosh / script.js
Last active March 17, 2016 23:31
Extract int keys and output in one line with comma
var c = [{'32059': 'true'}, {'32074': 'true'}, {'32062': 'true'}, {'32065': 'true'}, {'32068': 'true'}, {'32071': 'true'}];
var keys = [];
for(var k in c){
var a = c[k];
keys.push(parseInt((Object.keys(a))[0]));
}
keys.join(", ")
@shaosh
shaosh / processPfids.js
Created March 24, 2016 01:24
Read multiple lines from a textfile and put each into an array
var fs = require('fs');
function readLines(input, func){
var remaining = '';
var array = [];
input.on('data', function(data){
remaining += data;
var index = remaining.indexOf('\n');
while(index > -1){
var line = remaining.substring(0, index);
@shaosh
shaosh / sapiPost.js
Created June 24, 2016 17:28
Call Sales API to load workspace
$.ajax({
type:"POST",
url: "https://salesproducts.api.test-godaddy.com/v1/pl/1/cart/packages",
contentType: "application/json",
data: "requestData=" + JSON.stringify({
pkgid: "office365migration_tier3_012mo",
qty: 1,
itc: "eml_365_workspace",
ci: "86495"
}),
@shaosh
shaosh / autofill.js
Created September 23, 2016 21:11
Dynamically turn autofill on and off
$('#addrBox').on('mouseup keyup', function(){
var $this = $(this);
var val = $this.val();
val = val.length;
if(val === 0){
$this.attr('autocomplete', 'on');
}
else{
$this.attr('autocomplete', 'off');
}