Skip to content

Instantly share code, notes, and snippets.

Avatar

Omer Goldberg Arieg419

View GitHub Profile
View db.json
{
"users": [
{
"id": "40",
"firstName": "Alex",
"age": 13,
"companyId": "2"
},
{
"id": "41",
View DAOVotingContract.js
const DAOVotingContract = {
balance: 400,
id: 3,
authorizedVoters: [
{ nodeId: "A", address: "Alice" },
{ nodeId: "B", address: "Eve" },
{ nodeId: "A", address: "Gal Gadot" }
],
votes: [
{
View MoveFundsAfterArbitraryDate.js
const MoveFundsAfterDateContract = {
balance: 400,
expirationDate: new Date("October 13, 2016 11:13:00"),
id: 2,
fromAddress: "Bob",
call: function() {
return { getBalance: this.balance, getFromAddress: this.fromAddress };
},
send: function() {
return { changeBalance: this.changeBalance };
View CounterContract.js
const CounterContract = {
balance: 0,
counter: 0,
incrementValue: function() {
this.counter++;
},
id: 1,
fromAddress: "Alice",
call: function() {
return {
View purifyingSummary.js
let a = 4;
let b = 5;
let c = 6;
const updateTwoVars = (a, b, c) => [b++, a * b];
const updateRes = updateTwoVars(a,b,c);
b = updateRes[0]
c = updateRes[1]
View curryingIntro.js
const bankStatement =
name =>
location =>
balance =>
`Hello ${name}! Welcome to the bank of ${location}. Your current balance is ${balance}`;
const statementExpectingLocation = bankStatement("Omer");
const statementExpectingBalance = statementExpectingLocation("NYC");
const bankStatementMsg = statementExpectingBalance("100 million"); // wishful thinking?
View functionAsObjProperty.js
const functionAsObjectProperty = {
print: (value) => console.log(value)
};
functionAsObjectProperty.print("mic check"); // "mic check"
View unpureFunction.js
let a = 4;
let b = 5;
let c = 6;
const updateTwoVars = (a) => {
b++;
c = a * b;
}
updateTwoVars(a);
console.log(b,c); // b = 6, c = 24
View nonPureFunction.js
async function getUserToken(id) {
const token = await getTokenFromServer(id);
return token;
}
View functionThatReturnsFunction.js
const addWrapper = () => (x,y) => x + y;
const add = addWrapper();
const sum1 = add (1,2); // 3
// Or we could do it like this
const sum2 = addWrapper()(4,4); // 8