Skip to content

Instantly share code, notes, and snippets.

public IEnumerable<Instruction> Transpiler(IEnumerable<Instruction> codes)
{
var state = TranspilerState.Initial;
foreach (var code of codes)
{
switch (state)
{
case TranspilerState.Initial:
if (SomeCondition(code))
{
class Producer {
start(consumer) {
consumer.start(this);
this.counter = 0;
this.handler = setInterval(() => consumer.data(this.counter++), 1000);
}
stop() {
clearInterval(this.handler);
}
// 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(() => {