Open Side Menu Go to the Top
Register
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

02-29-2012 , 04:06 PM
Does anyone have much experience with Google WebToolkit? I am starting a project on the side for a large-scale web application. I am going to be using Java on the server, but still looking for a client solution. GWT looks pretty useful and I could keep everything in Java and under one project.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 04:44 PM
What is HN?

Raspberry Pi is like the Arduino except with a Mega Processor I take it...yeah do want (have an Arduino dev kit, kinda fun eventhough I haven't done as much as I wanted to yet).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 04:56 PM
Quote:
Originally Posted by MrWooster
And Gullanian makes it to front page of HN again!! God I hate you!!


Edit: Ok, I take that back, its an excellent article. Really going point about how cookies are always sent in the request so using a 2nd domain reduces request size... never thought of that.
lol! I wanted to post link here but I've been posting a lot recently and don't want to be an attention whore :S Thanks for compliments, all the techniques in there have been discussed quite a lot by other people as well but I wanted to try and show as well that page speed is a real competitive edge that startups should take advantage of as it has real benefits.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 05:16 PM
Quote:
Originally Posted by clowntable
What is HN?
http://news.ycombinator.com/news

pretty much the only other site I visit on a daily basis.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 05:23 PM
Quote:
Originally Posted by Neko
http://news.ycombinator.com/news

pretty much the only other site I visit on a daily basis.
No Reddit?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 05:25 PM
Nothing beats HN for actual discussion you can learn a ton from, Reddit is good as well but there's a lot more noise
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 05:26 PM
I have a couple reddit feeds on my iGoogle home page, but only click through once or twice a week probably. I find I get more than enough content from HN every day so I don't branch out too often.

edit: and as Gullanian says, the real value of HN is in the comments (I often only read the comments and not bother with the article).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 05:35 PM
I absolutely want a raspberry pi, probably many lol. I love that they're called model A and model B, bbc nostalgia ftw

+1 HN regular refresh, awesome content.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 05:56 PM
Ye, I have to say, the quality of content on reddit is fast going downhill. Its about 70% memes now.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 06:05 PM
Hi,

I've been lurking this sub-forum for some time as I started learning PHP a few months ago and use a fair amount of SQL in my job.

Anyway, I was trying to put together a function in PHP that would allow me to update a user's (or groups of users') info without having to decide in advance of using the function what fields I wanted to match or what fields I wanted to update.

I managed to put together a function that does what I needed it to, but it feels kind of hacky and inelegant.

Here's a version of the function that would only take 3 variables:
Code:
function update_user_info($userid=NULL,$email=NULL,$username=NULL)
{
    $update_array = array();
    $i = 0;
    $j = 0;
    
    if( $userid != NULL )
    {
        $update_array['userid'] = $userid[0];
        if("where"==$userid[1])
        {
            $update_array['where'][$i++] = 'userid';
        }
        else
        {
            $update_array['set'][$j++] = 'userid';
        }
        
    }
    
    if( $email != NULL )
    {
        $update_array['email'] = "'".$email[0]."'";
        if("where"==$email[1])
        {
            $update_array['where'][$i++] = 'email';
        }
        else
        {
            $update_array['set'][$j++] = 'email';
        }
        
    }
    
    if( $username != NULL )
    {
        $update_array['username'] = "'".$username[0]."'";
        if("where"==$username[1])
        {
            $update_array['where'][$i++] = 'username';
        }
        else
        {
            $update_array['set'][$j++] = 'username';
        }
        
    }
    
    $set = "";
    $where = "";
    
    if(isset($update_array['set'][0]))
    {
        foreach($update_array['set'] as $value)
        {
            $set .= "`" . $value . "` = " .$update_array[$value] . ", ";
        }
    }

    if(isset($update_array['where'][0]))
    {
        foreach($update_array['where'] as $value)
        {
            $where .= "`" . $value . "` = " .$update_array[$value] . " AND ";
        }
    }
    $set = substr($set,0,-2);
    $where = substr($where,0,-5);
    
    if($userid[0] == $userinfo['userid'] || isset($userinfo['admin_priv']))
    {
        $query = "UPDATE users SET " . $set . " WHERE " . $where;
        $result = mysql_query($query);
        $affected = mysql_affected_rows();
    }
    else return "Incorrect privileges";
}
So, if I wanted to update the username of a single user, and I knew his userid, I would call the function with:
Code:
$userid = array(5,'where');
$username = array('username','set');
update_user_info($userid,NULL,$username);
If I wanted to update the email of someone who I knew their username, I would:
Code:
$email = array('test@example.com','set');
$username = array('username','where');
update_user_info(NULL,$email,$username);
Like I said, it appears to work correctly for all the cases, I've tested so far, but it seems off to me (partially because it's so long), and I'm not experienced enough at programming yet to know why that might be.

Thanks for any help or insight anyone can give.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 06:32 PM
You should be keeping track of the user_id. Databases index certain columns on tables to make retrieval from them very fast. Typically, the index is on the user_id (though you could have multiple indexes).

The problem with the above code is that, unless you have indexes on all your columns, the queries are going to be very slow.

A better design would be to keep track of the user_id (maybe in a session or cookie), and always use it when updating the user information.




(Just realised that I didnt actually answer the actual question, exactly what this thread was talking about a few hours ago)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 06:38 PM
Just to extend on that as well if you have to be able to search on a non PK field it's best to have a set of methods that update something based on user ID, and another set of functions return the user ID based on another param.

IE:

Code:
function updateUsername(int UserID, string NewUsername)
{
    Set Username = NewUsername WHERE UserID = UserID
}

function getUserIDFromEmail(string Email)
{
    FROM Users WHERE Email = Email
    return Users.ID
}
Then for example you can do:

Code:
updateUsername(getUserIDFromEmail("tom@2+2.com"), "NewUsername")
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 06:49 PM
Sorry, for clarification, the Session information is stored in $userinfo, and the userid is stored in $userinfo['userid'].

I expect that most of the time I will be using the function to update based on userid, example: "SET blahblahblah WHERE userid = $userinfo['userid']", but I wanted to make a function that would be a catch-all so I could do something like "SET `ban` = TRUE WHERE `lastName` = 'Whitaker'". This type of command would likely be much more used in other tables, like tables that hold user content.

As I fleshed out my application, I'd probably take the most common uses and put them in their own function for speed sake, but I thought it might be useful to make it so I didn't need a new function for each time I interacted with user data until I knew all the ways I would be interacting with it once the app is closer to being 'finished.'
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-29-2012 , 09:09 PM
Quote:
1 / 5 Part 1 Wed 29 Feb 2012 5:02:22 PM PST 100.00 / 100
Great Success!

Did it cucumber style as well, not superhappy with the repetition and used a somewhat ugly hack so compare output.

Code:
---- count_words.feature ----
Feature: Count Words

As a user I want to be able to count the words in a given sentence.

Scenario Outline: Count words in a given sentence
  Given the input to count_words is "<input>"
  When count_words is run
  Then the output of word_count should be "<output>"
  
Examples:
  |input|output|
  |A man, a plan, a canal -- Panama|{'a' => 3, 'man' => 1, 'canal' => 1, 'panama' => 1, 'plan' => 1}|
  |Doo bee doo bee doo|{'doo' => 3, 'bee' => 2}|
  |a A a|{'a' => 3}|

---- palindrome.feature ----
Feature: Detect Palindromes

As a user I want to be able to check if a given word or phrase is a palindrome.

Scenario Outline: Provide input to palindrome?
  Given the input to palindrome? is "<input>"
  When palindrome? is run
  Then the output of palindrome? should be "<output>"
  
Examples:
  |input|output|
  |A man, a plan, a canal -- Panama|true|
  |Madam, I'm Adam!|true|
  |Abracadabra|false|
count_words_steps.rb...highlighted the uglyness in bold (+palindrome_steps.rb) as you can see lots of non-DRY
Code:
---- count_words_steps.rb ---- 
require_relative 'hw1.rb'

Given /^the input to count_words is "([^"]*)"$/ do |input|
  @input = input
end

When /^count_words is run$/ do
  @output = count_words(@input)
end

Then /^the output of word_count should be "([^"]*)"$/ do |expected_output|
  raise("Wrong Output") unless @output == eval(expected_output)
end

---- palindrome_steps.rb ---- 
require_relative 'hw1.rb'

Given /^the input to palindrome\? is "([^"]*)"$/ do |input|
  @input = input
end

When /^palindrome\? is run$/ do
  @output = palindrome?(@input).to_s
end

Then /^the output of palindrome\? should be "([^"]*)"$/ do |expected_output|
  raise('Wrong Output') unless @output == expected_output
end
hw1.rb .. somewhat of a quick hack without thinking much...mostly wanted to play with cucumber:
Spoiler:
Code:
def palindrome?(string)
  pretty_string = string.downcase.gsub(/\W/,'')
  return  pretty_string == pretty_string.reverse
end

def count_words(string)
  my_hash = Hash.new
  string.downcase.scan(/\w+\b/).each do |key|
    my_hash[key] ? my_hash[key] += 1 : my_hash[key] = 1
  end
  return my_hash
end

Last edited by clowntable; 02-29-2012 at 09:22 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-01-2012 , 06:12 AM
clowntable, or any experienced rubyists:

Is there any way to achieve the same effect you get with class_eval in Assignment 5, but without putting all that code in a long string, which just seems like such a hack.

WARNING: HW SPOILER if you havn't done it yourself yet: http://pastie.org/3495193
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-01-2012 , 02:39 PM
Just posted a question in the Business forum, looking at buying/selling websites on Flippa. If anyone here has any experience/info would be great to get some feedback.

http://forumserver.twoplustwo.com/30.../index130.html


Thanks
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-01-2012 , 03:48 PM
Quote:
Originally Posted by gaming_mouse
clowntable, or any experienced rubyists:

Is there any way to achieve the same effect you get with class_eval in Assignment 5, but without putting all that code in a long string, which just seems like such a hack.

WARNING: HW SPOILER if you havn't done it yourself yet: http://pastie.org/3495193
Hi gaming_mouse!

You have to use class_eval still, but instead of putting the code in a string, you can use define_method, instance_variable_set and instance_variable_get to create a block to be executed instead.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-01-2012 , 03:52 PM
Set money aside, think for a bit untill you have a good idea and use it as your fund to develop your own site.
Flipping sites seems like the devil...my advice would be to stay away

Re: Ruby..not gonna look at it untill I have finished mine. FWIW the cucumber version I did was really bad because that exercise is def. something I'd put into the "unittest it" realm i.e. rspec only is fine. Just did it to get a bit more cucumber experience.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-02-2012 , 12:18 AM
Quote:
Originally Posted by candybar
Hi gaming_mouse!

You have to use class_eval still, but instead of putting the code in a string, you can use define_method, instance_variable_set and instance_variable_get to create a block to be executed instead.
thanks candybar, that's some "sweet" advice. i am going to try to get it to work that way.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-02-2012 , 02:11 AM
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-02-2012 , 06:05 AM
Sigh, hotmail just blacklisted our webserver for email, this new IP block is a headache. What's a good cheap way to send email (not too much, like probably 10k a month or something). We don't want to use mailchimp, just something super cheap for just sending out emails, we provide the addresses and content and it distributes them.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-02-2012 , 12:57 PM
Quote:
Originally Posted by Gullanian
Sigh, hotmail just blacklisted our webserver for email, this new IP block is a headache. What's a good cheap way to send email (not too much, like probably 10k a month or something). We don't want to use mailchimp, just something super cheap for just sending out emails, we provide the addresses and content and it distributes them.
how many emails do you have the mailchimp would cost you more than 10K?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-02-2012 , 01:10 PM
Dyn has an SMTP service I think, assuming you're not running mailing lists, and that's what you want.

If you're running mailing lists, use a mailing list service.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-02-2012 , 01:18 PM
Mail chimp for us would be $50 a month for us quite soon I think, that's about 45% of our hosting cost just seems disproportionate but at the end of the day I suppose it doesn't matter and I can prune a lot of our lists as well.

We need it for a mix of things,
1) Mailing list
2) To email licenses to customers when they purchase (all hotmail ones bouncing atm which is time consuming to sort out)
3) General site usages (forgotten passwords, email confirmations etc)

Mail chimp is good for #1 but not #2 and #3, I'd like an all in one solution really for simplicities sake

Also our biggest emails are just notifying a new blog post it out, or to download a new release of our software. There's basically no way for us to get any costs back through selling to subscribers or advertising so just seems to expensive for that purpose.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-02-2012 , 01:24 PM
I remember someone recommending this:

http://aws.amazon.com/ses/#pricing

Anyone got experience? $0.10c per 1000 messages seems pretty good, not sure how good those messages are at not arriving in spam/being blacklisted though
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m