Skip to content

Commit

Permalink
feat: update src files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 18, 2022
1 parent 48d9c1a commit 7b7b710
Show file tree
Hide file tree
Showing 96 changed files with 8,036 additions and 2,960 deletions.
17 changes: 15 additions & 2 deletions scripts.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import path from 'path';
import { readdir, writeFile } from 'fs/promises';
import { readdir, writeFile, mkdir, readFile } from 'fs/promises';

async function createJS(filename = '') {
const outDir = path.resolve(process.cwd(), 'src');
await mkdir(outDir, { recursive: true });
const txt = (await readFile(filename)).toString();
const code = `const code = \`${txt.toString().replace(/`/ig, '\\`').replace(/\$\{/g, '\\${')}\`;\n\n export default code;`;
const name = path.basename(filename).replace(/^sample\./, '').replace(/\.txt$/, '');
const outfile = path.resolve(outDir, name + '.js');
// console.log('outDir:name:', name, outfile)
await writeFile(outfile, code);
console.log('✅', 'JS \x1b[32;1m', path.basename(outfile), '\x1b[0m', outfile);
}

;(async () => {
const rootSrc = path.join(process.cwd(), 'txt');
Expand All @@ -10,10 +22,11 @@ import { readdir, writeFile } from 'fs/promises';
const exts = ['diff'];
for (const file of files) {
const ext = path.extname(file.replace(/.txt$/g, '')).replace(/^./g, '')
console.log('✅', '\x1b[32;1m', ext, '\x1b[0m', file);
// console.log('✅', '\x1b[32;1m', ext, '\x1b[0m', file);
if (!/^diff/.test(file)) {
exts.push(ext);
}
createJS(path.resolve('./txt', file));
}
await writeFile(outputFileExts, JSON.stringify(exts, null, 2));
console.log();
Expand Down
32 changes: 32 additions & 0 deletions src/abap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const code = `REPORT zrosetta_base64_encode_data.
DATA: li_client TYPE REF TO if_http_client,
lv_encoded TYPE string,
lv_data TYPE xstring.
cl_http_client=>create_by_url(
EXPORTING
url = 'http://rosettacode.org/favicon.ico'
IMPORTING
client = li_client ).
li_client->send( ).
li_client->receive( ).
lv_data = li_client->response->get_data( ).
CALL FUNCTION 'SSFC_BASE64_ENCODE'
EXPORTING
bindata = lv_data
IMPORTING
b64data = lv_encoded.
WHILE strlen( lv_encoded ) > 100.
WRITE: / lv_encoded(100).
lv_encoded = lv_encoded+100.
ENDWHILE.
WRITE: / lv_encoded.
`;

export default code;
40 changes: 40 additions & 0 deletions src/aes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const code = `// Contract simulating developers organization
contract HackBG =
record state = { developers: map(address, developer) }
record developer = { name: string
, age: int
, skillset: map(skill, experience) }
type skill = string
type experience = int
datatype event =
LogDeveloperAdded(indexed address, indexed int, string)
entrypoint init() : state = { developers = {} }
stateful entrypoint dev_add(account: address, dev_name: string, dev_age: int) =
require(!is_member(account), "ERROR_DEVELOPER_ALREADY_EXISTS")
let dev : developer = { name = dev_name
, age = dev_age
, skillset = {} }
put(state{ developers[account] = dev })
Chain.event(LogDeveloperAdded(account, Chain.timestamp, dev_name))
stateful entrypoint dev_update(account: address, dev_name: string, dev_age: int) =
require(is_member(account), "ERROR_DEVELOPER_DOES_NOT_EXIST")
put(state{ developers[account].name = dev_name })
put(state{ developers[account].age = dev_age })
function is_member(account: address) : bool =
Map.member(account, state.developers)
stateful entrypoint dev_skill_modify(account: address, skill: string, experience: int) =
put(state{ developers[account].skillset[skill] = experience })
entrypoint dev_get(account: address) : developer =
state.developers[account]`;

export default code;
10 changes: 10 additions & 0 deletions src/apex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const code = `/* Using a single database query, find all the leads in
the database that have the same email address as any
of the leads being inserted or updated. */
for (Lead lead : [SELECT Email FROM Lead WHERE Email IN :leadMap.KeySet()]) {
Lead newLead = leadMap.get(lead.Email);
newLead.Email.addError('A lead with this email address already exists.');
}
`;

export default code;
7 changes: 7 additions & 0 deletions src/azcli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const code = `# Create a resource group.
az group create --name myResourceGroup --location westeurope
# Create a new virtual machine, this creates SSH keys if not present.
az vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --generate-ssh-keys`;

export default code;
15 changes: 15 additions & 0 deletions src/bat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const code = `rem *******Begin Comment**************
rem This program starts the superapp batch program on the network,
rem directs the output to a file, and displays the file
rem in Notepad.
rem *******End Comment**************
@echo off
if exist C:\output.txt goto EMPTYEXISTS
setlocal
path=g:\programs\superapp;%path%
call superapp>C:\output.txt
endlocal
:EMPTYEXISTS
start notepad c:\output.txt`;

export default code;
32 changes: 32 additions & 0 deletions src/bicep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const code = `targetScope = 'subscription'
param deployStorage bool = true
@description('The object ID of the principal that will get the role assignment')
param aadPrincipalId string
module stg './storage.bicep' = if(deployStorage) {
name: 'storageDeploy'
scope: resourceGroup('another-rg') // this will target another resource group in the same subscription
params: {
storageAccountName: '<YOURUNIQUESTORAGENAME>'
}
}
var contributor = 'b24988ac-6180-42a0-ab88-20f7382dd24c'
resource roleDef 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {
name: contributor
}
resource rbac 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
name: guid(subscription().id, aadPrincipalId, contributor)
properties: {
roleDefinitionId: roleDef.id
principalId: aadPrincipalId
}
}
output storageName array = stg.outputs.containerProps
`;

export default code;
6 changes: 2 additions & 4 deletions src/brainfuck.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const code = `[ This program prints "Hello World!" and a newline to the screen, its
length is 106 active command characters [it is not the shortest.]
Expand Down Expand Up @@ -39,7 +38,6 @@ Pointer : ^
<. Cell #3 was set to 'o' from the end of 'Hello'
+++.------.--------. Cell #3 for 'rl' and 'd'
>>+. Add 1 to Cell #5 gives us an exclamation point
>++. And finally a newline from Cell #6
`;
>++. And finally a newline from Cell #6`;

export default code;
export default code;
Loading

0 comments on commit 7b7b710

Please sign in to comment.