Skip to content

Instantly share code, notes, and snippets.

View todgru's full-sized avatar

todgru

  • Portland, OR
View GitHub Profile
@todgru
todgru / promise.js
Last active July 6, 2017 20:53
adding a delay inside a Promise
// Sometimes I have a promise chain that returns out of a promise before
// the the execution is actually completed. Maybe i'm not returning correctly?
// Anyway, might be a common problem for a newb, like me.
// here is a way to add a delay in the promise chain to wait for the previous
// promise to complete. This is NOT best practice, but maybe it can be used as
// a troubleshooting tool.
//
...
.then(() => {...})
.then(() => {
@todgru
todgru / cannot-read-property-getTableName.md
Last active August 21, 2018 17:14
TypeError: Cannot read property 'getTableName' of undefined node js, Sequelize, Mockery, Sinon, Ava, stub, stubs, stubbing, mock, mocking, is not a function

TypeError: Cannot read property 'getTableName' of undefined or foo.bar is not a function

I've had this error on numerous occasions. Here are a few things to look for:

  • Check that the table name that is included in the query is spelled correctly, check that is it defined correctly (for sequelize).
  • If you are running tests and using Mockery, check that Mockery is setup correctly. Try removing Mockery and running the test.
  • Check that if you are trying to stub with Sinon, that Mockery isn't ALSO trying to stub out the same object.
  • Example of stubbing with Sinon instead of Mockery: https://gist.github.com/todgru/e439373af2488eefc30ae8bd1fe3864a
@timneutkens
timneutkens / index.js
Last active March 4, 2024 14:01
Clear console/terminal in node.js the right way
const readline = require('readline')
const blank = '\n'.repeat(process.stdout.rows)
console.log(blank)
readline.cursorTo(process.stdout, 0, 0)
readline.clearScreenDown(process.stdout)
@tekemperor
tekemperor / rpi3-bt-keyboard.txt
Created July 22, 2016 01:46
Connect Apple Wireless Keyboard to Raspberry Pi 3 in Raspbian
sudo service bluetooth status # Verify bluetooth is active.
sudo bluetoothctl # Lauch bluetooth subshell.
agent on # [No idea what this does.]
default-agent # [No idea what this does.]
scan on # Displays a list of available devices.
pair XX:XX:XX:XX:XX:XX # This prepares a potential connection, the X's represent your device ID
# A "PIN code" will be displayed, type it on the keyboard and press "enter".
trust XX:XX:XX:XX:XX:XX # Adds device to trusted devices, this survives reboot.
connect XX:XX:XX:XX:XX:XX # Connect to the device now.
exit # Return to previous shell.
@noelboss
noelboss / git-deployment.md
Last active May 16, 2024 20:41
Simple automated GIT Deployment using Hooks

Simple automated GIT Deployment using GIT Hooks

Here are the simple steps needed to create a deployment from your local GIT repository to a server based on this in-depth tutorial.

How it works

You are developing in a working-copy on your local machine, lets say on the master branch. Most of the time, people would push code to a remote server like github.com or gitlab.com and pull or export it to a production server. Or you use a service like deepl.io to act upon a Web-Hook that's triggered that service.

@Telling
Telling / f2bufwnginx.md
Created February 14, 2016 13:35
Setup fail2ban (v0.8.11) with ufw and nginx

Setup fail2ban (v0.8.11) with ufw and nginx on Ubuntu 14.04

Install fail2ban & ufw

If you haven't already, install fail2ban and ufw:

sudo apt-get install fail2ban ufw

Now make a copy of the fail2ban configuration, and name it jail.local:

@oanhnn
oanhnn / using-multiple-github-accounts-with-ssh-keys.md
Last active May 22, 2024 07:55
Using multiple github accounts with ssh keys

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@davestevens
davestevens / LetsEncrypt.md
Last active March 28, 2024 10:35
Let’s Encrypt setup for Apache, NGINX & Node.js

Let's Encrypt

Examples of getting certificates from Let's Encrypt working on Apache, NGINX and Node.js servers.

Obtain certificates

I chose to use the manual method, you have to make a file available to verify you own the domain. Follow the commands from running

git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
@JadedEvan
JadedEvan / TUTORIAL-ruby-instance-methods-versus-attribute-accessors.md
Last active July 20, 2016 16:54
An article highlighting the difference in using instance methods over attribute accessors in Ruby classes. A fundamental concept that is often overlooked by beginner and intermediate Rubyists that can lead to cleaner, more predictable code

Ruby Design Patterns - Methods over Attributes

Overview

The objective of this article is to highlight the subtle differences between using class attributes and class methods in Ruby. Both offer a valid way to manipulate the state of an instance of a class. Things can get increasingly complex, hard to test and hard to maintain as more instance variables are introduced. Beginner and intermediate Rubyists often miss this subtle but important point which can introduce bugs that may be hard to fix in their native habitat.

The reasons I prefer to use methods over instance variables:

  • Increases predictability of method calls
  • Increases predictability when testing
@joerx
joerx / index.js
Last active May 17, 2023 12:58
Mocking S3 in Node.js using Sinon
var Aws = require('aws-sdk');
var sinon = require('sinon');
// Only works for 'createBucket', 'update' and a few others since most API methods are generated dynamically
// upon instantiation. Very counterintuitive, thanks Amazon!
var createBucket = sinon.stub(Aws.S3.prototype, 'createBucket');
createBucket.yields(null, 'Me create bucket');
// For other methods, we can 'assign' the stubs to the proto, already defined function won't be overridden
var listBuckets = Aws.S3.prototype.listBuckets = sinon.stub();