Skip to content

Instantly share code, notes, and snippets.

@shaosh
shaosh / getUrlParams.js
Created August 23, 2017 16:54
Para query strings in the url
function getUrlParams() {
var result = {};
var params = (window.location.search.split('?')[1] || '').split('&');
for(var param in params) {
if (params.hasOwnProperty(param)) {
paramParts = params[param].split('=');
result[paramParts[0]] = decodeURIComponent(paramParts[1] || "");
}
}
return result;
@shaosh
shaosh / setXhrAuthHeader.js
Created May 23, 2017 01:04
Javascript to set the auth header
var req = new XMLHttpRequest()
req.open('get', 'https://127.0.0.1:8181/Shopper/949244', true)
req.setRequestHeader('Authorization', 'sso-jwt ' + 'eyJhbGciOiAiUlMyNTYiLCAia2lkIjogIkVqaTVfc01yaVEifQ.eyJhdXRoIjogImJhc2ljIiwgImZhY3RvcnMiOiB7ImtfcHciOiAxNDk1MjM5ODUwfSwgImZpcnN0bmFtZSI6ICJTaGlodWFuIiwgImZ0YyI6IDEsICJoYmkiOiAxNDk1MjM5ODUwLCAiaWF0IjogMTQ5NTIzOTg1MCwgImp0aSI6ICJQSkt3QWI4cC0wN01HVFdwWFVBUV9RIiwgImxhc3RuYW1lIjogIlNoYW8iLCAicGVyIjogdHJ1ZSwgInBsaWQiOiAiMSIsICJzaG9wcGVySWQiOiAiOTQ5MjQ0IiwgInR5cCI6ICJpZHAiLCAidXNlcm5hbWUiOiAic3NoYW8ifQ.BS8kjmbb7e5lDT4XlEI5i2ji_myQsKv6yuO-R6qBamwycCNo6DVu7DwzCkY5RIcRug-I3l7VxHOMDaZIZrAvV9hpoU8OCWWhCZZ_kawGIFX6RUA06seUXdrt-ZFn5n939t0l7PxBNESd11RS_qTAdiSz-7EjOPIo6lCdyF42F28')
req.send()
@shaosh
shaosh / Bash script to setup aliyun
Last active February 8, 2017 22:42
logstashInAliyun.sh
#https://www.v2ex.com/t/331412
#Remember to go to /etc/apt/apt.conf to comment Acquire::http::Proxy "http://mirrors.aliyun.com/";
sudo /etc/apt/apt.conf
sudo touch /etc/apt/apt.conf
#Install nodejs
curl -sL http://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
#Install redis
@shaosh
shaosh / underscoreToCamelCase.cs
Created October 7, 2016 00:39
C# code to convert underscore name to camelcase
private string underscoreToCamelCase(string name)
{
if (string.IsNullOrEmpty(name) || !name.Contains("_"))
{
return name;
}
string[] array = name.Split('_');
for(int i = 0; i < array.Length; i++)
{
string s = array[i];
@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');
}
@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 / 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 / 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 / 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 / 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"
}
}