Skip to content

Instantly share code, notes, and snippets.

// This is the interesting bit
module: {
rules: [
{
use: [
{
loader: 'awesome-typescript-loader',
options: {
transpileOnly: true, // Note, this means you ignore errors.
// Due to legacy, we ignore errors in TypeScript files too, DON'T DO THIS FOR TS FILES
@MadaraUchiha
MadaraUchiha / in.js
Created October 30, 2017 17:32
flabebe
const request = require('request');
const reqContext = request.defaults({jar: true});
request.get('http://checkin.timewatch.co.il/punch/punch.php', (err, response, body) => {
console.log(JSON.stringify(response.headers));
request.post('http://checkin.timewatch.co.il/punch/punch2.php', {
form: {
comp: 2135,
name: 41,
export async function reserve(req, res) {
try {
const locker = await Locker.find({
where: {
_id: req.params.id
}
});
await handleEntityNotFound(res, true)(locker);
const reservation = req.body.reservation || {};
if (!reservation.tmpToken) {
function foo() {
return
{
foo: "bar"
};
}
@MadaraUchiha
MadaraUchiha / question.md
Created December 24, 2015 10:08
Implement the Promise constructor challenge

Task 1

A Promise is an object that represents a (potential value) over time. A replacement for callbacks. Your job is to implement the Promise object. Here are the requirements:

  • The Promise constructor takes a function with two arguments: new Promise((resolve, reject) => { ... })
    • Calling the resolve function inside of the handler will resolve the promise (i.e. success). You can call resolve with a single argument, which will be passed to .then().
    • Calling the reject function will reject it (i.e. error). You should always call reject with an Error instance, which will be passed to .then().
  • A Promise has three states, it starts at "pending" and can mutate only once to either "resolved" or "rejected".
  • A Promise object has a .then() method which accepts two functions, the first will call if it's resolved, and the second if it rejects.

Example:

const next = input => {
let chars = input.match(/(\d)\1*/g);
return chars.map(repetition => `${repetition.length}${repetition[0]}`).join('');
};
const nextN = (input, times) => {
if (times === 0) {
return input;
}
return nextN(next(input), times - 1);
let ivals = [/* lots of ivals here */];
let c = new Ftp();
function putItem(ftp, item) {
return new Promise((resolve, reject) =>
ftp.put(item, item, (err) => err ? reject(err) : resolve()));
}
ivals.reduce((promise, ival) =>
promise.then(() => {
@MadaraUchiha
MadaraUchiha / double-hashing.md
Created October 13, 2015 17:57
Why double hashing is bad

The woes of double hashing

What is a hashing function? A hashing function is a function that takes arbitrary input, and returns output with a uniform size (oversimplification, I know). What does this mean? Here's my hashing function:

function myHash($input) {
    return $input[0] === 'A' ? "1" : "0";
}

This hash function accepts any sort of string input, and returns an output of a uniform size. Either 0 or 1.

@MadaraUchiha
MadaraUchiha / right.js
Created June 24, 2015 21:23
Promises nesting is bad
validate
.then(function (sanitizedPayload) {
// Joi defaults any properties not present in `request.payload` so use `payload` from here on out
payload = sanitizedPayload;
return pagesService.checkIfSlugAvailable(server, payload.slug);
})
.then(function (isAvailable) {
if (isAvailable) {
return isAvailable;
} else {