Skip to content

Instantly share code, notes, and snippets.

View shamalroy's full-sized avatar
🐈

Shamal Roy shamalroy

🐈
View GitHub Profile
@shamalroy
shamalroy / 0_reuse_code.js
Last active September 17, 2015 14:32
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@shamalroy
shamalroy / gist:daeb49bc0a7256334eb9
Created August 15, 2015 01:44
MongoDB find documents
db.myCollection.find({ "name": "Manhattan" })
db.myCollection.find({ "detail.age": 25 })
db.myCollection.find({ "detail.age": { $lt: 60 }})
db.myCollection.find({ $or: [{"name": "My Name"}, {"detail.age": 25 } ]})
@shamalroy
shamalroy / gist:d09f13938f660cc99727
Created August 15, 2015 01:43
MongoDB insert update save
db.myCollection.insert({name:"My Name", password : "abc"})
db.myCollection.save({_id: "123", name:"My Name", password : "abc"})
db.myCollection.update(
{"name" : "My Name" },
{$set: { "password": "123" }}
)
@shamalroy
shamalroy / gist:0c1977acfcdbc0ee6c61
Created August 15, 2015 01:40
MongoDB create user
use myDB
db.createUser(
{
user: "userName",
pwd: "abc123",
roles: ["readWrite"]
}
)
@shamalroy
shamalroy / PatriciaTrieExample
Last active April 30, 2021 06:03
Patricia Trie Example
import java.util.*;
import org.apache.commons.collections4.Trie;
import org.apache.commons.collections4.trie.PatriciaTrie;
...
...
Map<String, BookInfo> library = new LinkedHashMap<>();
/* Load your regualr map with data */
library.put("To Kill a Mockingbird", new BookInfo("Harper Lee", "978-0061120084"));
libraby.put("Pride and Prejudice", new BookInfo("Jane Austen", "978-0679783268"));
libraby.put("To Kill A Warlock", new BookInfo("H.P. Mallory", "978-xxxxxxxx"));
@shamalroy
shamalroy / profile_page.jsp
Last active August 29, 2015 14:11
AEM (Adobe CQ) XSSAPI example in JSP
<%@ include file="/libs/foundation/global.jsp" %>
<%
String siteTitle = request.getParameter("siteTitle");
String websiteLink = request.getParameter("websiteLink");
%>
<html>
<head>
<title>
<%= xssAPI.encodeForHTML(siteTitle); %>
</title>
@shamalroy
shamalroy / UserComment.java
Last active November 10, 2017 23:31
AEM (Adobe CQ) XSSAPI usage example in Java class
import com.adobe.granite.xss.XSSAPI;
import org.apache.sling.api.resource.ResourceResolver;
public class UserComment {
public String getFilteredComment(ResourceResolver resourceResolver, String commentTxt) {
XSSAPI xssAPI = resourceResolver.adaptTo(XSSAPI.Class);
return xssAPI.getValidHref(commentTxt);
}
}
CREATE TABLE IF NOT EXISTS `continents` (
`code` CHAR(2) NOT NULL COMMENT 'Continent code',
`name` VARCHAR(255),
PRIMARY KEY (`code`)
) ENGINE=InnoDB;
INSERT INTO `continents` VALUES
('AF', 'Africa'),
('AS', 'Asia'),
('EU', 'Europe'),
@shamalroy
shamalroy / gist:ed70ef1662858e9c7b2e
Created March 27, 2012 18:52
Showing git branch name on terminal
# From http://railstips.org/blog/archives/2009/02/02/bedazzle-your-bash-prompt-with-git-info/
# Add this on bashrc file
# Git branch display with color
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "(ⓖ "${ref#refs/heads/}")"
}
BLUE="\[\033[1;34m\]"
RED="\[\033[0;31m\]"
@shamalroy
shamalroy / git-resources.txt
Created November 8, 2011 14:24 — forked from glennansley/git-resources.txt
Helpful Git Resources
These are some helpful Git resources that I found while climbing the learning curve.
Feel free to append / modify
=======================
== UNDERSTANDING GIT ==
=======================
* The Git Parable
- http://tom.preston-werner.com/2009/05/19/the-git-parable.html
- "Read this parable all the way through and you should have very little trouble mastering the various Git commands and wielding the awesome power that Git makes available to you."