Instantly share code, notes, and snippets.

Hacking

# Viktor Karpovvitkarpov

Hacking
• Sort options
Last active Dec 27, 2018
Computer Science Club, 27.12.2018 (Strings)
View Computer-Science-Club-27-12-2018.md

# Computer Science Club, 27.12.2018

Here's a set of problems for the class. Exploiring strings.

## Is Unique

Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?

Hints:

Created Oct 15, 2018
Removing an arbitrary element from the stack
View rm-element-from-the-stack.js
 function removeItemFromStack(stack, item) { const tmp = stack.pop(); // if we've looked up the whole stack there's no item // just return tmp element back to the top and we're done if (stack.length === 0) { stack.push(tmp); return; }
Created Jul 11, 2018
Extra Long Factorial
View extra-long-factorial.js
 function mult(a, b) { let carry = 0; for (let i = 0; i < a.length || carry > 0; i++) { if (i === a.length) { a.push(0); } const curr = carry + a[i] * b; a[i] = curr % 10; carry = Math.floor(curr / 10);
Created Jul 6, 2018
How do I make a tokenizer faster?
View question.md

Hello software engineers and computer scientists! :)

I'm working on open source JavaScript project which has css parser as one if its modules. Node --perf shows me that the cricical part is REGEXP which is used to find the next word boundary.

```const RE_WORD_END = /[ \n\t\r\f\(\)\{\}:;@!'"\\\]\[#]|\/(?=\*)/g;

// pos - current boundary
// next - next boundary which the code has to find```
Last active Jun 27, 2018 — forked from jamiebuilds/example.md
View example.md
``````/my-website/
| package.json
| /src/
| | /pages/
| | | index.html
| | /assets/
| | | site.css
| | | site.js
``````
Created Nov 11, 2017
The right way to distinguish errors
View code-comarison-in-errors.js
 if (err.code === 'ERR_HTTP_HEADERS_SENT') { //do something with the error }
Created Nov 11, 2017
Don't do this anymore, there're erorrs' codes since Node.js 9.0.0
View message-comparison-in-errors.js
 if (err.message === 'Can\'t set headers after they are sent.') { //do something with the error }
Last active Nov 11, 2017
Example of util.callbackify
View callbacify.js
 const { callbackify } = require('util'); async function main() { await Promise.resolve(); } callbackify(main)(function(err) { if (err) { return console.error(err); }
Created Nov 11, 2017
Example of util.promisify
View promisify.js
 // @see http://2ality.com/2017/05/util-promisify.html const { promisify } = require('util'); const fs = require('fs'); const readFileAsync = promisify(fs.readFile); const filePath = process.argv[2]; readFileAsync(filePath, { encoding: 'utf8' })
Last active Nov 10, 2017
Example of http/2 landed in Node.js 9 without --expose-http2 flag
View http2-example.js
 const http2 = require('http2'); const fs = require('fs'); const server = http2.createSecureServer({ key: fs.readFileSync('key.pem'), cert: fs.readFileSync('cert.pem') }); server.on('error', (err) => console.error(err)); server.on('socketError', (err) => console.error(err));
You can’t perform that action at this time.