Skip to content

Instantly share code, notes, and snippets.

View smbanaie's full-sized avatar

S.Mojtaba Banaie smbanaie

View GitHub Profile
@smbanaie
smbanaie / MongoSnippets
Last active August 29, 2015 14:05
Mongo Usefull Commands
# Add One Field to all documents
db.RssLink.update({}, {$set: {"type": "normal"}}, false#upsert#, true#multi#)
#simple Search
db.RssLink.find({run_time :{"$gt":180}})
@smbanaie
smbanaie / elasticsearch-aggregation-sample
Last active August 29, 2015 14:04
elasticsearch aggregation sample
{
"aggregations": {
"remax_stats" : {
"filter" : { "range" : { "RE" : { "gt" : 100 } } },
aggregations : {
"stat_re" : {"stats" : { "field" : "RE" }}
}
},
"cat_stat": {"terms": {"field": "category"}}
},
@smbanaie
smbanaie / ExportToCSV-Mongo
Last active August 29, 2015 14:04
Export One Collection in Mongo to CSV
OIFS=$IFS;
IFS=",";
# fill in your details here
dbname="dbname"
user="username"
pass="pass"
host="127.0.0.1:27017"
collections=`mongo "$host/$dbname" -u $user -p $pass --eval "rs.slaveOk();db.getCollectionNames();"`;
@smbanaie
smbanaie / BooleanQuery
Created July 22, 2014 21:32
Elastic Search Boolean Query
{
"from" : 0, "size" : 30,
"sort" : [ { "RE" : {"order" : "desc"}},"_score"],
"query": {
"simple_query_string" : {
"query" : "(+iran && +obama) || (+moore && +iran) || (+u.s. && +iran)",
@smbanaie
smbanaie / Python Useful Code Snippet
Last active August 29, 2015 14:04
Python Useful Code Snippet
##Add File Logger
import logging
logger = logging.getLogger('myapp')
hdlr = logging.FileHandler('/var/tmp/myapp.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.WARNING)
We can use this logger object now to write entries to the log file:
@smbanaie
smbanaie / PythonTips
Last active August 29, 2015 14:03
Some Python Code Imrovement TIPS
TIP #1 : Check Membership Efficiently
lyrics_list = ['her', 'name', 'is', 'rio']
# Avoid this
words = make_wordlist() # Pretend this returns many words that we want to test
for word in words:
if word in lyrics_list: # Linear time
print word, "is in the lyrics"
@smbanaie
smbanaie / Git Essential Command
Created June 8, 2014 13:03
Git Essential Command
git reset --hard <old-commit-id>
git push -f
@smbanaie
smbanaie / GPlus- Facebook _ Linkedin Sign
Created June 7, 2014 11:31
GPlus- Facebook _ Linkedin Sign in Process
1. in Google Developer Console , https://console.developers.google.com/ , create project -> create new Client ID in Credential Link at left sidebar
2.
@smbanaie
smbanaie / LinuxUsefullResources
Last active August 29, 2015 14:02
Some Usefull Linux Resources - DNS Settings
1.Setup a dns server in ubuntu : http://www.servermom.org/how-to-install-and-setup-bind9-on-ubuntu-server/136/
{
"from" : 0, "size" : 20,
"sort" : [ { "RE" : {"order" : "desc"}}],
"query": {
"filtered": {
"query" : {
"query_string" : {