Skip to content

Instantly share code, notes, and snippets.

View dheavy's full-sized avatar

Davy Peter Braun dheavy

View GitHub Profile
@dheavy
dheavy / array-matrix.js
Last active January 19, 2016 15:49
JS array matrix implementation
// ES5
Array.matrix = function(numRows, numCols, initialValue) {
var matrix = [];
for (var i = 0; i < numRows; ++i) {
var columns = [];
for (var j = 0; j < numCols; ++j) {
columns[j] = initialValue;
}
matrix[i] = columns;
}
// In the exemple, each nested array is a "row", and a set of grades for a student.
const grades = [[89, 77, 78],[76, 82, 81],[91, 94, 89]],
total = 0,
average = 0.0;
// Columnar approach: get average from student.
for (let row = 0; row < grades.length; row++) {
for (let col = 0; col < grades[row].length; col++) {
total += grades[row][col];
}
@dheavy
dheavy / hashtable-simple.js
Created March 30, 2016 08:37
Simple Hash Table implemented with separate chaining then open addressing collision strategy
function HashTable() {
this._bucketSize = 23;
this._buckets = [];
this._buckets.length = this._bucketSize;
}
HashTable.prototype.computeHash = function (key) {
var total = 0;
for (var i = 0; i < key.length; i++) {
total += key.charCodeAt(i);
@dheavy
dheavy / access_from_web.md
Created July 18, 2017 13:12 — forked from jasperf/access_from_web.md
MySQL Commands to create users, database, password and grant necessary privileges from the command line
mysql> CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'user_name'@'localhost' WITH GRANT OPTION;
mysql> CREATE USER 'user_name'@'%' IDENTIFIED BY 'password';

mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'user_name'@'%' WITH GRANT OPTION;

Principles of Adult Behavior

  1. Be patient. No matter what.
  2. Don’t badmouth: Assign responsibility, not blame. Say nothing of another you wouldn’t say to him.
  3. Never assume the motives of others are, to them, less noble than yours are to you.
  4. Expand your sense of the possible.
  5. Don’t trouble yourself with matters you truly cannot change.
  6. Expect no more of anyone than you can deliver yourself.
  7. Tolerate ambiguity.
  8. Laugh at yourself frequently.
@dheavy
dheavy / Dockerfile
Created April 21, 2024 21:40
vespa-flyio-dockerfile
# Use the specified Vespa image
FROM vespaengine/vespa:8.277.17
# Set the working directory
WORKDIR /opt/vespa
# Change to vespa user before running the script
USER vespa
# Copy the custom startup script to the container and make it executable in one step
@dheavy
dheavy / start-vespa.sh
Created April 21, 2024 21:42
vespa-flyio-ulimit-shell
#!/bin/bash
# Try to set ulimits
ulimit -n 262144 || echo "Failed to set nofile limit"
ulimit -u 409600 || echo "Failed to set nproc limit"
ulimit -c unlimited || echo "Failed to set core limit"
# Start Vespa configuration server and services
if [ "$1" == "configserver" ]; then
echo "Starting Vespa Config Server..."