..MindWrite..

Archive for the ‘tech’ Category

Insert only if not exists – mysql

Posted by guptaradhesh on April 3, 2014

 

Example:

insert into mytable
(my_string, created_at, removed, flag)
SELECT ‘this string should be unique’,curdate(), 0, ‘new’ FROM temp
Where not exists
(select * from mytable where my_string = ‘this string should be unique’);

// make sure there is no parenthesis in select
// it seems, using a temp table is a requirement

Advertisements

Posted in tech | Tagged: , , | Leave a Comment »

Copy files from one ec2 instance to other ec2 instance

Posted by guptaradhesh on January 7, 2014

Doing an scp gave the following error message:

Permission denied (publickey)

The reason for the above is that it asks for ec2 instance password while we use .ppk file now days.

Here are the quick steps one should follow:

  1. server 1
    1. generate the id_rsa.pub
      ssh-keygen -t rsa
    2. /root/.ssh/id_rsa or /home/ec2-user/.ssh/id_rsa
    3. No need to enter any passphrase
  2. server 2
    1. Open /etc/ssh/sshd_config/sshd_config
    2. If logged as ec2-user; susu su
      Uncomment the lines below if they are not already
      RSAAuthentication yes
      PubkeyAuthentication yes
    3.  Open /root/.ssh/authorized_keys
  3. append contents of id_rsa.pub file of server 1 to authorized_keys of server 2

Posted in tech, unix | Tagged: , , | Leave a Comment »

Designing a distributed scalable web application

Posted by guptaradhesh on August 30, 2013

Here is a very interesting and useful read: here

Posted in markets, tech | Tagged: , , , , | Leave a Comment »

Crowdsourcing vs Crowdfunding

Posted by guptaradhesh on August 30, 2013

Crowsdsourcing is when you have many people to help you with a project with ideas, testing, labor to build a better product. Open-source is a big example of crowd-sourcing. Leveraging the collective coding power of freelance programmers to deliver a great product. Another great examples being Wikipedia. Reddit, Digg being more examples of the same.

Crowdfunding is about the financing of projects and people by (large) crowds. Crowdfunding is a DIWO (do it with others) approaching to contributing to a cause they believe in. In a nutshell, it involves soliciting an audience of potential fans and convincing those fans that your film project is worthy of a donation from them to help you make the film. Or raising money for education or medical treatments.
Now they’re bringing these concepts home. Instead of just giving money away because it feels good or is the right thing to do, now you can do so and own shares of stock in that business!
Some of the top crowdfunding sites are: Kickstarter, Indiegogo, Crowdfunder, Angelist, Quirky ..

Posted in markets, tech | Tagged: , , , , , , | Leave a Comment »

Finding longest palindrome in a string

Posted by guptaradhesh on August 26, 2013

Here is an elegant code I found.

string expandAroundCenter(string s, int c1, int c2) {

  int l = c1, r = c2;
  int n = s.length();
  while (l >= 0 && r <= n-1 && s[l] == s[r]) {
    l–;
    r++;
  }
  return s.substr(l+1, r-l-1);
}
string longestPalindromeSimple(string s) {
  int n = s.length();
  if (n == 0) return “”;
  string longest = s.substr(0, 1);  // a single char itself is a palindrome
  for (int i = 0; i < n-1; i++) {
    string p1 = expandAroundCenter(s, i, i);
    if (p1.length() > longest.length())
      longest = p1;
    string p2 = expandAroundCenter(s, i, i+1);
    if (p2.length() > longest.length())
      longest = p2;
  }
  return longest;
}
source: here

Posted in java, puzzles/ algorithms, tech | Tagged: , , , | Leave a Comment »

Why char array is preferred over String for storing password?

Posted by guptaradhesh on August 23, 2013

String is immutable in java and stored in String pool. Once it’s created it stays in the pool until unless garbage collected, so even though we are done with password it’s available in memory for longer duration and there is no way to avoid it. It’s a security risk because anyone having access to memory dump can find the password as clear text.

If we use char array to store password, we can set it to blank once we are done with it. So we can control for how long it’s available in memory that avoids the security threat with String.

Posted in java, tech | Tagged: , , , | Leave a Comment »

Print matrix in a sprial order

Posted by guptaradhesh on August 22, 2013

 

Recursive Solution (Java):

public class PrintMatrixSpiral
{
 public static void main(String[] args)
 {
  int[][] matrix =
  {
  { 2, 4, 6, 2, 5, 7 },
  { 2, 5, 7, 8, 9, 3 },
  { 6, 4, 7, 3, 5, 7 } };

  printSpiral(matrix);
 }

 public static void printSpiral(int[][] matrix)
 {
  printSpiral(matrix, 0);
 }

 private static void printSpiral(int[][] matrix, int depth)
 {
  if (matrix == null && matrix.length == 0)
   return;
  int rows = matrix.length;
  int cols = matrix[0].length;
  if (2 * depth > Math.min(rows, cols))
   return;
  for (int i = depth; i < cols - depth - 1; ++i)
  {
   System.out.print(matrix[depth][i] + ",");
  }
  for (int i = depth; i < rows - depth - 1; ++i)
  {
   System.out.print(matrix[i][cols - depth - 1] + ",");
  }
  for (int i = rows - depth; i > depth; --i)
  {
   System.out.print(matrix[rows - depth - 1][i] + ",");
  }
  for (int i = rows - depth - 1; i > depth; --i)
  {
   System.out.print(matrix[i][depth] + ",");
  }
  printSpiral(matrix, ++depth);
 }
}


Posted in java, puzzles/ algorithms, tech | Tagged: , , , , | Leave a Comment »

Startups – food for thought!

Posted by guptaradhesh on July 16, 2013

With so many startup working hard on great ideas trying to innovate and make some impact. There is always a big threat for startups working on something which closely aligns with a big company. If they offer to buy you – you are lucky; if they launch a competitive product – things won’t be easy!!

Now days we see so many big companies like Google, Yahoo, Facebook entering different niche segments and launching different products. In such a scenario, its very important for a startup to be focused and take a right call at the right time.

I asked a similar question at a Tech-Meetup to some startup biggies and their answer was smart but unsatisfying. They pointed out in being smarter and confident about what you are doing and performing better. Also on the fact that, being a startup – its easier to maneuver the product and change directions (I liked this answer) — but still, I dont think one should not be worries about being crushed away as a minnow as soon as a big company enters in your space. Instead of demotivating anyone – build a product that makes the Giants think as worth buying then rebuilding.

Something similar I noticed which made me jot this down is this:

Amazon launched “Amazon Birthday Gift“, is a way to integrate social media for giving birthday gifts. It allows a group of Facebook friends to go in on an Amazon.com giftcard together. User buys an Amazon.com giftcard and invites other mutual friends to donate using Amazon Birthday Gift. When birthday arrives, recipients are tagged in the Facebook Timeline wall post.

Interesting to note is, the NY based startup called Aggregift has been running the same idea from quite a few months. I wonder what happens to such startups!! Similar gifting idea is run by companies like: Wrapp, Boomerang ..

aggregift

Posted in markets, tech | Tagged: , , , , , , | Leave a Comment »

Key Ecommerce Metrics that Determine Success

Posted by guptaradhesh on July 8, 2013

  1. Understanding lifetime value of a customer-

    Customer lifetime value, CLTV = (Avg profit generated per year X no. of years) – Acquisition costs

  2. Monitoring customer satisfactionThis will tell:

    – customers perspective
    – required potential changes in current offering
    – truth behind the numbers

  3. Measuring your sales funnelAnalyzing and working on the following plays an important role:

    – Landing pages
    – Conversion rate
    – types of visitors

  4. Determining marketing ROI

    Avg. acquisition cost = Acquisition spending / number of customers acquired

Posted in markets, tech | Tagged: , | Leave a Comment »

Yahoo acquires Tumblr! Great move?

Posted by guptaradhesh on May 20, 2013

Yahoo is being extra cautious this time. Definitely a brave move of buying a great social microblogging site (Alexa #32) generating just a few millions of revenue. But it looks like they have a plan. They have lessons to learn from Flickr. And hence we are hearing some nice statements like:

“They have promised not to screw it up.” and

“Part of our strategy here is to let Tumblr be Tumblr,” Ms. Mayer

Yahoo! anticipates to channel some younger audience from Tumblr and they project a 50% boost in their traffic. When it’s about buying Tumblr, 1.1B could be totally worth it. Let’s see how Yahoo! works on it.

Apart from all, definitely they should fix Flickr! Here is an interesting read:
http://www.linkedin.com/today/post/article/20130520172151-6388496-dear-yahoo-now-please-fix-flickr

P1-BL595A_TUMBL_D_20130519220303

Posted in markets, tech | Tagged: , , , | 1 Comment »