So, vim users have https://github.com/kien/rainbow_parentheses.vim
Emacs users have http://www.emacswiki.org/emacs/RainbowDelimiters
Is there something similar for users of Sublime Text (2 or 3?)
I already have bracket highlighter, which lets me highlight the innermost brackets, but I edit a lot of complex SQL in sublime text 3, and sometimes lose track of my parentheses. Can you edit the configuration files for this to match the behavior of the others?
Bracketeer allows you to perform operations on brackets, but I'd like to just see them in colors.
As requested, some example sql:
Select
name,
sum(cost) as total_cost,
count(*) as count
from
personnel p,
order o
where
p.prsnl_id = o.prsnl_id
and o.prsnl_id in (
Select prsnl_id
from
organization_personnel_relation
where
org_id in (Select org_id from organization_personnel_relation where prsnl_id = (Select prsnl_id from personnel where prsnl_name = 'test')))
and cost is not null
group by name
order by total_cost desc
limit 50;
I know it's not super deep nesting, but there are cases where I do see very deep nesting of parentheses, and I still would like to learn a lisp one day.
Here is another similar package:
This plugin [RainbowBrackets] I wrote for SublimeText is to
highlight brackets. It matches brackets you have added for the file
type, then gives brackets at different levels different colors, in the
cycle of the number of colors. colors are gave in the settings file,
by default, there are 7 type of colors.
(github repository)
This isn't ideal, but you can make sure you have the following settings:
"match_brackets": true,
"match_brackets_angle": true,
"match_brackets_braces": true,
"match_brackets_content": true,
"match_brackets_square": true,
And then when you are in a paren or bracket, the corresponding one will be highlighted.
This package seems like what you were looking for:
Rainbowth is a Sublime Text 3 plugin that automagically
highlights matching parentheses, brackets, and curly braces in source
code. While the name does imply a certain sequence of colors, the
palette used to paint them is entirely configurable
(github repository)
Related
I've implemented a page with a long list of subojects.
Every object contains one article (title + url) and N tags. I'd like to group by tag and show the count of articles related to that tag.
Something like:
SELECT tag, count(distinct article)
GROUP BY tag
I found an answer but it's very generic and I'd also like to document the solution for other user with the same problem.
As you know from previous answers to this question, you cannot have a "distinct" function from an SMW ask query.
My preferred solution is to use the "arrays" extension, that allows you to access PHP array manipulation functions in wiki code. Further than "distinct" list of value, its an irreplaceable tool for handling semantic data from queries.
You can create an array with the following function :
{{#arraydefine: *identifier* | *data* | *delimiter* | *parameters* }}
Identifier is the variable name you want.
Data is the array content, in SMW context, you load it with a query result content.
Delimiter specify the array delimiter relative to data. This have to be
coherent with the delimiter chosen in the ask query.
Parameters is where the magic appends. You can set a "unique" parameter, reducing the data list to unique values, thus, emulating the "distinct" function.
In tour case, you may do something like :
{{#arraydefine:tags
| {{#ask:[[-Has subobject::{{FULLPAGENAME}}]]
|?Tags#-=
| mainlabel=-
|limit = 1000
}}
|,
|unique
}}
Note that SMW ask query are, by default, limited to 50 results. Adding "limit=" adjusts the maximum result size.
At this point, you defined an array called "tags" containing all distinct values of this property.
You can use arrayprint function for any further data treatment or display.
I have 3 tables:
color: fixed list of original color names and their HEX.
store_color: custom color names (optional). For example if you want the color red to be call "deadpool red"
store_product_color: colors associated to a specific product ID.
This is the query causing the issue:
SELECT
store_product_color.id AS id,
store_product_color.id_color AS id_color,
color.hex AS hex,
IFNULL(store_color.name, color.name) AS name
FROM store_product_color
JOIN color ON color.id_color = store_product_color.id_color
LEFT JOIN store_color ON store_color.id_color = store_product_color.id_color
WHERE store_product_color.id_product = 176
ORDER BY store_product_color.id_color
It returns the id of the product association (primary), the id of the color, the color hex, and if a custom name exists, it should be used, else, use the original color name.
The query works perfect in my dev environment:
MySQL 5.6.25
Here comes the tricky part. The production environment uses another version of MySQL and the results vary from the dev environment. Instead of choosing between the custom and original color name, it creates 2 different rows, one for each name.
MySQL 5.6.30
I also tried removing IFNULL(store_color.name, color.name) AS name and adding store_color.name AS name2, color.name AS name1 but the issue remains.
I was unable to replicate this issue in sqlfiddle or db-fiddle. I added a live example, but it works fine just like it does on my dev environment: https://www.db-fiddle.com/f/25J8Kh8m8GSoHzw9MUJ67M/2
What can be causing this issue and how do I solve it? Thanks!
I have a spreadsheet/csv:
Code:,101,Course Description:,"Introduction to Rocket Science",
Student Name,Lecture Hours,Labs Hours,Test Score,Status
John Galt,48,120,4.7,Passed
James Taggart,50,120,4.9,Passed
...
I need to reshape it to the following view:
Code:,Course Description:,Students,Lecture Hours,Labs Hours,Average Test Score,Teaching Staff
101,"Introduction to Rocket Science",John Galt,48,120,4.7,Passed
101,"Introduction to Rocket Science",James Taggart,50,120,4.9,Passed
...
Beleive it or not, can not get the right idea how to do that despite it seems to be very primitive transformation, is there any silver bullet for this?
Original records (csv) have in a way json-like structure so my first approach was to represent the original data as a vector and then transpose it, (but in this case my resulting table looks like sparced matrix - rows I have transpored are blank in the rest of its values)
Another way Im considering - **serialize it into jsons and then de-serialize** into new spreadsheet (jsonize()) - in this case, Im having problems with merging them properly.
In both ways I have it "half-working";
Can anyone suggest simple and reliable algorithm for this;
Any language, RegEx, any tools, code snippets are very appreciated
Assuming that the pattern you've described here is consistent throughout, there are quite a few different approaches you could take I think, but in all cases you basically can use that fact that the 'Course' rows start with "Code:" but that's never going to be a student name.
You can take advantage of this either by a regular expression find/replace, or within OpenRefine.
Example:
Open file in a text editor that supports regular expressions in
find/replace
Search for lines starting with 'Code:' and add additional commas to the start of the row to shift the course data columns to the
right e.g. search for: ^Code: replace with: ,,,,,^Code:
If you now import the file into OpenRefine then you'll have a project with 10 columns (the 10th col is caused by the trailing
comma at the end of the course data row)
You can now use Transpose (or just rename) on the right-most columns which contain the course data, while leaving the left-most
columns which contain the student details
Isolate the rows that contain the phrase 'Student Name' in the first column and remove them (via a filter or facet)
Move the Course Code/Description columns to the beginning of the project, and use the 'Edit Cells->Fill Down' option on each column to get the values repeated on all the relevant lines
Finally rename the columns as you want, remove any extraneous columns
I'm implementing a system that returns a list of available articles based on tags inserted by the user, so that the user spots the items that match (or loosely match) his criteria. The returned items will be sorted according to how likely is that they are of interest for the user. The front-end collects the tags and use them in a mySQL query (for which I'm asking hel here).
my DB has this structure:
tags(tag_id, tag_name)
articles(article_id, some_text)
articles_tags(article_id,tag_name)
an example:
the user enters the tags: "hard", "sweet", "red". mySQL will return these items, in this order:
red_candy (which is tagged as hard, red, sweet) - so 3/3 tags match
red_hammer (which is tagged as hard, red, dangerous) - so 2/3 tags match
stone (which is tagged as hard, gray) - so 1/3 tags match
pillow (which is tagged as soft, white) - 0/3 tags match
Thanks all
AC
like this:
select
distinct some_text
from
articles join article_tags on (articles.article_id = articles_tags.article_id )
join tags on (articles_tags.tag_id = tags.tag_id)
where
tag_name in ("hard", "sweet", "red")
order by count(tag_id) DESC;
gbejic's answer is perfect.
I was starting writing functions for computing scores and what not, but this is very intuitive and straightforward.
thanks a lot
AC
I've got a custom searchable member page on a WordPress site running s2member and I have a client that wants to use the mutli select box feature for the "category" data listed members can enter. My current code falls down here as the REGEX I currently use to select the category from the meta_value field only works with the single select box.
Here is the data as it appears in the database field:
s:8:"category";a:1:{i:0;s:17:"Business services";}}
Here is my current AND line in my SQL statement:
AND UMS.meta_value REGEXP '.*\"".$_SESSION['searchfield']."\";s:[0-9]+:\".*".$_SESSION['searchvar'].".\".'
How can I modify the above REGEX to work with the new multi option data? I’ve tried a few things but REGEX isn't a strong point of mine.
Thanks in advance!!