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 / windows.h__.js
Created November 18, 2012 11:53
windows.h.js INFINITY
var ffi = require('ffi'),
ref = require('ref'),
Struct = require('ref-struct'),
Library = require('./Library'),
Type = ref.Type,
NULL = ref.NULL,
isNull = ref.isNull;
var groups = ['libs', 'types', 'structs', 'callbacks', 'enums'];
@pajtai
pajtai / show.jade
Created November 10, 2012 20:47 — forked from kembuco/show.jade
Underscore template in jade
script(id='greeting', type='text/html')
div#example
Hello my name is, <%= name %>!
@pajtai
pajtai / readme.md
Created October 26, 2012 01:39 — forked from coolaj86/how-to-publish-to-npm.md
How to publish packages to NPM

Getting Started with NPM (as a developer)

If you haven't already set your NPM author info, now you should:

npm set init.author.name "Your Name"
npm set init.author.email "you@example.com"
npm set init.author.url "http://yourblog.com"

npm adduser

@pajtai
pajtai / functions.php
Last active September 18, 2015 02:50
Add custom element into Wordpress RSS feeds
add_action('atom_entry', 'add_thumbnail_to_feed');
add_action('rdf_item', 'add_thumbnail_to_feed');
add_action('rss_item', 'add_thumbnail_to_feed');
add_action('rss2_item', 'add_thumbnail_to_feed');
function add_thumbnail_to_feed(){
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' );
$url = $thumb['0'];
echo "<thumbnail>$url</thumbnail>";
@pajtai
pajtai / open-and-keep-alive.sh
Last active August 29, 2015 14:25
Robust way of opening an closing ssh tunnels without having to depend on active connections
#!/usr/bin/env bash
#set -x # for debugging
SSH_HOST="user@www.sample.com"
# using -f and -o exitOnForwardFailure is helpful, but if you are managing processes that restart and you want to keep
# the tunnel open even after a restart this can be difficult (e.g. nodemon with a remote mongo, mysql, elasticsearch, etc)
#
# instead you can open the tunnels and close them on script exit
@pajtai
pajtai / example.conf
Created July 26, 2015 06:59
Proxy Kibana4 from a subdirectory
server {
listen 80;
server_name example.com;
location /analytics {
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.users;
# the only tricky part is that kibana won't work without the rewrite rule
# to proxy from another port and use "location /", you can leave out the rewrite rules
rewrite ^/analytics(.*)$ $1 break;
@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
@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 / _ 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

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"