Skip to content

Instantly share code, notes, and snippets.

View chabgood's full-sized avatar
🏠
Working from home

Chris Habgood chabgood

🏠
Working from home
View GitHub Profile
@arpitbbhayani
arpitbbhayani / taxonomy.sql
Last active July 29, 2023 15:09
Quickly populate random 5 million + rows in a taxonomy using SQL
# create table topics!
create table topics (
id int primary key auto_increment,
name varchar(256),
parent_id int null,
type smallint not null,
foreign key (parent_id) references topics(id),
index(type)
);
@exAspArk
exAspArk / self-signed-ssl-mongo.sh
Last active April 6, 2024 19:38
Self-signed SSL Certificate with OpenSSL on MacOS | MongoDB
openssl genrsa -out CAroot.key 2048
openssl req -new -key CAroot.key -out CAroot.csr # CN should be different from the certificates below
openssl req -x509 -days 1825 -key CAroot.key -in CAroot.csr -out CAroot.crt
cat CAroot.crt CAroot.key > CAroot.pem
openssl genrsa -out mongod.key 2048
openssl req -new -key mongod.key -out mongod.csr
openssl x509 -req -days 1825 -in mongod.csr -CA CAroot.pem -CAkey CAroot.key -CAcreateserial -out mongod.crt
cat mongod.crt mongod.key > mongod.pem
package main
import (
"database/sql"
"gopkg.in/gorp.v1"
"log"
"strconv"
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
@palkan
palkan / Gemfile
Last active January 28, 2021 21:38
FactoryProf: profiler for your FactoryGirl
# if you want to render flamegraphs
gem "stackprof", require: false # required by flamegraph
gem "flamegraph", require: false
@hugodias
hugodias / digital_ocean_setup.md
Created February 29, 2016 19:15 — forked from ChuckJHardy/digital_ocean_setup.md
DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 Setup Instructions

DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3

SSH into Root

$ ssh root@123.123.123.123

Change Root Password

@learncodeacademy
learncodeacademy / cluster.md
Created October 9, 2014 18:11
Node Cluster - Enhance your node app by using all the cores of your processor.

Here's all you have to do to add clustering to your node.js application.

  • save this code as cluster.js, and run cluster.js instead of server.js (or /bin/www, or whatever it's called for your project)
  • the only line you'll need to change is the last line - it needs to point to the location of your server.js file
var cluster = require('cluster');

if (cluster.isMaster) {
  // Count the machine's CPUs
 var cpuCount = require('os').cpus().length;
@davidcelis
davidcelis / nginx.conf
Last active June 15, 2018 13:11
Nginx configuration to redirect HTTP traffic to HTTPS (Puma)
upstream puma {
server unix:///var/www/app/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80 default deferred;
server_name example.com;
rewrite ^/(.+) https://example.com/$1 permanent;
}
@leemour
leemour / time_spec.rb
Created April 26, 2014 15:16
RSpec time stubbing without Timecop
#Timecop is fun, but you don't need a whole gem for that. Just use
#Time.stub(:now), e.g.
describe "time" do
before do
@fake_time = Time.now
Time.stub(:now) { @fake_time }
end
it "is equal" do
Time.now.should == Time.now # now it passes
@ChengLong
ChengLong / ruby_cron.md
Created April 17, 2014 06:34
Run Ruby Script using cron job

If you see this error when cron job runs a ruby script:

'require': cannot load such file ...

And you are using bundler e.g. require 'bundler/setup'. It's probably because the directory where cron runs the script is not correct, resulting in bundler fails to load gems.

Simply changed the directory to fix it, i.e.

* * * * * /usr/local/bin/ruby -C /home/example/scripts example_script.rb >>/home/example/log/cron.log 2>&1

@SirRawlins
SirRawlins / url_matcher.rb
Last active August 12, 2022 19:42
RSpec url matcher.
# Drop this into /spec/support/matchers
# Usage: result.should be_url
# Passes if result is a valid url, returns error "expected result to be url" if not.
# Matcher to see if a string is a URL or not.
RSpec::Matchers.define :be_url do |expected|
# The match method, returns true if valie, false if not.
match do |actual|
# Use the URI library to parse the string, returning false if this fails.
URI.parse(actual) rescue false