Nikola Brežnjak blog - Tackling software development with a dose of humor
  • Home
  • Daily Thoughts
  • Ionic
  • Stack Overflow
  • Books
  • About me
Home
Daily Thoughts
Ionic
Stack Overflow
Books
About me
  • Home
  • Daily Thoughts
  • Ionic
  • Stack Overflow
  • Books
  • About me
Nikola Brežnjak blog - Tackling software development with a dose of humor
Stack Overflow

How to pass GET parameters to jsFiddle

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My quesiton was:

How to pass GET parameters to jsFiddle? I tried http://jsfiddle.net/mKwcF/?id=123 but all I get ishttp://fiddle.jshell.net/mKwcF/show/

My example js is simple on a given link above:

alert(window.location.href);

The (updated) answer, by Jack Miller, was:

As of October 2014 it is a little more complicated than it used to be:

If your jsfiddle url is:

http://jsfiddle.net/u7G7n/41

Some code to make stackoverflow happy. Ignore this.

use instead (including some url parameters):

http://fiddle.jshell.net/u7G7n/41/show/light/?lat1=52&lng1=9&lat2=50&lng2=1

AND send the same url (including parameters) as referer. You can use Referer Control as Chrome plugin: https://chrome.google.com/webstore/detail/referer-control/hnkcfpcejkafcihlgbojoidoihckciin

And configure like this: enter image description here

Now the second link (including parameters) should work.

Stack Overflow

phpMyAdmin Class ‘PMA_Message’ not found in /usr/share/ phpMyAdmin/libraries/ Error.class.php

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My quesiton was:

I just got this error (no errors in phpMyAdmin for the last 2 years):

PHP Fatal error: Class ‘PMA_Message’ not found in /usr/share/phpMyAdmin/libraries/Error.class.php on line 24

I tried searching the net and links like

  • http://gnuwhatimsaying.com/phpmyadmin-error-class-pma_message-not-found/ (changing the ownership of /var/lib/php/session/ folder to apache:apache – it’s already set like that)
  • http://rakesh.sankar-b.com/2012/05/20/phpmyadmin-pma-message-class-not-found/ (quote: “I got a weird idea to see if the space is available for PHP to create sessions – gotcha, that is where my problem was. I cleaned up some unnecessary items and all went well.” – to be honest I don’t know what the author meant by this)

but none solved my issues, and strangely enough – these are only two links which pop up in the first 50 links of google search for this error. So, please shed some light on this.

Btw, the site which is hosted on this server works fine, DB works fine (mysql, login via SSH).

The answer, by Chris Muench, was:

I fixed this issue by restarting apache.

My comment on this answer was:

Thanks, in my case the reload was enough (service httpd reload)

Stack Overflow

Regular expression to match sets of numbers that are not equal nor reversed

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My quesiton was:

I am referring as a follow up on this question here: Regular expression to match two numbers that are not equal

Now my other question scenario is this:

P121324 - T  
P1212 - F - we got this covered in the message on link above (no same "sets")
P1221 - F - now new restriction -not even the reversed digits 12-21

But, the problem now is that the P string can be very long! – like this:

P121315162324

please notice this is ok since the “sets” are:

12131415162324

Now, I could make this in the code (PHP) by checking if there are repetitions, but I was wondering if this can be done with single regex command?

The answer, by Mark Byers, was:

Try this:

^P(?:([0-9])(?!\1)([0-9])(?!(?:..)*(?:\1\2|\2\1)))*$

If you want the digits to be restricted to [1-6] like in your previous question then change [0-9] to [1-6].

See it working online: rubular


Here is a breakdown of the regular expression:

^          Start of string/line.
P          Literal P
(?:<snip>) Non-capturing group that matches a distinct pair of digits. See below.
*          Zero or more pairs (use + if you want to require at least one pair).
$          End of string/line.

Explanation of ([0-9])(?!\1)([0-9])(?!(?:..)*(?:\1\2|\2\1)) – match one pair:

([0-9])    Match and capture the first digit. Later refered to as \1.
(?!\1)     Negative lookahead. The next character must not be the same as \1.
([0-9])    Match and capture a digit. Later refered to as \2.
(?!<snip>) Negative lookahead. Check that the pair doesn't occur again.

Explanation of (?:..)*(?:\1\2|\2\1) – try to find the same pair again:

(?:..)*       Match any number of pairs.
(?:\1\2|\2\1) Match either \1\2 or \2\1.
Stack Overflow

Best practice for C# calling PHP which then queries the database

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My quesiton was:

For some reason I have to have a windows client application (written in C#) which communicates with the PHP files that are on my server. Windows application can’t be allowed to have SQL queries in the code because of the possible disassembling of the exe file. This is the main reason why this approach is used.

Basically it looks like this: from windows client i call getResult.php which then opens the connection to the database, queries the database, returns the result to the client and closes the database connection. Therefore windows client doesn’t have any code for querying the database, it just has calls to the PHP file.

My several questions follow:
1. What is the best way to send request from c# code to the PHP file? (Cause I need to send this php file some parameters like ID, etc… -> I know I can do it with GET like this getResult.php?id=123456, but is this same possible with POST? And also, one question: how to do this in code? http requests or?)

2.Since every time I call the PHP file (there will be more files which I will call, like getResult.php, getStatus.php, etc…) I will somehow need to send login information to that PHP file with which that PHP will query the database. My question here is how to do this securely, and plus: is it maybe somehow possible to call something like doLogin.php and send the login username and password one time, and after that call this (and all other) php files without the need to send the login information as a parameter to the function. I know I can use PHP sessions when the whole application is on the server, but the main difference here is that I am only calling some files, executing them and closing the connection.

My main question is: is this ok from conceptual point of view or are there any commonly known concepts for this, for which I don’t know about – please advise I’m willing to learn. I did some research and do believe this might have to be done with web services approach, but please do reply your thoughts on this.

The answer, by Steve Mayne, was:

Your PHP code is effectively serving as a RESTful data-access API. Run your PHP on a webserver over SSL (HTTPS) so that all your comms are encrypted.

You could either use trusted certificates to authenticate the client, or if you require different access levels, submitting a username/password to get an authorisation token for the data-access requests is not a bad idea.

Here is an example from Yahoo!: http://developer.yahoo.com/dotnet/howto-rest_cs.html

But, another good answer was from user Tom Glenn:

For a simple GET you can do:

var webClient =newWebClient();
webClient.DownloadString("http://someurl.com/somescript.php");

You could then return perhaps an XML or JSON formatted response from the PHP script? You can use WebClient for POST too.

As for the login, you can do that too. I do a similar thing in one of my applications. We send the login details to the script (ASP.NET not PHP) and the ASP page returns an XML response telling the C# app whether or not it was successful – the application can then decide whether it is allowed to continue or not.

Stack Overflow

How to serialize everything but the checkbox elements in jQuery.serialize()?

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My quesiton was if there is a way to serialize all form elements using serialize() function except the checkboxes?

The answer, by Simeon, was:

The .serialize() method can act on a jQuery object that has selected individual form elements, such as<input>, <textarea>, and <select>.

You could do this:

var s = $('#post-form').find('input, textarea, select').not(':checkbox').serialize()
Stack Overflow

How to get Disk Space Usage and Monthly Bandwidth Transfer from cPanel to my website in PHP

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My quesiton was:

I’m wondering how can I show (get) disk space usage and monthly bandwidth transfer on my website in the same way as it’s shown when I login to my cPanel account. Is there an api from cPanel for this or is this a general method to do so? I’m using PHP.

This answer, by user richsage, was:

cPanel/WHM has an API which offers access to both the elements you’re looking for. See the API docsfor more details. The bandwidth and disk usage modules in API 1 output HTML, however API 2 has anaccount summary method which will return the diskused parameter in the appropriate format (XML/JSON as requested).

Stack Overflow

Is there an event just before the radio button is about the be checked?

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My quesiton was:

This is the part of the code for one of the radio buttons:

$("#new").click(function(){
    if( $('#new').is(':checked') )
        $.jGrowl("You already have this option selected!", life: 1500});
    else
        changeOption(1);
});

Now, I understand that the else part will never run, because the radio button will be already checked on click event. What I’m wondering is, is there an event which would let me capture the state of the radio button (which is about to be clicked) and therefor determine if he is not yet clicked, and if so change the option to this newly selected one.

The answer, by JOPLOmacedo, was:

Use the mouseup event instead.

$("#new").mouseup(function(){if( $('#new').is(':checked'))
        $.jGrowl("You already have this option selected!", life:1500});else
        changeOption(1);});

The fiddle.

Edit
Even though the mouseup event works, it seems more logical to use the mousedown event. Here’s that fiddle.

Stack Overflow

WebBrowser control that can handle HTTPS

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My quesiton was:

I am searching for a substitute of the WebBrowser control in .NET which can handle HTTPS. This question is similar here on Stack Overflow, but none of these controls offer HTTPS.

btw, just to mention, I tried all these

GeckoFx – development stopped
Se7en – this is actually continued GeckoFx
Webkitdotnet – no one replying on forum

but none of them support HTTPS, so I’m kind of stuck here :/.

Also, to mention, WebBrowser control that comes with .NET framework works just fine with HTTPS, but the reason I can’t use it is because my app uses a lot of javascript that IE refuses to render, and for example Firefox (gecko engine) or Chrome (webkit) work just fine.

So, please if someone knows a good control that can do this (can be Webkit or Gecko wrapper, it doesn’t mind, as long as it’s not an IE wrapper).

This one I answered myself:

After long googling I finally ended up using the same as I was using before. So Webkit fromhttp://sourceforge.net/projects/webkitdotnet and I ended up purchasing a SSL certificate for my domain and now all is fine.

Stack Overflow

What is the difference between $(window) and window in jquery/javascript

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My quesiton was:

What is the difference between javascript window and jquery $(window)?

I tried in the Chrome console and I get this: enter image description here

So, I would conclude is “just” a window object wrapped in a jquery object in a way that then I can use jquery’s functions on it (like height(), width(), etc…)

The answer, by user Elias Van Ootegem was:

When you write $(window), you should know that that piece of code is going to run on the JS engine. Ever why jQ objects all have parentheses around them? Simple because $ is a function object. Basically you’re calling the $ function, and passing the native global, or window object to it as an argument.

If you browse through the jQ source code, you’ll see that it’ll pass that object on to many internal functions and in the end, it’ll return a jQ wrapper object.
So yes, your assumptions are pretty much correct.

Stack Overflow

tmhOauth twitter api stopped working with update_with_media call

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My quesiton was:

So, this morning I got the following error:

{"errors": [{"message": "The Twitter REST API v1 will soon stop functioning. 
Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.",
"code": 68}]}

Since I was using the tmhOauth twitter api I went to look if there are updates for it, and as it seems there is an issue listed here.

I’m using the api to update the status with media like this:

$code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
        array(
            'media[]'  => "@{$image}",
            'status'   => "{$text}"
        ),
        true, // use auth
        true  // multipart
);

I found notes that I should just change the link to use 1.1 instead of 1 but it’s still not working.

I actually answered this one my self after finding the solution:

My main problem was that I didn’t read the docs fully! While the change in the url from 1 to 1.1 was sufficient I missed the point by not looking that the new url for update_with_media, as explained in thedocumentation, is https://api.twitter.com/1.1/statuses/update_with_media.json, namely it’s api instead of the old upload subdomain.

So, now my api call looks like this and all works again:

$code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json',
        array(
            'media[]'  => "@{$image}",
            'status'   => "{$text}"
        ),
        true, // use auth
        true  // multipart
    );

Hope this helps someone.

Page 7 of 9« First...«6789»

Recent posts

  • Discipline is also a talent
  • Play for the fun of it
  • The importance of failing
  • A fresh start
  • Perseverance

Categories

  • Android (3)
  • Books (114)
    • Programming (22)
  • CodeProject (35)
  • Daily Thoughts (77)
  • Go (3)
  • iOS (5)
  • JavaScript (127)
    • Angular (4)
    • Angular 2 (3)
    • Ionic (61)
    • Ionic2 (2)
    • Ionic3 (8)
    • MEAN (3)
    • NodeJS (27)
    • Phaser (1)
    • React (1)
    • Three.js (1)
    • Vue.js (2)
  • Leadership (1)
  • Meetups (8)
  • Miscellaneou$ (77)
    • Breaking News (8)
    • CodeSchool (2)
    • Hacker Games (3)
    • Pluralsight (7)
    • Projects (2)
    • Sublime Text (2)
  • PHP (6)
  • Quick tips (40)
  • Servers (8)
    • Heroku (1)
    • Linux (3)
  • Stack Overflow (81)
  • Unity3D (9)
  • Windows (8)
    • C# (2)
    • WPF (3)
  • Wordpress (2)

"There's no short-term solution for a long-term result." ~ Greg Plitt

"Everything around you that you call life was made up by people that were no smarter than you." ~ S. Jobs

"Hard work beats talent when talent doesn't work hard." ~ Tim Notke

© since 2016 - Nikola Brežnjak