Step by Step tutorial how to create a mode in CodeMirror - codemirror

Can anybody provide me a step by step tutorial in order to create a own mode for CodeMirror.
The online tutorial is quite complicated.
Thanks.
Regards.

I recommend you this site, it has a great tutorial for "simple modes", if its your case. Also I'll show you a mode that I made for a pseudo-regex mode:
CodeMirror.defineSimpleMode("simplemode", {
start: [
// As you can see I use different tokens for different matches as needed.
{regex: /(\.\+|\.\*|\.|\+)/, token: "keyword"},
{regex: /(\\d)|(\\w)|(\\s)|(\\t)|(\\r)|(\\n)|(\\\()|(\\\))|(\\\[)|(\\\])|(\\\{)|(\\\})|(\\\.)|(\\\-)|(\\\_)/i, token: "string"},
{regex: /(![A-Za-z]+\{|\})/, token: "number"},
{regex: /(\(|\)|\||\[|\]|\-)/, token: "operator"}
]
});
Then just add mode: "simplemode" to the editor options. Hope it helps you!

Related

google tag manager eCommerce

I am getting crazy trying to get this to work.
I am pretty new to the whole Google Tag Manager thing, but after reading documentation, I got the basic google analytics to work.
Having said that, I am trying to set up an eCommerce transactions using dataLayer but I cannot seems to get it to work.
I am using the basic example taken on the main site:
var dataLayer = dataLayer || [];
dataLayer.push({
'ecommerce': {
'purchase': {
'actionField': {
'id': 'T12345',
'affiliation': 'Online Store',
'revenue': '35.43',
'tax':'4.90',
'shipping': '5.99',
'coupon': 'SUMMER_SALE'
},
'products': [{
'name': 'Triblend Android T-Shirt',
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray',
'quantity': 1,
'coupon': ''
},
{
'name': 'Donut Friday Scented T-Shirt',
'id': '67890',
'price': '33.75',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Black',
'quantity': 1
}]
}
}
});
In my GTM configuration, I have the following:
- Tag Type: Universal Analytics
- Track Type: Page View
- Google Analytics Settings: {{gaTrackingID}}
- Enable overriding settings in this tag: ticked
- Enable Enhanced Ecommerce Features: true
- Use Data Layer
and in the Trigger i have:
- Trigger Type: Page view
- Trigger fires on: "Page URL contains /checkout
I forgot to mention that I have two tags enabled, one to log activity on all pages and the second one which should log the purchase.
I can in google Analytics that the visit worked correcty, but the transaction does not.
Also, can someone tell me if the section "CONVERSATIONS -> Ecommerce" displays the standard or Enhanced Ecommerce?
I am a bit confused..
Why the above does not work?
I just found out this morning that the code actually worked, but google analytics takes around 24/48 hours to reflect the changes. this is something I did not read anywhere in most of the documentation I found. This kind of make the whole testing process a bit difficult, as the only thing we can do is to check if the event is fired (as far as I know).
Perhaps there is a better way (and more instant) to test whether an eCommerce data has been pushed to google Analytics?
Try to insert page and transaction information into a single 'ecommerce' object and not separated.
Regarding the data displayed in the ecommerce report in Analytics, it depends on whether you have enabled enhanced ecommerce settings or only those standard.

getting different results when using Bing V5 API vs bing.com

So I am trying to implement Bing Search V5 API (click here for full code).
$.ajax({
url: "https://api.cognitive.microsoft.com/bing/v5.0/search",
data: {
"q": $("#search-text").val() + "+site:berkeley.edu",
"mkt": "en-US",
"responseFilter": "Webpages",
"count": "10",
"offset": "0"
},
beforeSend: function(xhrObj) {
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", "supply-your-own-key-here");
},
type: "GET",
})
As a test, I searched using bing.com (click here for search results) and the first 10 results I'm getting is completely different from the results I'm getting using my code. I've added a screenshot that shows the search results.
Any ideas what I could be doing wrong? Thanks
ps. I've found similar discussion but they were from 2011 and things most likely has changed since then.
screeshot of search results using my code:
You're not doing anything "wrong". It's simply that an extra setting is giving you a different result. The setting for mkt=en-US, causes the difference.
Not supplying it gives the same result, for instance in Postman.
Changing it to use cc instead, "A 2-character country code of the country where the results come from." Results in the same as with the mkt.
So likely if you want Bing result, don't supply anything.

How to deal with a REST API structures redundancy?

I am currently build a REST API for a webservice that, amongst other things, handles user bans.
The current API I designed look like:
URL: GET /user/<user_id>/bans/<session_id>
Description: Get the ban on the specified session for the specified user.
Output:
{
session_id: 1,
banned_until: "..."
}
URL: GET /user/<user_id>/bans
Description: Get all bans for the specified user.
Output:
[
{
session_id: 1,
banned_until: "..."
},
{
session_id: 2,
banned_until: "..."
}
]
URL: PUT /user/<user_id>/bans/<session_id>
Description: Set or update a ban on the specified session for the specified user.
Input:
{
session_id: 1,
banned_until: "..."
}
Output:
{
session_id: 1,
banned_until: "..."
}
Now one of my coworkers believes that the API is wrong because, for instance in the case of the PUT, the user has to specify the session_id twice: once in the URL and once in the content and those two have to match (which means an extra check server-side). He makes the same comment for the GET where the user specifies the session id in the URL to get it back in the response, meaning a waste of bandwidth.
While I understand his concerns, I however think the current design as it is, is simpler for the user (only one data structure to care about) and that the extra check on the server isn't that much work to do compared to the comfort it brings the user.
Is there an official guideline regarding this in the REST best-practices ? What is the usual/recommended way of dealing with this ?
Personally, I think what you are talking about is the different between the PUT and POST methods.
From the RESTful CookBook:
Use PUT when you can update a resource completely through a specific resource. For instance, if you know that an article resides at http://example.org/article/1234, you can PUT a new resource representation of this article directly through a PUT on this URL.
So, in the PUT example you gave, I think it is perfectly valid to specify the sessionID in the URL since you are storing the ban at a specific point.
However you could also create a POST service at URL: POST /user/<user_id>/bans to satisfy your co-worker. :-)

API design : Need help for URLs

I'm designing a new website. Before i start to code, i'm learning a lot about api and nosql database (as i'm used to sql but i want to try with mongoDB).
In mongoDB, i'll have a 'user' document like that :
{
firstname: 'xxxxxxx',
lastname: 'xxxxxxx',
projects: [
{
name: 'project xxxxxxx',
participants: [], // array of friends into this project
operations: [
{ title: 'Title OP xxxxxxx', contributors: [] },
{ title: 'Title OP xxxxxxx', contributors: [] },
{ title: 'Title OP xxxxxxx', contributors: [] }
]
}
]
}
I was wondering two things :
Should projects.participantsand projects.operations.contributors be references to other users ?
For the API, should i do something like :
GET /users/:id_user
GET /users/:id_user/projects/:id_project
GET /users/:id_user/projects/:id_project/operations/:id_operation
(should my API always start with users ?)
If you ever have a better solution I will be glad to know.
Thanks
EDIT 1 : I'll work on NodeJS with Express and i would like to have a REST API.
yes, projects.participants and projects.operations.contributors can be reference to other documents in the same collection. Each of these should refer to valid _id in the same collection.
can you please put some more light on how exactly are you creating your APIs? I mean which framework you are using as a wrapper to access mongoDB? May be then I can try to help more.
ok great!!!
So, users is your collection name. Its absolutely not necessary to start your API name with users. In node.js you can create a router, which will route your request to a particular js file and you can name it anything you want. Example:
use case: You want to expose 3 API
1. To access all the users. (exposed using url - /getallusers)
2. To access all the participants of the project.(exposed using url - /getparticipantsbyproject)
3. To access all the contributors in the operations.(exposed using url - /getcontributorsbyproject).
You can write all these APIs in your file called myapi and expose them.
Now, you can very well call these APIs from browser using below urls:
http://host:port/myapi/getallusers
http://host:port/myapi/getparticipantsbyproject
http://host:port/myapi/getcontributorsbyproject
Its about RESTful API only. I mentioned 3 urls above which are nothing but RESTful API exposing different functionalities.

I'd like to know how to change pages in Form Post

I'd like to know how to change pages by putting some in Forms by Post way.
http://www.aldoshoes.com/us/women/shoes/flats
in this page
How do I move to page 2 by putting some variabels in URL?
Please help me out.
This is not possible because it seems to me that the server does not handle GET parameters in the http request.
However it is possible to achieve this using POST parameters, either programmatically or using a plug-in for Chrome/Firefox (see Super User question).
The server accepts the following parameters:
formAction:
startRow:1
rowsperPage:12
flagID:
seasonID:
dimensionID:
sizeID:
colorID:
colorGroupID:
itemCategoryLevel1:1100
itemCategoryLevel2:1101
itemCategoryLevel3:1120
itemCategoryLevel4:
styleID:
styleDescription:
keywords:
alternateDescription:
descriptionDetail1:
descriptionDetail2:
descriptionDetail3:
onsale:N
sortBy:
itemFamilyID:
heelHeight:
To get to the second page of the shop you can set the parameter startRow to 13:
startRow:13
rowsperPage:12