This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function type_line(tlen, text, target, timing) { | |
var txt = text.substr(0, tlen++) | |
target.innerHTML = txt | |
if (tlen < text.length + 1) { | |
setTimeout(type_line.bind(null, tlen, text, target), timing) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Functions for creating and verifying authentication tokens | |
according to the `JWT spec <https://jwt.io/>`_. | |
JWT authentication tokens are made of three sections that are | |
Base64Url encoded with no padding. The third section is an HMAC | |
of the first two sections, so that without knowing the secret | |
key you cannot verify the token nor create tokens that will be | |
accepted on the other end. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
/* | |
Base64 translates 24 bits into 4 ASCII characters at a time. First, | |
3 8-bit bytes are treated as 4 6-bit groups. Those 4 groups are | |
translated into ASCII characters. That is, each 6-bit number is treated | |
as an index into the ASCII character array. | |
If the final set of bits is less 8 or 16 instead of 24, traditional base64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <kore/kore.h> | |
#include <string.h> | |
char * base64_url_decode(char * in) { | |
size_t len; | |
char * padded; | |
u_int8_t * out; | |
unsigned int i; | |
len = strlen(in); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(consumer). | |
%% API | |
-export([execute_query/0]). | |
parse_item(Data) -> | |
ID = maps:get(<<"id">>, Data), | |
Item = maps:get(<<"attributes">>, Data), | |
DOI = maps:get(<<"doi">>, Item), | |
Title = maps:get(<<"title">>, Item), | |
Published = maps:get(<<"published">>, Item), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testJWT() throws Exception { | |
Calendar now = Calendar.getInstance(); | |
now.add(Calendar.SECOND, 20); | |
JsonObject obj = Json.object(); | |
obj.add("sub", "1234567890"); | |
obj.add("name", "John Doe"); | |
obj.add("admin", true); | |
obj.add("exp", now.getTimeInMillis()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Calendar; | |
import javax.crypto.Mac; | |
import javax.crypto.spec.SecretKeySpec; | |
import org.apache.commons.codec.binary.Base64; | |
import org.apache.commons.lang.StringUtils; | |
import com.eclipsesource.json.Json; | |
import com.eclipsesource.json.JsonObject; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(display). | |
-export([format/1,format/2]). | |
format(Num) -> format(Num, 2). | |
format(Num, Precision) -> | |
Abs = abs(Num), | |
TB = math:pow(10,12), | |
GB = math:pow(10,9), | |
MB = math:pow(10,6), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var msg1 = { msg: 'commit' } | |
var msg2 = { msg: 'update', id: 5, length: 21 } | |
var protobuf = require('protocol-buffers') | |
var schema = protobuf([ | |
{ "name": "msg", "type": "string" }, | |
{ "name": "length", "type": "float" }, | |
{ "name": "id", "type": "float" } | |
]) | |
var encoder = schema.encode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* OSTI is home to lots of scientific, engineering and technical journals and other doucments. | |
* It is part of the US Dept. of Energy. This shows how to retrieve search results from their vast | |
* collection of data as XML and consume it. | |
*/ | |
var xml2js = require('xml2js') | |
var http = require('http') | |
// Get 100 entries from OSTI in the subject area HYDROGEN | |
// See https://www.osti.gov/home/sites/www.osti.gov.home/files/SciTechXMLDataServices1.1.pdf for more info |