Search This Blog

Sunday, December 25, 2011

PostgreSql change password command line


Awww yeah... If we can't remember your postgres db password, we can reset it.

Ubuntu
First we have to switch to postgres user


su - postgres


now we can execute the psql command


psql -d dbname -U postgres; (this allows you to get it o the db)


alter user postgres with password 'newpassword'; (now you can modify the password)

Monday, December 5, 2011

Git Hub: Undo Commit and Push

Git Hub: Undo Commit and Push

Some times we commit undesirable changes to out local repository, and unfortunately on some rare occasions we actually push the undesirable change to remote repository( quick hands :) ). So we would need to undo the commit and push.
Scenario below has the following setup.

* Master branch, branch A, branch B.
* Both branch A and B came from master and they are focusing on totally different things. Neither of them are ready to be committed to master.

1) Mistake: branch B decides to commit to its remote repository but mistakenly committed to branch A's remote repository. Now Branch A is messed up and needs to be reverted.

solution:
step 1, checkout branch A locally.
step 2, revert local repository of branch A to the version right before the bad commit and push using the following command.

git reset --hard 9ab122edde

this tag 9ab122edde refers to the hash of the version right before the commit. every commit has one, so no need for me to go about where to find this guy.

step 3, now the local repository of branch A is back to normal and we should push it to its remote repository.

git push origin +branchA

Done!

PS .... to remove a remote branch, do the following.

git push origin :branchName









Thursday, October 13, 2011

Solr 3.x and Tomcat setup tutorial

There is a good tutorial on solr's official site on Solr with jetty but I wouldn't find a good instruction on Solr with Tomat setup thats clean and easy. So here is my instruction.

1. download solr ( we are at version 3.x.x)
2. extra files    (tar -zxvf apache.solr.blabla.tar)
3. create solrHome folder
4. go to the upzipped solr directory and copy dist/apache.solr.3.x.x.war to solrHome
5. rename that file in solrHome from apache.solr.3.x.x.war to solr.war
6. download tomcat and modify server.xml as in 7
7.       <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
                <Context docBase="/home/ec2-user/sandbox/solrHome/solr.war" path="/solr" reloadable="true" unpackWAR="false">
                        <Environment name="solr/home" type="java.lang.String" value="/home/ec2-user/sandbox/solrHome/" override="true" />
                </Context>

      </Host>
8. copy folders and files below  to solrHome folder also make a folder name "data" too.
conf, example, exampledocs, start.jar
these things can be found in the solr distribution tar file downloaded.

9. test solr.
go to http://localhost:8983/solr/admin/
make sure server is up and running.

10. index the monitor data 
-data are in xml format, if we want to add more data, modify the solrconfig and schema.xml files
-to fit the new data format. this is actually very simple.

cd /home/ec2-user/sandbox/solrHome/exampledocs
user:~/solr/example/exampledocs$ java -jar post.jar solr.xml monitor.xml
make sure not error from catalina.out.

11.
http://localhost:8983/solr/browse
check interface. play with it, click it. no error.

12
index all data.
java -jar post.jar *.xml

13
http://localhost:8983/solr/browse
check interface. play with it, click it. no error. more data.

------------------
command to delete all index

java -Ddata=args -Dcommit=no -jar post.jar "<delete><query>*:*</query></delete>"

java -Ddata=args -Dcommit=no -jar post.jar "<commit/>"

java -Ddata=args -Dcommit=no -jar post.jar "<optimize/>"
---------------------

Monday, October 10, 2011

OutOfMemoryError Intellij - Tomcat

Dealing with “OutOfMemoryError” in “PermGen space”.  IntelliJ - tomcat

from the IntelliJ tool bar do the following

1. run --> edit configuration
2. select tomcat server and press the + button from the right hand panel to create tomcat instance.
3. edit vm parameter   add    -XX:MaxPermSize=512m
4. edit and configure other stuff related to your project then click "apply"
done

Saturday, October 8, 2011

Install JDK 7 on ubuntu 11

Install JDK 7 on ubuntu 11

1. download jdk binary from
http://www.oracle.com/technetwork/java/javase/downloads/index.html

2. unzip the file (assume that the file was downloaded and saved under /home/merlin/Downloads/)

3. move the unzipped folder to /usr/lib/jvm
sudo mv /home/merlin/Downloads/jdk1.7.0/ /usr/lib/jvm/jdk1.7.0

4. find out how many jdk has been installed in the system.
sudo update-alternatives --config java

my system only had java6 installed, so the out put looks like this.

There is only one alternative in link group java: /usr/lib/jvm/java-6-openjdk/jre/bin/java
Nothing to configure.

5.  since i only had 1 installed, i'm going to install number 2 so i can pick from a list of them.
sudo update-alternatives --install /usr/bin/java java  /usr/lib/jvm/jdk1.7.0/jre/bin/java 2

-- the final number of the command is 2 meaning i'm installing second java version. if you want to install 3rd, or 4th or 5th, then the number should change accordingly eg 3, 4 or 5


6. pick your java version
sudo update-alternatives --config java

--out put from the console below


  Selection    Path                                      Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/jdk1.7.0/jre/bin/java         2         manual mode

0 indicates the version in use.

all you have to do now is type the number you wish to pick and hit enter

2    --- type 2 and press enter



7. test your java version

java -version

output below

java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)



done








Tuesday, September 13, 2011

iptables firewall commands


#to allow access to server with iptables
iptables -A INPUT -s 192.111.111.111 -j ACCEPT
service iptables save

#tp remove access to server with iptables
iptables -A INPUT -s 192.111.111.111 -j DROP
service iptables save


//to list properties of iptables and show allowed ip is added
iptables -L

Friday, September 2, 2011

Mantis and mysql

modifying mantis user data from command line

1. find the mantis config file    
locate config_inc.php

2. connect to the db
mysql -u username -h hostname -p


3. switch to the mantis database
use mantisdb;

4. locate the table that holds users.
show tables;

5. check table content.
select * from mantis_user_table;


6. do what ever you want to a user!
update!!!! update!!! update!!!

mantis with ldap


$g_roadmap_view_threshold = 50;

# --- Database Configuration ---
$g_hostname      = "localhost";
$g_db_username   = "mantis";
$g_db_password   = "dont know";
$g_database_name = "mantis_db";
$g_db_type       = "mysql";

# --- Anonymous Access / Signup ---
$g_allow_signup                         = OFF;
$g_allow_anonymous_login        = OFF;
$g_anonymous_account            = OFF;

# --- LDAP Access / Sign-in ---
$g_login_method = LDAP;
$g_ldap_server = 'ldap://10.1.10.30';
$g_ldap_root_dn = 'ou=Users,ou=my company name,dc=mydomain,dc=com';
$g_ldap_bind_dn = 'mydomain\admin';
$g_ldap_bind_passwd = 'nottellingyou';
$g_use_ldap_email = ON;
$g_ldap_protocol_version = 3;
$g_ldap_uid_field= 'sAMAccountName';

Thursday, September 1, 2011

reset Mac os admin account without boot disk

  1.  Reboot the machine.
  2. Hold command + s 
  3. Time to get to command line as root and type the following command---->
    mount -uw /
    rm /var/db/.AppleSetupDone
    shutdown -h now

Friday, March 18, 2011

DBSight - combining levenshtin distance and double metaphone

My attempt to make "lastname" search friendly to users.

Decision: Use DBSight, utilize multiple analyzers: numberOrLowerCase, Double Metaphone.

Problem:
People don't spell names correctly all the time, for example, I'm trying to search for 'picasso', but i decided to misspell it as for 'picaso' (with a missing s). From the search result, 'Bachs' alone with a bunch of other names showed up with the same score as 'picasso'. But to have 'picasso' show up on the top of the list is what I want to achieve. So, I'm thinking, if i can put levenshtin distance in there and assign it with a higher score, then i might be able to solve this problem.(configure search --> searchable columns)




Solution:
lastNameT is for text search, so when i type in "picasso" the correct spelling, the exact spelling  shows up on the top. This field is also use for Stemming or Levenshtin distance, so that words that spells similarly will weight more than the phonetic matches. if i only use phonetic, names with similar sounds will show up with the same score.
lastNameP is the phonetic one.


so here is my setup:

lastNameT, lastNameP all hold the same value, and they are only differ in analyzer and weight. to achieve this, i did the following.

1. getData
Data Source->select data->sql

----------------------------------------
select id, 
lastName as lastNameT,
lastName as lastNameP
from mytable


------------------------------------------------------

1.2 i have my id as primary key and and the names are text fieldTypes


2. adjust analyzer
Data source -> language
change the analyzer setting for lastNameT, lastNameP to numberOrLowerCase, Double Metaphone respectively.


3. enable spellcheck (it's really nice to have)
Data source -> spell check
check the checkbox on lastNameT
check the checkbox on "use index-specific" spell checking. (using regular dictionary to correct my spelling of a person's last name wouldn't make too much sense since i would only be interested in what my database has to offer)


4. adjust weight (depending on needs)
fieldName       type         FieldType        Analyzer                       weight
lastNameT     String           text          numberOrLowerCase            2.0
lastNameP     String           text          Double Metaphone               1.0

5. enable wild card search(optional)
 configure search -> wild-card
this part is very self explanatory.

make a template and when you type in 'picaso' in the search box, hit enter and then add &lq=lastnameT:picaso~0.4 to the end of the url.

there u have it! picasso on top of the list!

because i don't want to modify the URL at the address bar every time when i do a search, i did the following modification to the template so that it captures the lq parameter and fires it off with the form submit.

6.  create and modify display template.
  display template -> create from scaffold 
 6.2 create a display template.(i used client side sortable table)
 6.3 modify template.
display template -> list
      click on the template name and locate searchBox.ftl and add the following java script to the end of the file.
--------------------------------------------------------
<script>
function populateLQ() {
  var newtext = document.search_demo.q.value;
    document.search_demo.lq.value ='lastNameT:'+newtext+'~0.4';
}
</script>
--------------------------------------------------------
Note1: line 3:document.search_demo.q.value must be modified to match the name of your index. eg. document.search_myNameIndex.q.value;
Note2: notice the ~0.4, that's what i use, because i think 0.4 is close enough.

add a hidden field
<input type="hidden" name="lq" id="lq" value="">

modify the input text field of search box
From
<input type="text" name="q" id="q" size="41" maxlength="2048" value="${searchResult.userInput?html}">&nbsp;
To:
<input type="text" name="q" id="q" size="41" maxlength="2048" value="${searchResult.userInput?html}" onchange="populateLQ();">&nbsp;

this way the input also modifies the hidden field that will be passed for search.

Done!

After thoughts:
I later created another index that searches the combination of first name and last name by concatenating the first name and last name separated by a space and added auto complete from partial scaffold->"search suggestion". which is much more user friendly.

I'm sure there are many other ways of doing this and much better ways too. So please share your criticisms, thoughts or what ever you have in mind.

thanks Paul, Will. (DBSight is awesome!)

Check out their wiki for more info

http://wiki.dbsight.com/index.php?title=Exact_Search_plus_fuzzy_double_Metaphone_search

Monday, February 21, 2011

Fedora 14 and Eclipse Helio

I'm a noob when it comes to Linux operating systems and my memory span is only slightly longer than a fish's, so  I need to save things I discovered myself and found over the internet.
  • Instructions about installing Eclipse on Fedora.
    1. Download Eclipse from here
    2. From terminal, log in as root
    3. Unzip the  package to /work directory.
      tar - xvzf eclipse-version.blablabla.tar.gz -C /work
    4. Change permission on folder /eclipse
      chmod -R +r /work/eclipse
    5. Create executable file and save it to /usr/bin
      touch /usr/bin/eclipse
      chmod 755 /usr/bin/eclipse
      # create this file using vi
      vi /usr/bin/eclips
      # write the env variable to the file
      ECLIPSE_HOME=/work/eclipse
      export ECLIPSE_HOME
      $ECLIPSE_HOME/eclipse $*
    6. Create destop launcher for easy access
      vi /usr/share/applications/eclipse.desktop
      #add these lines to the file
      [Desktop Entry]
      Encoding=UTF-8
      Name=Eclipse
      Comment=Eclipse Helio
      Exec=eclipse
      Icon=/work/eclipse/icon.xpm
      Terminal=false
      Type=Application
      Categories=GNOME;Application;Development;
      StartupNotify=true
    7. RUN Eclipse!!! YAY!!!!
    8. Now, if there is an error message about /lib/i386/client/libjvm.so: try this:
      chon -t execmem_exec_t '/work/eclipse/eclipse'