Posts

Showing posts from 2017

Steinhaus–Johnson–Trotter algorithm

package permutation; import java.util.HashSet; import java.util.Scanner; public class JohnsonTrotter { static HashSet<String> permutations = new HashSet<>(); public static void main(String args []) { // Incorrect(); System. out .println( "Enter the count of integers whose all " + "possible orders will be permuted using Johnson and Trotter" ); Scanner scanner = new Scanner(System. in ); int N = scanner .nextInt(); scanner .close(); int arr [] = new int [ N ]; for ( int i = 1; i <= N ; i ++) { arr [ i - 1] = i ; } boolean [] direction = new boolean [ N ]; // I am using a boolean array of the same size as the number of // integers. A true indicates right, and false indicates left. Don't // judge me for choosing right as true, I am right handed :P. There is // another reason why I chose right as true, by default a new boolean // array in Java

SOAP REST SERVLET What is the difference?

This is more of a psychological question I think. What is psychological about this? These 3 things together represent something very broad, so broad it may not even share a name. Phew.. differences between boys and girls. Between cat and dog. Pencil and pen. At least those things are close. Asking SOAP vs REST vs SERVLET is like asking 'bat' vs 'bat shit crazy'. So let's take them one by one, then we shall find out the underlying relationship. SOAP: Soap is a construct. The construct demands you to use the Internet in a particular way to achieve your job at hand. It suggests that you send human readable data like XMLs through the Internet using mainly HTTP and SMTP protocols. So if you want to make a blog application. You will send the blog posts as XMLs to your browser which shall be equipped with a JavaScript file to understand and make sense of this fury of information. Coming in on the HTTP and SMTP protocol in extensive human readable formats like XML. Is it
I was wondering, why can't I read .class files generated by the compiler on my notepad. I saw some strange figures between infrequent english alphabets. There were even some paragraph changes. What is this? What is a .class file? Why are there random alphabets in it? What is happening? Can I read this file somehow?? Well basically how a java program gets executed is divided into some steps. Starting of these is the conversion of java code written in the Java Programming language which is quite human readable. Human readable... Hmmm. Does that mean the machine cannot understand it? Isn't the machine showing me all this, isn't it supposed to know? Yes the machine is showing you all this. But you have to understand a machine just understands instructions. And your machine has a lot of them. Actually its just being fed with shit load of instructions, a couple of billions every second approximately. Speak of a hardworking individual. So when you tried to read it on your

Self musings

Light burns diffidence into me   Darkness is my accomplice   Together we prowl, looking for victims   Not to villainize >   For we are the heroes who revel in secret   Touched we get by these small gestures   Incomplete we are without the other   Sail high our emotions do   For we understand what nothingness feels   Black is our color, we roll into it happily   Hate we the happiness that flows through our veins   Dislike our nature we do   But it is our nature which defines us   So constantly we struggle to become brighter   Without understanding that brightness will eventually kill us   Because we do not believe in destinations   Which is absolution   But love the journey we do

Rails Musings

The order of mentioning stuff in the model.rb files should be: =begin 1. reference to libraries 2. has many association 3. has many through association 4. belongs_to association 5. validations 6. call backs 7. custom validations 8. custom instance methods 9. custom class methods 10. all our private methods =end Oh and btw, =begin and =end mark the start and end of the comment :)

Linux-Postgres Musings

To take a dump from linux server and compress it psql -U username -F filename psql -U postgres -d postgres -f chameli.sql pg_dump -U postgres postgres -f  /tmp/chameli.sql tar -cvzf abc.tar.gz chameli.sql tar -zcvf archive-name.tar.gz directory-name To use a dump file to setup db in win machine  Use pg_restore.exe --host "localhost" --port "5432" -U "postgres" --dbname "postgres" --verbose --schema "public" "C:\Users\abhinav\Downloads\new03march.backup"

SQL Musings

SELECT distinct "public".task."id", "public".task_log.created_at FROM "public".task , "public".task_log WHERE "public".task.actor_id = 777 and task."id"= task_log.task_id order by "public".task_log.created_at desc limit 10 TO Set up data for the whole column UPDATE schema.table_name SET column_name='value' Deleting a lesson SELECT id FROM cmsession WHERE cmsession.title like '%elete%' DELETE FROM cmsession WHERE cmsession.title like '%elete%' SELECT * FROM lesson WHERE  session_id in (SELECT id FROM cmsession WHERE cmsession.title like '%elete%' ) DELETE FROM lesson WHERE  session_id in (SELECT id FROM cmsession WHERE cmsession.title like '%elete%' ) SELECT * from assessment where lesson_id in (SELECT "id" FROM lesson WHERE  session_id in (SELECT id FROM cmsession WHERE cmsession.title like '%elete%' )) DELETE fro