Thursday, April 26, 2012

Ditch the landline or cell plan?

You can have the best pure Google smartphone and not have to pay for phone service, only data.  The caveat is that you will to be on wifi to receive a call. But, ah ha! You can bring your own wifi wherever you go. You can get a device called a MIFI or personal hotspot from Verizon or AT&T or whatever mobile provider you want. Keep in mind that Voice over IP uses about 1.2MB per minute. So if you use about 1000 minutes a month you'll use at least 1.2 gigabytes of data.  That's assuming all calls are actually going over the MIFI. If you're like me and have wifi at home and work you'll use much less mobile data.

If you just want to replace a home phone with a smartphone that makes calls over wifi. You won't need a mobile plan or MIFI.

Here's how to do it.

1) Get a Google Voice phone number.
2) Go to the Settings page in Google Voice. Make sure Google Chat is checked on the Phones tab.


3) Install Talkatone on your Android or iOS device, or both. Yes iPad and Android tablets work.
4) Start up Talkatone and use the same Google account as your Google Voice account.
5) Done. Make and receive calls using Talkatone.

If you are using a tablet or don't want to do speakerphone only calls pick up a good pair of earbuds with a microphone, a bluetooth headset, or one of these wired or bluetooth handsets. (Click em to find them at Amazon)


Edit: Yes, you can send and receive SMS text messages this way. MMS (picture or multimedia messages) do NOT work and will be silenty dropped and never reach you. Google is already working on this and has some support for people sending MMS to a Google voice number.  MMS originating from other providers, not

Edit2: Saving power. This could bite you.  Most, if not all smart phones will turn off WIFI after inactivity. This means you will not receive calls once it is disconnected. That's kind of a bummer since forcing WIFI to stay on will eat your battery.  So, clearly this solution isn't perfect.

Edit3: Upon investigating the talkatone website there is a setting that will keep the wifi connected.

Monday, April 2, 2012

Generating and emailing HTML reports from SQL Server

Recently, I was looking for a way to email nightly reports directly from SQL Server (I'm using 2008 R2). With sp_send_dbmail, sending email is a piece of cake after setting up your mailing profile. But ever try attaching a query? You get a disgusting regurgitation of your results splattered all over your email. It's not pretty.... or readable.



So I created a stored procedure to convert a temp table into an HTML table. Yep, just select something into a temp table and call this stored procedure and out pops an HTML table suitable for emailing. Here's the code:



CREATE procedure [dbo].[temp_table_to_html](@tbl varchar(64), @no_results_msg varchar(MAX) = 'None') as begin
  set NOCOUNT ON
  
  if exists (select * from tempdb.sys.columns where object_id = object_id('tempdb..#'+@tbl)) begin
    declare @q varchar(MAX);
    declare @cols varchar(MAX);
    declare @c int;
    set @c = 0;
    create table #c (c int);
    set @q = 'insert into #c select count(0) from #'+@tbl
    exec(@q)
    select @c = c from #c;
    drop table #c;
    
    if @c > 0 begin 
        select '<style>table,td,th { border:solid 1px #ccc; border-collapse:collapse; padding: 3px;}</style>';
select '<table><tr>';
select '<th>'+name+'</th>' from tempdb.sys.columns where object_id = object_id('tempdb..#'+@tbl);
select '</tr>';
   
select @cols = coalesce(@cols +'+','') + '''<td>''+ISNULL(cast('+name+' as varchar(MAX)),''NULL'')+''</td>''' from tempdb.sys.columns where object_id = object_id('tempdb..#'+@tbl);
   
   
set @q = 'select ''<tr>''+' + @cols + ' +''</tr>'' from #'+@tbl;
   
exec sp_sqlexec @q
select '</tr>'
   
select '</table>';
end
if @c is null or @c = 0 select @no_results_msg as NoRows
  end


  set NOCOUNT OFF
end



And here is how you might use it:


select 'Joe' as Name, 25 as Age, 42.10 as Budget into #results
exec dbo.temp_table_to_html 'results'

It returns multiple tables that are all chunks of HTML. Htmm... not pretty in SQL Server Management Studio.



So lets add a switch to control whether it renders HTML or returns a table and we get the best of both worlds.



create procedure sample_report(@html bit = 0) as begin
  set nocount on
  select 'Joe' as Name, 25 as Age, 42.10 as Budget into #results;
  if @html is null set @html = 0;
  if @html = 0 begin
    select * from #results;
  end
  if @html = 1 begin
    exec dbo.temp_table_to_html 'results'
  end
  drop table #results;
  set nocount off
end

Now if we run the procedure manually it returns the query results as intended.






Ok, we've built our foundation. Now lets write a procedure to email the results of the query, as HTML.




exec msdb.dbo.sp_send_dbmail 
  @from_address = 'me@here.com',
  @recipients = 'you@there.com',
  @subject = 'That report you wanted',
  @body = '<h1>This appears before the HTML table and can be HTML as well.</h1><br/>',
  @query_result_header = 0,
  @execute_query_database = 'your_db_name_here',
  @query = 'exec dbo.sample_report 1',
  @body_format = 'HTML';




And that's it!  We can now email the results of a query very easily as a nice HTML table. Here's what our sample looks like:














Thursday, February 9, 2012

The US patent system

I have 3 kids. They are wonderful and give me tons of joy.  But sometimes they fight over things and there is yelling, crying, hurt feelings, etc.  That stinks and it hurts my ears.

An analogy occurred to me today that the US patent system, since it is funded by the number of patents that are applied for, are in the business of getting as many people or companies to apply for patents as possible. If they spend a lot of time researching and actually determining if a patent is valid or not they get paid the same. So why spend a lot of time on a patent? There's no reason to actually think about it because the faster they decide on a patent the faster they can move on to the next patent.  They get paid faster and make more money.
 They shovel the decision of who actually gets that patent over to the judicial system where it costs exponentially more to determine who wins.  All of those costs are rolled in to the winners final product to recoup costs and the cost goes up for consumers. Lawyers win, consumers lose.

As a parent, it's like promising all of my children that they can have a cookie even though there is only one left. Then I let them fight it out to see who gets it. Is that the best way to handle it? Maybe I should put a little more thought into this and avoid the fighting and crying. Maybe if the patent office was able to hear all of the crying and fighting, and it affected them negatively, they would be inclined to avoid causing that racket. How about some repercussions if they make a bad decision?

Let me know your thoughts. How can we make this better? What can we do to be heard? Leave a comment or hit me up on G+