Wordpress alphabetical index - wordpress

I have a question.
How can do an alphabetical index with links without plugin ?
Example : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
If a character contains posts, it will be a link.
Else it will text.
Anyone can help me ?
Update : Or something like this http://dribbble.com/tags

You could write a few lines of code to query the database and do a like search on the post titles. The below is not formatted for a WP query, but it should give you a good idea:
SELECT count(*)
FROM wp_posts
WHERE post_title LIKE 'a%';
If the count is greater than 0, you know there are posts and you can add a hyperlink to the letter.

Related

Gremlin : How to get all the vertex details in the traversal?

Sample Data
A knows B
A knows C
A knows D
B knows E
C knows F
Desired Output
B
C
D
E
F
I tried the following query, but it's not working,
g.V('A').
out('knows').
as('x').
out('knows').
as('x').
project('Employee').
by(select('x'))
If you just want to get all the vertices in the path you can do:
g.V('A').repeat(out("knows")).emit().label()
example: https://gremlify.com/c533ij58a98z8

R - filter data from MongoDB collection

I want to use R to load a collection from mongoDB to R, with filter to increase the speed. The filter can be Or condition or IN a R data.
MongoDB collection
Name Type
A M
B P
C M
D P
E O
RFilter
Criteria
M
P
RData <- MongoCollection$find('{"Type" in RFilter$Criteria}',
fields = '{
"Name" : true,
"Type" : true
}')
I expect the output:
RData
Name Type
A M
B P
C M
D P
If you need to check-in database to check if name or type is P or M try $or in criteria as below:
{$or:[{Name:{$in:["P","M"]}},{Type:{$in:["P","M"]}}]}
The above $or condition will check in DB if the name is "P" or "M" it'll return document else it'll check in type if it values is "P" or "M" else won't return document if both are not matched.

R - replacing strings using gsub()

I have a lot of unclean data in the form:
abc
abc/def
abc/de
abc/d
abc/def/i j k
abc/def/i
abc/def/i j
This is just the part of the data I would like to change. This is part of much bigger set of data.
I would like to change all the elements to abc/def/i j k.
I have used the gsub() function as follows:
gsub('abc[a-z/]', 'abc/def/i j k', str)
output :
abc/def/i j k
abc/def/i j k/def
abc/def/i j k/de
abc/def/i j k/d
The problem being that it replaces any occurrence of the pattern.
The only solution where i got decent enough results are where i hard code all the possible options like this:
gsub('abc$|abc/d$|abc/de$|abc/def/i$', 'abc/def/i j k', str)
However, this would not work if there is a variation in any new data.
So I was wondering if it was possible to get the result without hard coding the parameters.
You may use
x <- c("abc", "abc/def","abc/de","abc/d","abc/def/i j k","abc/def/i","abc/def/i j")
sub("^(abc)(?:/[^/]*)?", "\\1/def", x)
## => [1] "abc/def" "abc/def" "abc/def" "abc/def"
## [5] "abc/def/i j k" "abc/def/i" "abc/def/i j"
See R demo
Details:
^ - start of string
(abc) - Group 1: abc
(?:/[^/]*)? - an optional group matching a sequence of:
/ - a /
[^/]* - 0+ chars other than /

Pivot datatable based on key and value in datatable

the data i am having is like, i am trying this from week am not able to find any solution.
I need to do this using either pivot using c# or using lists. Kindly provide the answers. immediate.
Key Value
A e
B f
C i
D j
A k
B l
C m
D n
i need something like this
A B C D
-------
e f i j
k l m n
where the first line is a column header.
Any better link of any stackoverflow question also appreciable.
By following code am able to get distinct columns, now problem is with assigning values in rows.
please provide any better way of doing this.
foreach (DataRow row in dtBackupData.Rows)
{
keyname = row["KeyName"].ToString();
if (!keyNameList.Contains(keyname))
{
keyNameList.Add(keyname);
dtDynamic.Columns.Add(keyname, typeof(string));
}
}

Decoding adobe color files (*.ACO), need input about comprehending the syntax

So I'm developing a web application to more easily be able distribute color palettes created with Photoshop in a *.ACO or *.ASE format to colleagues who doesn't have those programs. I've come quite a long way setting up the basics, but now I'm totally stuck for the sole reason that I can't figure out how the swatch files are structured.
This is what I get when I open the *.ASE file in a text editor:
ASEF & S w a t c h 1 RGB & S w a t c h 2 RGB ?
Œ ?€ ?€ & S w a t c h 3 RGB ?oïð?)̪>mí & S w a t c h 1 RGB & S w a t c h 2 RGB ?
Œ ?€ ?€ & S w a t c h 3 RGB ?oïð?)̪>mí & S w a t c h 1 RGB & S w a t c h 2 RGB ?
Œ ?€ ?€ & S w a t c h 3 RGB ?oïð?)̪>mí & S w a t c h 1 RGB & S w a t c h 2 RGB ?
Œ ?€ ?€ & S w a t c h 3 RGB ?oïð?)̪>mí
and when I open it in NP++ it looks like this:
I was hoping (and naively expecting) that the format would be in some comprehensible XML structure, but it's clearly not..
I've tried researching the subject and found these sources:
http://www.nomodes.com/aco.html
http://www.selapa.net/swatches/colors/fileformats.php
http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/PhotoshopFileFormats.htm#50577411_31265
But to be honest it feels to complicated for me to be able to wrap my head around.. If anyone with better knowledge about file coding formats or color coding formats has any input for me I would greatly appreciate it!
The files are available here for download if you want to have a look at them:
https://www.dropbox.com/sh/9vo2h7ophpfc201/p7saMtxi_k
What you are seeing is the ASCII representation of the binary file. In the link you shared previously you will see that the file format is binary. So that lets take that as the starting point. Now open the file and read it in like so,
$handle = fopen("temp.aco", "rb");
while (!feof($handle))
{
$data = fread($handle, 2);
echo bin2hex($data)."<br/>";
}
This opens the .aco file and reads until the end of file is reached. By using fread and setting the second parameter to 2 you read in 2 bytes worth of data from the file. You will then see output like so,
0001 0008 0000 fafa e2e2 dbdb 0000
Now looking at your other link you will see that the first number 0001 represents the version number 0008 represents the number of colours in the file (in my case 8) then you have the colour type which will typically be 0000 (RGB) 0001 (HSB) 0002 (CMYK) see the colour conversion table for the rest.
Colours are made up of either 3 or 4 words so sometimes you can ignore the last word it will be zero'd. So lets see an example of this,
0000-(RGB Type) fafa-(Red represented by 0..65535 range) e2e2-(Green represented by 0..65535 range) dbdb-(Blue represented by 0..65535 range) 0000-(no data needed in this positioned so zero'd)
By converting the words read to an unsigned int and following the conversion table you will get the appropriate rgb values. Here is my code for parsing the various types.
function colorInColorSpace($colorSpace, $w, $x, $y, $z){
// RGB
if($colorSpace==0){
$r = $w/256;
$g = $x/256;
$b = $y/256;
//z component not used in rgb format
print $colorSpace." ".$r." ".$g." ".$b."<br/>";
}
//HSB
else if($colorSpace==1){
$h = $w/182.04;
$s = $x/655.35;
$b = $y/655.35;
print $colorSpace." ".$h." ".$s." ".$b."<br/>";
}
//CYMK
else if($colorSpace==2){
$c = 100 - ($w/655.35);
$m = 100 - ($x/655.35);
$y = 100 - ($y/655.35);
$k = 100 - ($z/655.35);
print $colorSpace." ".$c." ".$m." ".$y." ".$k."<br/>";
}
//Lab
else if($colorSpace==7){
// print $colorSpace." ".bin2hex($w[0])." ".bin2hex($w[1])."<br/>";
}
//Grayscale
else if($colorSpace==8){
$greyscale = $w/39.0625;
print $colorSpace." ".$greyscale."<br/>";
}
//Wide CYMK
else if($colorSpace==9){
$c = $w/100;
$m = $x/100;
$y = $y/100;
$k = $z/100;
print $colorSpace." ".$c." ".$m." ".$y." ".$k."<br/>";
}
}
Hope this helps.
Just for reference to others, I faced a similar problem and found this C program that reads ACO files and convert them into html. http://www.hping.org/aco2html/
It's a great tool, but as I wanted to modify it and made it better, I decided to port it to JavaScript. Here's my code on Github https://github.com/websemantics/Color-Palette-Toolkit
There's also a live demo
http://websemantics.github.io/Color-Palette-Toolkit/
Stumbled on this post while I was searching for a way to decode Adobe's .ASE swatch format. I'm not sure if it will help you or not with .ACO, but I found a guy that wrote a class for extracting colors from the .ASE format:
Adobe Swatch Exchange Reader/Decoder!broken link

Resources