Skip to content

Instantly share code, notes, and snippets.

View pajtai's full-sized avatar

Peter Ajtai pajtai

  • https://www.soliddigital.com/
  • Portland, Oregon
View GitHub Profile
@pajtai
pajtai / redirect.js
Created June 18, 2014 21:43
Express 4 redirect www.domain.com to domain.com
express.use(function(req,res,next){
var host = req.get('host');
if(/^www\./.test(host)){
host = host.substring(4, host.length);
res.writeHead(301, {'Location':req.protocol + '://' + host + req.originalUrl,
'Expires': new Date().toGMTString()});
res.end();
} else {
next();
}
@pajtai
pajtai / migrate.js
Last active August 29, 2015 14:04
gh core user migration to using identities
/* jshint node:true */
'use strict';
var _ = require('lodash'),
fs = require('fs');
migrateUsers();
migrateContentTypes();
function migrateUsers() {
@pajtai
pajtai / data.js
Last active August 29, 2015 14:04
mongo import / export grunt task breaking it apart into one file per document using a configurable db endpoint
/*jshint node:true*/
module.exports = function (grunt) {
'use strict';
var _ = require('lodash'),
path = require('path'),
sep = path.sep,
databases = require('./databases');
grunt.registerTask('data:deleteTemp', function() {
<head>
<base href="/trailing/">
</head>
<body>
<a href="go">GO GO GO</a>
</body>
<head>
<base href="/trailing">
</head>
<body>
<a href="go">GO GO GO</a>
</body>

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@pajtai
pajtai / _ using pf on macs.md
Last active August 29, 2015 14:15
Using pf for port forwarding on macs

Since ipfw is deprecated and removed on Yosemite and Maveriks, and there are no iptables on Mac you have to use pfctl for port forwarding.

This is important in Vagrant, where usually port 8080 is exposed, but you want to be able to use port 80 on your host browser.

Here is how to setup 80 <-> 8080 port forwarding on your mac (include empty lines at the end of each file... one of them is supposedly picky about it).

After adding the two files below as root, to start (enable) port forwarding do:

sudo pfctl -ef /etc/pf-vagrant.conf
@pajtai
pajtai / cleanup.md
Last active September 13, 2017 09:55
Cleaning up a Vagrant box before packaging

I tested the following script on a vagrant box.

The box was 850MB without the script, and 450 MB with the script.

The script was taken from chef/bento with just one modification.

screen shot 2015-02-08 at 3 27 20 pm

@pajtai
pajtai / mysqlDataBackup.sh
Last active August 29, 2015 14:22
Backup mysql data to a directory and clear directory of old files.
#!/usr/bin/env bash
set -e
#set -x # for debugging
MYSQL_PW=""
TTL=365
while test $# -gt 0; do
case "$1" in
-h|--help)
@pajtai
pajtai / mongoBackupData.sh
Last active August 29, 2015 14:22
Backup mongo data to a directory and clear directory of old files.
#!/usr/bin/env bash
set -e
#set -x # for debugging
# daily backups with logs crontab -e example:
# 0 1 * * * /home/user/path/to/this/file -u my-user -p 'my-pw' -d mydb -t 90 >>/home/user/logs/backup.log 2>&1
MONGO_PW=""
TTL=180