Skip to content

Instantly share code, notes, and snippets.

View allenkim67's full-sized avatar

Allen Kim allenkim67

  • Bangkok, Thailand
View GitHub Profile
If see 1 person with blue eyes:
If I don't have blue eyes they will kill themself in 1 day
If I do have blue eyes they will not kill themself and then both of us will know we have blue eyes and kill ourselves in 2 days
If see 2 people with blue eyes:
If I don't have blue eyes then the 2 other people are thinking with the logic above, so they will kill themselves in 2 days
If I do have blue eyes they will not kill themselves by day 2 and all 3 of us will know we have blue eyes and kill ourselves in 3 days
If see 3 people with blue eyes:
If I don't have blue eyes then the 3 other people are thinking with the logic above, so they will kill themselves in 3 days
function outerFn() {
var x = 1;
function innerFn() {
x += 1;
console.log(x);
}
return innerFn;
}
var fn = outerFn();
function fn1(arr) {
if (arr.length === 1) {
return arr[0];
} else {
return arr[0] + fn2(arr.slice(1));
}
}
function fn2(arr) {
if (arr.length === 1) {
function fn1(arr) {
if (arr.length === 1) {
return arr[0];
} else {
return arr[0] + fn2(arr.slice(1));
}
}
function fn2(arr) {
if (arr.length === 1) {
function tokenize(json) {
var regex = /(true|false|null|".*?[^\\]"|\d+|\[|\]|{|})/g
return json.match(regex);
}
function cast(data) {
if (typeof data === 'string') {
if (data.match(/".*?[^\\]"/)) { return data.slice(1, -1).replace(/\\/g, ""); }
if (data.match(/\d+/)) { return Number(data); }
if (data === 'true' || data == 'false') { return data === 'true'; }
function tokenize(json) {
var regex = /(true|false|null|".*?"|\d+|\[|\]|{|})/g
return json.match(regex);
}
function cast(data) {
if (typeof data === 'string') {
if (data.match(/".*?"/)) { return data.slice(1, -1); }
if (data.match(/\d+/)) { return Number(data); }
if (data === 'true' || data == 'false') { return Boolean(data); }
(def relations {:number-of ["start = number filler food
number = '{number}'
filler = #'[^{}]*'
food = '{food}'"]
:with ["start = food #'with|/w' includes+
includes = filler include
filler = #'[^{}]*'
include = '{include}'
food = '{food}'"]})
(def relations {:number-of ["start = number filler food
number = '{number}'
filler = #'[^{}]*'
food = '{food}'"]
:with ["start = food #'with|/w' includes+
includes = filler include
filler = #'[^{}]*'
food = '{food}'"]})
/*
Asychronous functions wait for something to happen outside of the javascript
code, BUT without blocking the rest of the javascript code. For example if you
make a request to a database to get data, while the request is traveling to
the database and the response is traveling back, the rest of your code will
continue to run instead of leaving the CPU idle. Then when the response comes
back, the callback code gets run. If the rest of the program hasn't finished
running, the program will finish running and then the callback code will run.
fetch('https://connect.stripe.com/oauth/token', {
method: 'post',
headers: {
client_secret: process.env.STRIPE_SECRET_KEY,
code: req.query.code,
grant_type: 'authorization_code'
}
}).then(function(err, response) {
console.log(err);
});