pty 882 Posting Pro

Sorry if I didn't make it clear. When I refer to 'additional logic', I mean checking that the API's response is suitable for the user making the request.

There are two scenarios in your example, generally listing and viewing user profiles and viewing and modifying your own profile. It makes sense from an API point of view and a code-organisation point of view to split these between two controllers. Requests to /users/20 and /users/~ will be routed to the same place (by every router I've worked with, at least!), because the paths match; the only difference is the parameter on the end (20 vs ~). This means you'd need additional code to cope with the params and react accordingly.

To attempt to clarify what I mean, here's a quick example of how a single controller that's trying to perform both roles might look. Note how inside #update and #show, there's additional logic that makes the controller more difficult to understand because it no longer has a single responsibility.

If we split that functionality into two, we have two simple controllers; the user controller that only provides allowed actions and the profile controller that only has access to the currently logged-in user.

If you're also building a web interface on top of (or to compliment) this API, it makes even more sense, because you want to serve a different page for someone visiting their own profile vs visiting someone elses. Again, it's simpler and cleaner to do …

pty 882 Posting Pro

Incidentally, in my previous post the profile's POST line should have been a PUT or PATCH; you'd assume that every user has one and shouldn't be able to create another.

The difference, I guess, is that users/1 returns the results as a collection while users/~ returns a singular resource, us. Is that what you were referring to?

Not exactly. /users/~, or /users/{my_id} is fine for accessing my profile page, but it's also the way you'd access anyone else's profile page.

This approach means you'd need additional logic in the views (and checks in the controller) to display things that only a user can do to themselves, such as modify personal details, update profile picture, view their own event log, etc.

This makes the functionality more difficult to write, test and maintain, because the action isn't specific.

Splitting it out makes both sides simpler.

Also, I agree, /me sounds better than /profile, but /me/cv sounds odd. What is the profile component? Does a user only have one?

There are only two hard things in Computer Science: cache invalidation and naming things. - Phil Karlton

pty 882 Posting Pro

For the most part I'd say it looks ok.

The tilde in some of the currently-OAuthed user routes doesn't 'feel' right to me, though. The current user (or you), and the current user's CV (your CV) are both singular resources; you already know their ID if they are authenticated so you needn't treat them as if they are a collection:

GET  profile
POST profile
GET  profile/cv
POST profile/cv
pty 882 Posting Pro

I'm not sure exactly what you'll be visualising, so it's difficult to suggest anything, but I'm sure that d3 will have you covered. It's immensely powerful and incredibly well-designed.

pty 882 Posting Pro

I use snippets heavily. For non-work stuff, Github's gists are perfect. You can add multiple files to a single gist (which would help if some of the code you're pasting is spread across a model, controller and view), and everything's syntax highlighted.

Github allows gists to be embedded. Perhaps this would be a better approach than creating one from scratch. To build anything with that kind of functionality that people will actually want to use is a project in itself.

pty 882 Posting Pro

So two things are happening here, first you're searching for a row and if you find one, you're updating the timestamp (and if not, doing an insert). It's unlikely that it's the insert that's slow, so let's check the query first:

explain select *
from articles_read
where member_id = 314062
and article_id = 507257;

The output should indicate whether or not your index is being used. If it's not, you need to look at why. If it is, then it might indiacate that the update (or insert) is slow. I suspet it's the former, so try the above and if that's not the problem we can look in more depth at the inserting/updating

pty 882 Posting Pro
   select * from company where has_made_profit_every_year_for_the_last_five_years = 1;

Hope this helps.

rproffitt commented: I understand this line of thinking. +11
pty 882 Posting Pro

To clarify, I think @jkon was making a joke. SOAP was a nightmare at the best of times and unusable at the worst, and I'm glad I've not had to deal with WSDL in years.

Keeping an interface simple, RESTful and documenting it with Swagger or Stoplight is a much better idea.

pty 882 Posting Pro

I'm no PHP expert, so forgive my ignorance.

If you test in a basic manner, rather than by using AJAX, what happens? By using your browser's inspector, you can see that doing:

$.ajax({
  url: "my_service",
  data: {f_date1: "yesterday", t_date1: "today"},
  success: function(msg) {
    console.debug("yay")
  }
});

will result in a GET request like this:

my_service?f_date1=yesterday&t_date1=today

If you paste that into a browser's URL bar (or better yet use something like HTTPie or Postman), you can make sure that you can access the query string properly. Once you know that works, and you know that jQuery's .ajax method does the same thing, you'll have a much better chance at solving your problem.

pty 882 Posting Pro

Also, you shouldn't need to use suffixes to identify object types. Tb is already inconsistent; your link tables don't have it, but what if you add a link table with another attribute?

pty 882 Posting Pro

I was going to help, but rather than just help you in the way that you want (that'd be too boring) I thought I'd give the answer in Ruby.

[2,4,6,3,2,4,3,8]
  .group_by{|i| i}
  .select{|_,matches| matches.count > 1}
  .keys

=> [
    [0] 2,
    [1] 4,
    [2] 3
]
pty 882 Posting Pro

Is reporting the only reason you need this number? If that's the case, remove it from your application and add it to your report. In PostgreSQL you an use a window function for this, but in MySQL do something like this. Imagine you have a table of names:

create table people (id int primary key auto_increment, name varchar(20)) ;

insert into people (name) values ('John'), ('Paul'), ('George'), ('Ringo');

Now, you want them numbered by something other than the id:

select
  (@i := @i+1) as number,
  id,
  name
from people, (select (@i := 0)) j
order by name desc;

    | number | id |   name |
    |--------|----|--------|
    |      1 |  4 |  Ringo |
    |      2 |  2 |   Paul |
    |      3 |  1 |   John |
    |      4 |  3 | George |

There's a better example here.

Providing your query is constructed properly and is only selecting records from a particular day, and your results are ordered, your results will be the same every time. Plus, your application is simpler, you have fewer columns and you won't run into transaction-related bugs.

pty 882 Posting Pro

@hinaraees I'll show you what you need to know. Just send me your Facebook login and password and I'll send you everything you need!

rproffitt commented: Better yet, just post it here so all of us can contribute. +11
pty 882 Posting Pro

What probably happened is that your customer created an order, then while the above code was running they created another. As you're using max to work out which number to allocate and you've not yet saved the first record, both have the same id. Without knowing your transaction isolation level I can't say why your sequence looked correct.

Rule of thumb, for automatically generating numbers, use a sequence (known as auto increment in MySQL). Also, if your ids are meant to be unique, consider making that column a primary key; if not use a unique index.

pty 882 Posting Pro

Yes, we purposefully don't support tables.

Ah, what's the reasoning behind that? It doesn't need to be provided by the editor, but in some cases it makes a post much easier to read.

pty 882 Posting Pro

Incidentally, in my earlier post, I used Rails-esque route notation :group_id and :membership_id. In case it's not obvious, that's where your identifiers would go, so the actual path would be /groups/1/memberships/3 (or if you prefer slugs, /groups/admin/memberships/joey)

pty 882 Posting Pro

Perhaps what I am doing, however, is creating a new membership record?

This is correct, but when you're posting to /groups/memberships, to which group are you adding a member?

I'd expect to see something more like this. Of course, you don't need all of these actions (i.e. updating a membership, which is probably just a record in a link table, might not be necessary) but it's obvious at every point what each action does.

GET    /groups/                                     get a list of all groups
POST   /groups/                                     create a new group
GET    /groups/:group_id                            get an individual group :group_id
PUT    /groups/:group_id                            replace group :group_id
PATCH  /groups/:group_id                            modify group :group_id
DELETE /groups/:group_id                            delete group :group_id

GET    /groups/:group_id/memberships                get a list of members for group :group_id
POST   /groups/:group_id/memberships                create a new membership for the group (i.e. add a member)
GET    /groups/:group_id/memberships/:member_id     get an individual membership :member_id for group :group_id
PUT    /groups/:group_id/memberships/:member_id     replace membership :member_id
PATCH  /groups/:group_id/memberships/:member_id     modify membership :member_id
DELETE /groups/:group_id/memberships/:member_id     remove membership :member_id from group :group_id

Also, it would appear that your Markdown implementation doesn't support tables! :)

pty 882 Posting Pro

I suggest you use the HTML Agility Pack rather than attempting to use loops, counters and .IndexOf. It will allow you to use XPath which will be more efficient and require less complex code to achieve. Or, if you're doing this as a one off, copy it into a .csv file and use the standard tools.

Also, pasting a wall of unformatted HTML isn't going to help anyone. Either link to a gist or use the 'Code' button above to make it somewhat readable. If it still looks like a wall of text, use html tidy first.

pty 882 Posting Pro

I doubt it's your query that's slow. What happens if you simply run the query select * from Doopgegevens; in a shell? For ~10k rows, providing your table is holding 'normal' data (and not base64 encoded movie files or something) it should be fast. If it is fast, try changing your data list to only use a subset of your table's columns, which will indicate if that's where your performance problem is.

pty 882 Posting Pro
pty 882 Posting Pro

So, the two obvious options are to modify MySQL's collation to utf8mb4. Clearly this is a big task and there's potential risk, for something of such minimal priority it's not worth it. The easier and lower friction way is to strip out offending characters before saving.

pty 882 Posting Pro

Here is how the post looked when I submitted it.

pty 882 Posting Pro

It's ok, was only a paragraph. I believe what happened is a result of MySQL's encoding. Let's try it in this comment...

Nerd emoji will follow this line

pty 882 Posting Pro

I've made a couple of lengthy posts over the last couple of days and have noticed a few bugs with the editor. Nothing show-stopping but some make the editing process more difficult or some content vanish! (I added the 'nerd' Emoji in one of my posts, it saved without errors but all subquent content in the post was missing!). Rather than me add them here, is there a tracker somewhere so they can be categorised, verified and dealt with? If there is, I'm happy to post detailed steps, screenshots, even animated gifs if that gives whoever will be looking at it a better chance :)

pty 882 Posting Pro

It sounds like you aren't working to the strengths of the database. MySQL, unlike Oracle, PostgreSQL etc doesn't support arrays, and searching on text is unlikely to be optimal.

I don't know the context of the original query, so it's difficult to suggest a solution, but it could be something like this:

 Tags:
 - id: 1
   name: Programming
 - id: 2
   name: Databases
 - id: 3
   name: Web Development
 - id: 4
   name: Floristry
 - id: 5
   name: Kids TV

 Posts:
 - id: 1
   name: Making pages faster
   tags: [1, 2, 3]
 - id: 2
   name: CBeebies top ten
   tags: [5]

So, to find all posts about Web Development you'd look through all of the posts, filtering on the tags field for the inclusion of 5. In PostgreSQL, using the array type, we'd do something like this:

select * from posts;
┌────┬──────────────┬─────────┐
│ id │     name     │  tags   │
├────┼──────────────┼─────────┤
│  1 │ CBeebies     │ {5}     │
│  2 │ Fast Website │ {1,2,4} │
│  3 │ Programming  │ {4,6}   │
└────┴──────────────┴─────────┘
(3 rows)

Time: 0.282 ms
peter=# select * from posts where tags @> '{5}';
┌────┬──────────┬──────┐
│ id │   name   │ tags │
├────┼──────────┼──────┤
│  1 │ CBeebies │ {5}  │
└────┴──────────┴──────┘
(1 row)

That's fine, but that doesn't give you the benefits of using a relational database. What if someone deletes the Kids TV tag from the tags table? Well, our arrays (or strings full of comma separated values) will point to nothing. That's precisely …

cereal commented: nice explanation, thanks for sharing! +14
pty 882 Posting Pro

It would appear that the leak is available; the reason I logged in after quite a break was that I received an email from haveibeenpwned.com telling me that:

You've been pwned!
You signed up for notifications when your account was pwned in a data breach and unfortunately, it's happened. Here's what's known about the breach:

Email found: xxxxxxxxx@gmail.com
Breach: DaniWeb
Date of breach: 1 Dec 2015
Number of accounts: 1,131,636
Compromised data: Email addresses, IP addresses, Passwords
Description: In late 2015, the technology and social site DaniWeb suffered a data breach. The attack resulted in the disclosure of 1.1 million accounts including email and IP addresses which were also accompanied by salted MD5 hashes of passwords. However, DaniWeb have advised that "the breached password hashes and salts are incorrect" and that they have since switched to new infrastructure and software.

pty 882 Posting Pro

Remember that UNION (and its cousins INTERSECT and EXCEPT) essentially require each of the provided queries to be run separately and the results collated. In this example (using PostgreSQL, but the same applies in MySQL), we can see exactly what's happening.

I have a small table with some users and their favourite colours:

peter=# select * from users;
┌────┬─────────┬──────────────────┐
│ id │  name   │ favourite_colour │
├────┼─────────┼──────────────────┤
│  3 │ Francis │ blue             │
│  4 │ Toby    │ blue             │
│  1 │ Joey    │ red              │
│  2 │ Dwayne  │ purple           │
└────┴─────────┴──────────────────┘
(4 rows)

Time: 0.400 ms

Now, let's say we want all users with a favourite colour of blue or red; if we use a UNION the following happens:

peter=# explain select name from users where favourite_colour = 'blue' union select name from users where favourite_colour = 'red' ;
┌───────────────────────────────────────────────────────────────────────────┐
│                                QUERY PLAN                                 │
├───────────────────────────────────────────────────────────────────────────┤
│ HashAggregate  (cost=35.33..35.39 rows=6 width=58)                        │
│   Group Key: users.name                                                   │
│   ->  Append  (cost=0.00..35.31 rows=6 width=58)                          │
│         ->  Seq Scan on users  (cost=0.00..17.62 rows=3 width=58)         │
│               Filter: ((favourite_colour)::text = 'blue'::text)           │
│         ->  Seq Scan on users users_1  (cost=0.00..17.62 rows=3 width=58) │
│               Filter: ((favourite_colour)::text = 'red'::text)            │
└───────────────────────────────────────────────────────────────────────────┘
(7 rows)

Time: 3.868 ms

As you can see, the query plan involves

  • two sequental scans (Seq Scan) that each perform a Filter,
  • an Append operation which is actually performing the UNION,
  • plus Group Key and HashAggregate steps, from which the resulting recordset can be returned.
pty 882 Posting Pro

Threads should be automatically locked after a few months so idiots like luisin22 can't resurrect them in order to find an answer to a homework question that he's too lazy to do properly.

pty 882 Posting Pro

i'm sorry, its not fail but the records display is incorrect...

Incorrect? Incorrect how? Also, this is my last post on this topic, you clearly are either a troll or an idiot.

pty 882 Posting Pro

thanks for reply.
I try something like this to read record with range month and year.
Example from June, 2011 to June 2012

Select * from table where (YEAR(date1)>='$year1' AND MONTH(date1)>='$mon1') and (YEAR(TKH_date1)<='$year2' AND MONTH(TKH_date1)<='$month2')

i had test this. And run separately.

(YEAR(date1)>='$year1' AND MONTH(date1)>='$mon1')

For above code it run smoothly

(YEAR(TKH_date1)<='$year2' AND MONTH(TKH_date1)<='$month2')

But for this code, it fail....

TQ

Fails why? What error? What variables? Also, by calling YEAR(blah) you're going to bypass your indices and your query will be slow. Something like this is better and will work.

SELECT * FROM table WHERE date_data >= '2011-06-01' AND date_data < '2011-07-01';
pty 882 Posting Pro
SELECT * FROM table WHERE YEAR(date_data)= 2011 AND MONTH(date_data) BETWEEN 1 AND 4;

Or preferably:

SELECT * FROM table WHERE date_data BETWEEN '2011-01-01' AND '2011-02-01';
pty 882 Posting Pro

If you have a lot of internal software that utilises Exchange, Google Business Apps may not be what you're looking for. Depending on what this software does it may not work at all with Google Apps or you may need to change the way you work.

I have used Google Apps with the last company I worked at, though, and it is fantastic. You get the benefit of having everything 'looked after' hardware-wise by Google's team, the best webmail client available, POP3/IMAP access if required, excellent calendar, tasks, office apps, contacts directories etc.

pty 882 Posting Pro

This should help explain the differences between UNIX and Linux.

alaa sam commented: thanks alot +0
pty 882 Posting Pro

You can vastly simplify the granting of permissions by using groups/roles.

pty 882 Posting Pro

id is your primary key so it is already indexed

mysql> show indexes from artikulli;
pty 882 Posting Pro

Your text example doesn't really show how the script you provide works. Here's what you are probably after though - this could be a bit more robust but in this state it's clear:

#!/usr/bin/env/ruby

#first get the name
puts "Enter your name"
name =  gets
#now get a number, to_i returns the entered string (eg "5" to an integer eg 5)
puts "Enter a number"
number = gets.to_i

#times is a method on integer, we can use it to iterate through the block
number.times do 
  #print the name
  puts name
end
pty 882 Posting Pro

When will people realise that Jabber/XMPP is the future?

pty 882 Posting Pro

KDE is not supported because this is a LTS release; KDE 4 will be brand new when Ubuntu 8.04 is released and there is no guarantee that the KDE guys will still be writing security updates etc for KDE3.x releases in 3 years time.

It simply does not make sense to offer LTS on either a 'bleeding edge' KDE release or one that may not be actively developed soon.

Ubuntu has a Gnome focused release schedule; this is just a case of bad timing.

pty 882 Posting Pro
pty 882 Posting Pro

Linux has been doing pretty well in that arena for a long time.

pty 882 Posting Pro

First they laugh at us. Then they ignore us. Then they fight us. Then we win.

pty 882 Posting Pro

The furthest away wine can be is "sudo apt-get install wine". I just think that Mark Shuttleworth doesn't want people to buy a Dell/Ubuntu machine expecting all their Windows apps to work flawlessly; hopefully this will make people seek out a open alternative - usually there are a few options.

pty 882 Posting Pro

Is the installer on the minimal and universal disks a graphical one too? Or is it just the Live CD install (like Ubuntu)?

pty 882 Posting Pro

I think Dell shipping machines with Feisty pre-installed will have a relatively small impact on both Red Hat and Novell who aim more at medium-large businesses.

I just hope that Dell's customised Ubuntu will make it easier for the end user by coming with Flash and most commonly used codecs pre-installed. Dell's involvement should at least mean that wireless networking will work out of the box.

Also, it would be great if they didn't install the usual crap you get like AOL shortcuts etc.

pty 882 Posting Pro

Redhat have contributed more code than any other company to the Linux Kernel. They have made massive contributions to Gnome, GCC, GLIBC, SELinux, ext3.

They may have some closed source stuff (I'm not too sure about what or how much) but in comparison to other 'OS friendly' companies they have contributed a hell of a lot.

pty 882 Posting Pro

Some people want their software to be completely free in every meaning of the word. Others just want a functional computer.

If it weren't for people who fall into the former camp we the OSS landscape would not look how it does today.

pty 882 Posting Pro

I think you slightly misunderstood the press release.

Gutsy Gibbon will come with some binary firmware, drivers etc.

A new official 'varient' of ubuntu will be introduced that will contain none of the above. Something similar already exists; afaik the Gnewsense developers will assist with the new Ubuntu varient.

pty 882 Posting Pro

It will sell like hotcakes simply because Apple are so popular at the moment.

This is the thread on /. when the oringinal iPod came out.

FTA:

"At an invitation only event Apple has released their new MP3 player called the iPod. iPod is the size of a deck of cards. 2.4" wide by 4" tall by .78" thick 6.5 ounces. 5 GB HDD, 10 hr battery life, charged via FireWire. Works as a firewire drive as well. Works in conjunctions with iTunes 2. Here are Live updates". No wireless. Less space than a nomad. Lame."

pty 882 Posting Pro

I think that the most difficult aspect of Linux to most people is the install. Once its on (and all the hardware is working) doing most day to day things really aren't that hard. Even installing software is a breeze with tools like Ubuntu's add/remove applications thing (which I think is an simplified synaptic gui).

To the non-tech savvy I think a clean install of Windows is just as daunting as a install of Ubuntu/SuSE/Fedora.

Linux won't become mainstream any time soon but hopefully the slightly tech savvy people who a few years ago would just use pirate Windows discs may consider it as a legal alternative.

pty 882 Posting Pro

Its not like Apple haven't had chance to test it out; the beta has been out for years.

The question is, who will the average Joe who upgrades blame? Apple who left everything the same or Microsoft who made drastic changes?

Give it a couple of months and Steve Jobs will be making fanboys moist with his shiny new fully iTunes compatible OS.

I am a Mac owner. I'd be mighty peed off if my library of music got screwed up. I guess I'm glad my library is all MP3.