Skip to content

Instantly share code, notes, and snippets.

View todgru's full-sized avatar

todgru

  • Portland, OR
View GitHub Profile
@srt32
srt32 / gist:8535548
Created January 21, 2014 06:59
nginx.conf file for running multiple apps using passenger
#user nobody;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@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
@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(() => {
@VantivSDK
VantivSDK / gist:2120291
Last active November 7, 2017 16:09
Curl example
$curl --header "Content-Type: text/xml" -d@<File with XML content> https://www.testvantivcnp.com/sandbox/communicator/online
@eveevans
eveevans / StreamSave.rb
Created May 10, 2012 23:06
Ruby script for save mp3 stream
require 'rubygems'
require 'net/http'
require 'uri'
BIT_RATE = 48 #6kbxseg * 60 seg (a min) * 15min
TAMO_CORTE = (BIT_RATE/8) * 60 * 15 #en KB
url = URI.parse('http://186.1.15.253:8000/')
Net::HTTP.start(url.host, url.port) do |http|
@ilguzin
ilguzin / gist:6606011
Last active March 9, 2018 07:46
How to convert Java Key Store file to pem/key for nginx
1. Convert our ".jks" file to ".p12" (PKCS12 key store format):
keytool -importkeystore -srckeystore oldkeystore.jks -destkeystore newkeystore.p12 -deststoretype PKCS12
1.1. List new keystore file contents:
keytool -deststoretype PKCS12 -keystore newkeystore.p12 -list
2. Extract pem (certificate) from ".p12" keysotre file:
@kreeger
kreeger / mw2md.rb
Created March 5, 2012 22:43
Ruby: Convert MediaWiki to Markdown
#!/usr/bin/env ruby
require 'rubygems'
require 'optparse'
require 'maruku'
require 'wikicloth'
require 'tidy_ffi'
require 'pandoc-ruby'
opts = {}
OptionParser.new do |o|
@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
@todgru
todgru / git_branch_info.md
Last active November 10, 2018 05:30
Todd's git branch info! merge move delete ours fix conflicts rebase
@todgru
todgru / bootable-usb-drive.md
Last active January 8, 2019 07:25
osx debian usb asus 900A EEE PC

I created a bootable usb drive in disk utility

then ran diskutil list to find the identifier

/dev/disk2s1 in my case

make sure to unmount the drive

then dd