Skip to content

Instantly share code, notes, and snippets.

View kiyanwang's full-sized avatar

Nadeem Shabir kiyanwang

View GitHub Profile
@kiyanwang
kiyanwang / test-bash-dialog.sh
Last active October 9, 2017 07:17
script to test bash dialog command
#!/bin/sh
# script to test bash dialog command
# creates a simple cli app that can view or edit a file containing key value
# pairs in the form
# <key>:<value>
file='./conf.txt'
tempfile1=/tmp/dialog_1_$$
tempfile2=/tmp/dialog_2_$$
@kiyanwang
kiyanwang / print-collection-counts.js
Created March 22, 2016 15:28
Mongo: Print count of the number of documents in each collection in a database.
// Usage: mongo localhost}/{DbName} [-u {Username}] [-p {Password}] < ./print-collection-counts.js.j
var collections = db.getCollectionNames();
print('Collections:');
for(var i = 0; i < collections.length; i++){
var name = collections[i];
if(name.substr(0, 6) != 'system')
print("\t" + name + ": " + db[name].count());
#!/bin/bash
# checks if an array contains the specified element
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
REPO="git@github.com:USER/YOUR_PUPPET_REPO"
@kiyanwang
kiyanwang / copys3files.sh
Last active December 22, 2015 15:28
Copy all files from a S3 bucket/folder to another S3 bucket/folder
s3cmd ls s3://sourcebucket/sourcefolder/ | awk '{ print $4 }' | tail -n +2 | sed -e 's!^s3://sourcebucket/sourcefolder/\([a-z0-9\_\.]*\)!s3cmd cp s3://sourcebucket/sourcefolder/\1 s3://targetbucket/targetfolder/\1!g' | bash
@kiyanwang
kiyanwang / test.html
Created July 8, 2012 10:24
Html file calls jsonp node service
<html>
<head>
<title>jsonp test</title>
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(function(){
$('#testlink').click(function(e){
e.preventDefault();
var url = 'http://localhost:3000/foo?cb=?';
@kiyanwang
kiyanwang / app.js
Created July 8, 2012 10:10
nodejs + express with jsonp support
var express = require('express');
var app = module.exports = express.createServer();
// this enables jsonp support
app.enable("jsonp callback");
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());