{"QuestionId": 21279600, "AnswerCount": 2, "Tags": "", "CreationDate": "2014-01-22T09:58:44.253", "AcceptedAnswerId": "21279677", "Title": "Check last character is \"&\" is not and remove it (make this with linq)", "Body": "

I have a string _outputUrl and I want to check whether its last character is \"&\" or not. And if its \"&\" I want to remove it from string. I have made this with If case like this

\n\n
if (_outputUrl!=null && _outputUrl[_outputUrl.Length - 1].ToString() == \"&\")\n{\n    _outputUrl = _outputUrl.Remove(_outputUrl.Length - 1);\n\n}\n
\n\n

How can I convert this to a linq expression?

\n", "Lable": "No"} {"QuestionId": 21337158, "AnswerCount": 1, "Tags": "", "CreationDate": "2014-01-24T16:04:41.240", "AcceptedAnswerId": "21339613", "Title": "Delete Duplicate Items In SharePoint List", "Body": "

I have a list which has thousands of records and I need them to be unique. I found a PowerShell script online that will work if I only have 1 unique column. However, I have to group by 2 columns and I can't figure out how to make it work.

\n\n

For example, if I have this data in a SP list, only if both columns are duplicates should the items be removed.

\n\n
Title     Carrier\n1         Carrier1\n1         Carrier1     *Remove This One\n12        Carrier1\n12        Carrier2\n100       Carrier1 \n100       Carrier1     *Remove This One\n100       Carrier2\n
\n\n

Here is the code sample I found online that will work for 1 column, but not for 2.

\n\n
cls\nif((Get-PSSnapin | Where {$_.Name -eq \"Microsoft.SharePoint.PowerShell\"}) -eq $null) {\n     Add-PSSnapin Microsoft.SharePoint.PowerShell;\n}\n\n$ListName = \"DuplicateTest\"\n\n$web = Get-SPWeb -identity \"http://MyVM/sites/TestSite\"\n$list = $web.Lists[$ListName]\n\n$AllDuplicates = $list.Items.GetDataTable() | Group-Object Title | where {$_.count -gt 1}\n$count = 1\n$max = $AllDuplicates.Count\nforeach($duplicate in $AllDuplicates) \n{ \n    $duplicate.group | Select-Object -Skip 1 | % {$list.Items.DeleteItemById($_.ID)} \n    Write-Progress -PercentComplete ($count / $max * 100) -Activity \"$count duplicates removed\" -Status \"In Progress\" \n    $count++ \n}\n
\n", "Lable": "No"} {"QuestionId": 21355266, "AnswerCount": 2, "Tags": "", "CreationDate": "2014-01-25T19:34:55.590", "AcceptedAnswerId": null, "Title": "Using ajax to render partial", "Body": "

In my rails app I have a model Song. On one of the user's profile pages user_music_path(@user) I'm rendering all of their songs.

\n\n

People can also like these songs, which is set up and working, I just want to use AJAX instead of page refreshes. The problem I'm having is when using ajax, I get the error undefined local variable or method \"song\" when I'm clicking the link \"like\".

\n\n

Here is some of my code:

\n\n

User's Music Page views/users/music.html.erb

\n\n
...\n<ul class=\"playlist list-group\">\n  <%= render @songs %>\n</ul>\n
\n\n

views/songs/_song.html.erb

\n\n
<li class=\"list-group-item\">\n  <p class=\"pull-right\">\n    <%= render :partial => 'songs/like_button', :locals => {:song => song} %>\n    <%= render :partial => 'songs/likes', :locals => {:song => song} %>\n  </p>\n</li>\n
\n\n

views/songs/_like_button.html.erb

\n\n
<% if current_user.voted_on?(song) %>\n  <%= link_to \"Unlike\", unlike_song_path(song), :method => :post, :remote => true %>\n<% else %>\n  <%= link_to \"Like\", like_song_path(song), :method => :post, :remote => true %>\n<% end %>\n
\n\n

views/songs/_likes.html.erb

\n\n
<%= song.votes.count %>\n
\n\n

views/songs/like.js.coffee

\n\n
$(\"p.pull-right\").html('<%= render :partial => \"songs/like_button\", :locals => {:song => song} %><%= render :partial => \"songs/likes\", :locals => {:song => song} %>');\n
\n\n

controllers/songs_controller.rb

\n\n
def like\n  begin\n    @vote = current_user.vote_for(@song = Song.find(params[:id]))\n    @vote.save\n    respond_with @song.user, :location => user_music_path(@song.user)\n  rescue ActiveRecord::RecordInvalid\n    redirect_to @song\n  end\nend\n
\n\n

And as mentioned earlier, the :like action worked perfectly before I starting using AJAX. I've also added respond_to :html, :js to my songs_controller. And the error I get when I try to like the song is ActionView::Template::Error (undefined local variable or method \"song\" for #<#<Class:0x000001028de9d0>:0x00000106ecd9f0>):

\n", "Lable": "No"} {"QuestionId": 21739432, "AnswerCount": 2, "Tags": "", "CreationDate": "2014-02-12T20:57:30.700", "AcceptedAnswerId": null, "Title": "checking the value of CKEditor and disabling the submit button if no content", "Body": "

running a basic function that disables a form submit button depending on the input length.

\n\n

I am using this:

\n\n
    // check if the newpost text area in empty on page load and also input change\n$(document).ready(function(){\n    disableNewPost();\n    $('#newpost').keyup(disableNewPost);\n});\n\n// disable new post submit button if the new post ckeditor is empty\nfunction disableNewPost() {\n    if ($('#newpost').val().length > 0) {\n        $(\".addnewpostbtn\").prop(\"disabled\", false);\n    } else {\n        $(\".addnewpostbtn\").prop(\"disabled\", true);\n    }\n}\n
\n\n

This works with a normal text area see here:http://jsfiddle.net/QA22X/

\n\n

But when working with CKEditor it doesn't work.

\n\n

I have done my research, but cant find anything that works.

\n\n

I saw this and tried it:

\n\n
    // check if the newpost text area in empty on page load and also input change\n$(document).ready(function(){\n    disableNewPost();\n    var e = CKEditor.instances['#newpost']\n    e.on( 'keyup', function( event ) {\n    disableNewPost();\n    });\n});\n\n// disable new post submit button if the new post ckeditor is empty\nfunction disableNewPost() {\n    var value = CKEDITOR.instances['#newpost'].getData();\n    if ($(value).length > 0) {\n        $(\".addnewpostbtn\").prop(\"disabled\", false);\n    } else {\n        $(\".addnewpostbtn\").prop(\"disabled\", true);\n    }\n}\n
\n\n

But that also doesn't work.

\n\n

Any help on this?

\n", "Lable": "No"} {"QuestionId": 21767161, "AnswerCount": 1, "Tags": "", "CreationDate": "2014-02-13T22:44:15.853", "AcceptedAnswerId": null, "Title": "How do I pass a spring expression language evaluation as an argument?", "Body": "

This isn't working:

\n\n
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<beans xmlns=\"http://www.springframework.org/schema/beans\" \n    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n    xmlns:encryption=\"http://www.jasypt.org/schema/encryption\"\n    xsi:schemaLocation=\"http://www.springframework.org/schema/beans\n                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd\n                        http://www.jasypt.org/schema/encryption\n                        http://www.jasypt.org/schema/encryption/jasypt-spring31-encryption-1.xsd\">\n\n    <import resource=\"properties/secure/jasypt-context.xml\" />\n    <bean name=\"propEnvironment\" class=\"java.lang.String\">\n        <constructor-arg value=\"#{ systemProperties['property.environment'] ?: systemProperties['cfg.environment'] }\" />\n    </bean>\n    <encryption:encryptable-property-placeholder \n        encryptor=\"configurationEncryptor\"\n        location=\"classpath:properties/#{propEnvironment}/*.properties,classpath:properties/common.properties\" />\n\n</beans>\n
\n\n

Only common.properties gets configured by the encryptable property placeholder. It's like the other entry just disappears (no error is thrown or anything, it just doesn't load anything else). I want to stand up an instance with the production config files, but I want to use my dev properties. The spel expression is evaluating properly if I print that out. Is this possible?

\n\n

When I try this,

\n\n
<bean name=\"propEnvironment\" class=\"java.lang.String\" id=\"testing\">\n    <constructor-arg value=\"#{ systemProperties['property.environment'] ?: systemProperties['cfg.environment'] }\" />\n</bean>\n<bean name=\"fullString\" class=\"java.lang.String\">\n    <constructor-arg value=\"classpath:properties/#{ systemProperties['property.environment'] ?: systemProperties['cfg.environment'] }/*.properties\" />\n</bean>\n<bean class=\"EchoBean\" lazy-init=\"false\">\n    <constructor-arg ref=\"propEnvironment\" />\n</bean>\n<bean class=\"EchoBean\" lazy-init=\"false\">\n    <constructor-arg ref=\"fullString\" />\n</bean>\n<bean class=\"EchoBean\" lazy-init=\"false\">\n    <constructor-arg value=\"#{@testing.toString()}\" />\n</bean>\n<bean class=\"EchoBean\" lazy-init=\"false\">\n    <constructor-arg value=\"blah\" />\n</bean>\n
\n\n

The third echo using the @ syntax does not produce any output.

\n\n
2014-02-14 10:03:41,998 [main] INFO  EchoBean - local\n2014-02-14 10:03:42,000 [main] INFO  EchoBean - classpath:properties/local/*.properties\n2014-02-14 10:03:42,000 [main] INFO  EchoBean - blah\n
\n", "Lable": "No"} {"QuestionId": 21783137, "AnswerCount": 7, "Tags": "", "CreationDate": "2014-02-14T15:23:27.910", "AcceptedAnswerId": null, "Title": "Default camel case of property names in JSON serialization", "Body": "

I have a bunch of classes that will be serialized to JSON at some point and for the sake of following both C# conventions on the back-end and JavaScript conventions on the front-end, I've been defining properties like this:

\n\n
[JsonProperty(PropertyName=\"myFoo\")]\npublic int MyFoo { get; set; }\n
\n\n

So that in C# I can:

\n\n
MyFoo = 10;\n
\n\n

And in Javascript I can:

\n\n
if (myFoo === 10)\n
\n\n

But doing this for every property is tedious. Is there a quick and easy way to set the default way JSON.Net handles property names so it will automatically camel case unless told otherwise?

\n", "Lable": "No"} {"QuestionId": 21817378, "AnswerCount": 1, "Tags": "", "CreationDate": "2014-02-16T22:08:32.827", "AcceptedAnswerId": null, "Title": "Efficiently assign a row to a lil_matrix", "Body": "

How can I efficiently assign a row to a lil_matrix? I'm currently using:

\n\n
Q[mid, :] = new_Q\n
\n\n

where new_Q is the result of lil_matrix.getrow(x)

\n\n

I ran a test on using Q.getrow(i) vs. Q[i, :], and found the former to be 20x faster.

\n\n

Here's the lil_matrix documentation.

\n", "Lable": "No"} {"QuestionId": 21966096, "AnswerCount": 2, "Tags": "", "CreationDate": "2014-02-23T08:47:39.093", "AcceptedAnswerId": "21986967", "Title": "Publish AIR desktop application", "Body": "

This is what the users of my desktop application see when they launch my AIR installer.

\n\n

What should I do?

\n\n

\"Do

\n", "Lable": "No"} {"QuestionId": 21974347, "AnswerCount": 0, "Tags": "", "CreationDate": "2014-02-23T20:51:53.720", "AcceptedAnswerId": null, "Title": "Combining two sequential backend responses to construct the frontend response", "Body": "

Netty 4.0 server that makes two outbound requests for every incoming request, and uses the responses of the outbound requests to form the response to the original inbound request. Outbound 1 response is used to build Outbound 2 request if successful.

\n\n

See diagram here: https://twitter.com/puffybsd/status/437652876928626688/photo/1

\n\n

Here's what I'm doing now (just a test with 1 remote host):

\n\n
    \n
  1. Create a standard ServerBootstrap with a pipeline that contains a SimpleInboundChannelHandler<FullHttpRequest> call it HandlerA.
  2. \n
  3. When HandlerA receives a channelActive event, create a new Bootstrap, register a new Handler, HandlerB, open the connection to the 1st remote host and store the channel ChannelB in a variable of HandlerA.
  4. \n
  5. When HandlerA receives a read0 event, extract parameters from the FullHttpRequest object, build a FullHttpResponse object and store it in an attribute of the ChannelB variable along with the current context.
  6. \n
  7. Send a request to the first remote host.
  8. \n
  9. When HandlerB receives a FullHttpResponse from remote host 1, extract the original context and FullHttpResponse object from the ChannelB attribute set.
  10. \n
  11. Update the FullHttpResponse and write it to the original context's channel.
  12. \n
\n\n

This appears to work. Haven't added the 2nd remote host call yet. The two backend remote hosts do not change - they're always the same addresses. What it appears to be doing is opening a socket to the backend when there's a new client request, sending a request to the backend, then sending a response to the client when a response from the backend is received.

\n\n

Here's some code:

\n\n
public class MainIncomingRequestHandler extends SimpleChannelInboundHandler<FullHttpRequest> {\n   private Channel outboundChannel;\n\n   @Override\n   public void channelActive(final ChannelHandlerContext ctx) throws Exception {\n\n         Bootstrap bootstrap = new Bootstrap();\n         bootstrap.group(ctx.channel().eventLoop());\n         bootstrap.channel(ctx.channel().getClass());\n         bootstrap.handler(new IncomingResponseHandler());\n\n         outboundChannel = channelFuture = bootstrap.connect(host, port).channel();\n    }  \n\n    @Override\n    public void channelRead0(final ChannelHandlerContext ctx, FullHttpRequest msg)\n        throws Exception {\n        //create a response object.\n\n        //save the response to the outboundChannel's attribute map.\n        outboundChannel.attr(CONTEXT_KEY).set(ctx);\n        outboundChannel.attr(RESPONSE_KEY).set(response);\n\n        //create a request and write it to the outboundChannel.\n        outboundChannel.writeAndFlush(req);\n    }\n}\n\npublic class IncomingResponseHandler extends SimpleChannelInboundHandler<FullHttpResponse> {\n\n    @Override\n    protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse inboundResponse)\n        throws Exception {\n\n        //extract data from the remote response.  \n        //...      \n\n       //fetch the original context and response from the channel attributes.\n       ChannelHandlerContext ctx = ctx.channel().attr(CONTEXT_KEY).get();\n       FullHttpResponse response = ctx.channel().attr(OUTBOUND_RESPONSE_KEY).get();\n\n       //update the outbound response with results from the inbound response.\n       //...\n\n       //send the response to the original inbound request.\n       ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);\n\n    }\n}\n
\n\n

Here are the questions:

\n\n
    \n
  1. Will creating a new Bootstrap client for each active channel reuse underlying connections?
  2. \n
  3. Is there a risk that responses get tied to the wrong incoming request? (I think not due to http rules, but not 100% sure).
  4. \n
  5. Is there an easier way to do it?
  6. \n
  7. How should errors and timeouts be handled, particularly clean-up?
  8. \n
  9. Is there an end-to-end example other that SocksProxy and HexDumpProxy? This seems like an extremely common use case.
  10. \n
\n", "Lable": "No"}