This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char read_input_char() | |
{ | |
char c; | |
c = getch(); | |
if (c == '\033') { // if the first value is esc | |
c = getch(); // skip the [ | |
switch(c = getch()) { // the real value | |
case 'A': | |
// code for arrow up | |
return 'w'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This should be an external database in real development. This is just for simplified demonstration. | |
const memoryDB = { | |
users: {}, | |
usersCount: 0 | |
} | |
const express = require('express') | |
const obsidian = require('obsidian-js') | |
const bodyParser = require('body-parser') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var delegationObjects = { | |
Employee: (name) => Object.assign({ | |
name, | |
hello: () => console.log(`Hi, I'm ${name}`) | |
}), | |
Fulltime: (name, role) => Object.assign(delegationObjects.Employee(name), { | |
role, | |
weeklyHours: 40 | |
}), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Employee() { | |
this.name = ''; | |
this.dept = 'general'; | |
} | |
function Manager() { | |
Employee.call(this); | |
this.reports = []; | |
} | |
Manager.prototype = Object.create(Employee.prototype); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var subclasses = { | |
Employee: function(name, role) { | |
this.name = name; | |
this.sayHi = function() { | |
console.log(this.name + ": I work " + this.weeklyHours + "hrs/week"); | |
}; | |
if(role === "manager" || role === "salesman") return subclasses.Fulltime(name, role); | |
else if(role === "temporary" || role === "traveling") return subclasses.Parttime(name, role); | |
}, | |
Fulltime: function(name, role) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
board = [] | |
for x in range(5): | |
board.append(["O"] * 5) | |
def print_board(board): | |
for row in board: | |
print " ".join(row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var findLeft = function(grid, row, col) { | |
if(col > 0) { | |
return grid[row][col - 1]; | |
} else { | |
return undefined; | |
} | |
}; | |
var findRight = function(grid, row, col) { | |
if(col < grid[row].length-1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getCurrentRow = function(board, row, col) { | |
return board[row]; | |
}; | |
var getCurrentCol = function(board, row, col) { | |
var flatCol = []; | |
board.forEach(function(row) { | |
flatCol.push(row[col]); | |
return row; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sortedIndex = function (array, value) { | |
var low = 0, | |
high = array.length; | |
while (low < high) { | |
var mid = (low + high) >>> 1; | |
if (array[mid] < value) low = mid + 1; | |
else high = mid; | |
} | |
return low; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person() { | |
if(typeof Person.instance === 'object') | |
return Person.instance; | |
Person.instance = this; | |
return this; | |
} |
NewerOlder