-12

Is there any Stack Exchange site where people can post solutions they found for they faced, particularly if they think it's the best solution for a specific problem?

For example, I needed to exchange all elements of a list (using all combinations) only having the initial order, and I found this solution:

PHP for the elements that must to spin (the i class=btn-info element is the element that trigger the spin function)

<div id="element-<?=$id; ?>" data-order="<?=$order; ?>" >
    <i class="btn-info fa fa-refresh" data-id="<?=$id; ?>" data-function="true" data-action="spin"></i>
    <ul class="soc" id="onspin-<?=$id; ?>">
        <li id="title<?=$id; ?>">element-1</li>
        <li id="<?=$type.$id;?>">element-2</li>
        <li id="text<?=$id;  ?>">element-3</li>
        <li id="area<?=$id;  ?>">element-4</li>
    </ul>
</div>

Javascript for the action button (The i class btn-info has a attribute data-function="true", and data-action="spin" for this reason the spin function is called. This is made in this way because these elements are request by AJAX -but the javascript is load with the document-)

jQuery(".panel-body").on("click", '[data-function="true"]', function(){
    eval(jQuery(this).attr("data-action"))(jQuery(this).attr("data-id"));
});

Javascript for the spin function

function spin(id)
{
    obj     = jQuery("#element-"+id);
    it      = 0;        
    if(!(old = obj.data("old-order")))
        old  = obj.data("order").split(",");
    else
    {
        it   = parseInt(obj.data("iter"));
        old  = old.split(",");
    }
    order   = "";
    del  = old[it%old.length];
    n_or = obj.data("order").split(",");
    for(var i=0; i<n_or.length; i++)
    {
        if(n_or[i]==del)
        {
            del_aux = jQuery('#'+n_or[i]+id);
            i_aux = i;
        }
        else    
            order += n_or[i] + ",";
    }
    order += n_or[i_aux];
    jQuery("#onspin-"+id).append(del_aux);
    obj.data("old-order",jQuery("#element-"+id).data("order"));
    obj.data("iter", it+1)
    obj.data("order",order);
}
4
  • 8
  • 5
    "solutions they found for they problems wich ones this people thinks that had been the best solution for a determinate problem??" - I'm sorry, what? If you just want to share code you've written, get an account on e.g. GitHub.
    – jonrsharpe
    Aug 5, 2015 at 13:41
  • 3
    I am sorry but I don't understand the question. Can you please elaborate a little more? Aug 5, 2015 at 13:47
  • 1
    I fairly heavily edited your first sentences @Eloy. Please have a look and see if it still says what you intended to say. If not, feel free to roll back my edit.
    – Bart
    Aug 5, 2015 at 14:45

1 Answer 1

10

Solutions are not found in isolation. Solutions are the result of a problem you faced. So if you feel you have come upon something particularly insightful, surely you can tell us what the non-trivial problem was that it solves. That's where self-answered questions come into play.

Wait a minute. Come back. Don't rush to post every snippet you think is great. Don't treat the Q&A as your personal blog or collection of Github Gists.

The basis of your self-answered question still needs to be the question. If the question you're asking isn't great, or if it's even a duplicate, no matter how wonderful your solution is, you still risk downvotes and closure of the question. So before you post it, make sure the question is actually good, non-trivial and hasn't been asked before.

3
  • The 15 rep limit for self-answers is way too low.
    – false
    Aug 5, 2015 at 14:53
  • 1
    cough feature request cough @false
    – Bart
    Aug 5, 2015 at 14:54
  • Not yet, it seems there is currently this "let's be very, very nice" tide.
    – false
    Aug 5, 2015 at 14:56

Not the answer you're looking for? Browse other questions tagged .