I am trying to encode/decode a string with base64. Does coffeescript have any inbuilt support for this ? I found this library: https://github.com/carlcalderon/Base64.coffee .
Is there a better way to do it in Coffeescript ?
You don't need to use libraries written in CoffeeScript just because you're using CoffeeScript.
CoffeeScript compiles to JavaScript. Therefore, any JavaScript library can be used!
If you are using node, the Buffer package can help you. Please refer to this discussion: How to do Base64 encoding in node.js?
An example:
> console.log(new Buffer("Hello World").toString('base64'));
SGVsbG8gV29ybGQ=
> console.log(new Buffer("SGVsbG8gV29ybGQ=", 'base64').toString('ascii'))
Hello World
If you are on the browser, though, you can use any base64 library. This one looks relatively alive and well: https://github.com/dankogai/js-base64
<script src="base64.js"></script>
<script>
Base64.encode('dankogai'); // ZGFua29nYWk=
</script>
Related
I am trying to apply babel plugin on code source something like this
code = require('babel-core').transform(code, {
plugins: ['some plugin']
})
above code is var that contains actual code as a string, what is the right way to do above?
This example shows how you can transform your code according to different babel plugins.
Using babel-core transform method (you already doing).
Output will be transpiled code according to babel-plugin.
You can refer to this link for more babel methods.
Hope it helps you :)
I am trying to encode PGWRecord CDR using ASN.1 notation, starting on page 89 in this 3GPP TS Document
I've been looking for awhile for examples how I can do this, but to no avail. Are there any examples that can show me how to do this using Bouncy Castle? Or is there a better alternative than Bouncy Castle to encode this CDR?
Step by step instructions on how I can do this would be very nice!
Any help would be very appreciated. Thanks all!
Ya, just two months back i have worked on Bouncy castle to decode CDRS which of 3GPP stranded encoded file. Currently i am good in decoding and if any issues on decoding i can give more example and i can solve it easily solve it.
But for your question i can suggest some points and if you have any question pleas add comment. It not only help for you it can help for new bees who start with encode / decode process.
a) You did right API choice (Bouncy Castle) for encoding CDRS files
b) You can go for paid version of encode / decode APIs but it is too expansive
c) I have found 3 paid APIs which gives good and expected results, those are
1) [OSS Nokalva][1]
2) Obj-Sys
3) unigone
d) For me Bouncy castle gave 100% result then paid APIs even though they work well and good. If you want to use Bouncy castle then you need to put some more effort to work on encoding, So Bouncy castle is an API which support basic and some advanced parser, to do any encoding / decoding you need to write the java classes as per your ASN.1 syntax specification and so on.. I can write the steps but it will be too long so end of this answer i am giving you a link which explain it better. click on this link and download bcprov-jdk15on-154.tar.gz file.
e) Unzip the package you downloaded and go to bcprov-jdk15on-154\bcprov-jdk15on-154\src\org\bouncycastle\asn1\test you will find N number of examples to encode/decode CDRs according to the ASN.1 syntax specification
f) If you want to understand with very simple example then go through this link you can easily do your job
Still if you find difficult to understand then write a comment i will try to help my best.
Try to look at BinaryNotes. You have ASN.1 definition of what you are trying to encode. BinaryNotes will generate classes for encoding/decoding objects to/from ASN.1.
BinaryNotes works with xlst transformations to generate classes. You could modify the transformations in a way that it will use bouncy classes form encoding/decoding.
I guess that the encoding of GPRSRecord CHOICE would be something like that below.Be careful to tag values and conversion from string view to hex and BCD packing for IMSI and GSNAddress value :
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new BERTaggedObject(true, 0, new ASN1Integer(18))); //e.g. sgsnPDPRecord (18)
v.add(new BERTaggedObject(true, 3, new BEROctetString(Hex.decode("490154203237518")); //IMSI. String to BCD bytes conversion needed
v.add(new BERTaggedObject(true, 4, new BERTaggedObject(true, 0, new DEROctetString(Hex.decode("994507776655"))))); // GSNAddress
v.add(new BERTaggedObject(true, 5, new BEROctetString(Hex.decode("00DB")))); //ChargingID
byte[] encoded = BERTaggedObject.getInstance(new BERTaggedObject(true, 78, new BERSet(v))).getEncoded(); //SGWRecord
I am developing a web application using ExtJS to build GUI and communicate with server via RESTful web-service (the returned data is formatted as JSON objects).
Now I am having problems when processing with data which contains HTML tags, Javascript codes inside; because when I set those values to Ext forms, labels, input fields, they are affected by those syntaxes.
I used this function to load data from model object to form:
form.loadRecord(model);
I have found a solution to escape HTML and JS: using
field.setValue(Ext.util.Format.htmlDecode(data));
but I think that is not a good solution for whole application, because the developers must do so much things: review all input fields, labels, and put that snippet to them. And after all, that is not a beautiful way to build a fast, robust and maintainable application.
So, could you please help me solution so that it can be modified at one place, and affects to the rest. Can I override the setValue/ setLabel of AbstractComponent? Or should I encode the data before rendering them? And how to decode those data?
(P/S: I uses Grails framework on the server-side)
Thank you so much.
If you're using Ext.XTemplate, you can escape html in fields like this:
var tpl = new Ext.XTemplate(
'<p>My Field: {myField:htmlEncode}</p>'
);
Everything depends on your use case, but what I do is - escape all HTML code on server side, so that there are no 'forgotten' places by mistake. That of course creates problems, when these data need to be loaded in form fields, because they are escaped.
The easiest solution is to override setValue for all form fields and use Extjs htmlDecode function, which will revert these values back to normal.
Ext.override(Ext.form.field.Base, {
setValue: function(val) {
val = Ext.util.Format.htmlDecode(val);
return this.callParent([val]);
}
});
This link has a excellent answer by jack.slocum :
https://www.sencha.com/forum/showthread.php?13913
grid.on('validateedit', function(e){
e.value = Ext.util.Format.stripTags(e.value);
});
Util method Ext.util.Format.stripTags() removes all the html/script tags.
We have quite a number of .xqy files in several folders.
Sometimes, I need to invoke an .xqy file (via Marklogic's CQ) to test if it's working.
But I find it rather cumbersome to have to know what parameters to pass in and specify them in the xquery in CQ.
Is there a tool out there that would generate an HTML form that presents to me the parameters of a given .XQY file and invokes it when I press a "submit" button ?
If there is none out there, would somebody here know of how to make such an HTML form ? Right now, I can't seem to find any readily-available xdmp or xquery commands to tell me if an .XQY file is invocable or what parameters it expects to be fed.
Danny
The XQuery standard doesn't support introspection, nor does MarkLogic provide any functions that help with that. The closest you can get with this is using the XQDoc documentation code that is capable of parsing the XQuery code itself and producing descriptions of all function signatures within modules.
You can find more details about it here: http://developer.marklogic.com/code/xqdoc-ws
It doesn't provide a 'Submit' button, but using the XML output of xqdoc, you could make that yourself..
Good luck!
Another option would be to convert your XQuery to XQueryX and you can then process this as XML using XQuery (or XSLT) to generate an XForm or XHTML Form.
Since Danny mentioned unit testing, I'll risk plugging my own framework for that: https://github.com/mblakele/xqut
I usually run XQUT test suites in a cq buffer, but it would be easy enough to wrap one in a simple web page - with or without a form.
I am looking for a way of generating PNG images of equations from LATEX source code embedded in templates. For example, given:
[% FILTER latex_display ]
\begin{eqnarray*}
\max && U(x,y) \\
\mathrm{s.t.} && p_x x + p_y y \leq I \\
&& x \geq 0, y \geq 0
\end{eqnarray*}
[% END %]
I would like to get the output:
<div class="latex display"><img src="equation.png" width="x" height="y"></div>
which should ultimately display as:
I am using ttree to generate documents offline. I know about Template::Plugin::Latex but that is geared towards producing actual documents out of LATEX templates.
Any suggestions?
Update:
I appreciate the suggestions (and I have voted them up). However, they are no quite what I need. I would really appreciate a few pointers towards getting started with a Plugin or Filter for Template Toolkit.
Wikipedia does something similar to what you want. They use a program called texcv. Then you also have MathJAX which is more aimed at dynamic math rendering in web-pages.
texcv is according to the linked page written in OCaml however since the rest of Mediawiki is written in PHP I don't think you should have any problem with repurposing the program to use with Perl.
you should take a look at jsMath, MathML, or mathjax
I would really appreciate a few pointers towards getting started with a Plugin or Filter for Template Toolkit
These docs on Template Toolkit site should provide all necessary info to setup a plugin or filter:
Plugin provider module
Base class for plugin filters
Once you have your LATEX to PNG conversion sorted then you probably need to save it as a file using redirect. Example from POD:
[% PROCESS my/png/generator
FILTER redirect("images/logo.png", binmode=1) %]
Hope that helps.
/I3az/