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 / instructions.md
Last active May 29, 2023 12:13
Debugging Node with Webstorm running on a remote server

Debugging node running on a remote server

Node uses a TCP interface for debugging, so if you can get a handle on the right port, you can debug apps running remotely. This means you can run through code on staging, Vagrant, etc. The following shows you how to start node with the debug flag and use an SSH tunnel to access the right port.

Things you need:

  • ssh access to the server
  • ability to restart node app with --debug flag or node-inspector installed on server

Debugging using Webstorm

@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 / 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 / countries.jade
Last active August 28, 2015 16:24
Two letter country code jade dropdown
select
option(selected disabled) Pick your country
option(value='US') United States
option(value='AF') Afghanistan
option(value='AX') Åland Islands
option(value='AL') Albania
option(value='DZ') Algeria
option(value='AS') American Samoa
option(value='AD') Andorra
option(value='AO') Angola
@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>";
{
role: 'admin',
enabled: true,
firstname: 'Test',
lastname: 'User',
identities: {
basic: {
username: 'admin',
salt: '225384010328',
hash: '885f59a76ea44e1d264f9da45ca83574fbe55e3e7e6c51afe681730b45c7bb03'
@pajtai
pajtai / test-ssl.sh
Last active September 27, 2016 14:25
Test open ssl cyphers for a domain. e.g.: ./test-ssl.sh example.com
#!/usr/bin/env bash
# source: http://superuser.com/a/224263/41059
# OpenSSL requires the port number.
SERVER=$1:443
DELAY=1
echo Obtaining cipher list from $(openssl version).
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')
@pajtai
pajtai / rewrite-rules.php
Last active March 29, 2018 06:33
Wordpress Rewrite Rules
<?php
add_action( 'init', function () {
add_rewrite_rule('blog/market/([^/]+)/category/([^/]+)/page/([0-9]{1,})/?$', 'index.php?pagename=blog&pg=$matches[3]&market=$matches[1]&category=$matches[2]', 'top');
add_rewrite_rule('blog/market/([^/]+)/category/([^/]+)/?$', 'index.php?pagename=blog&market=$matches[1]&category=$matches[2]', 'top');
add_rewrite_rule('blog/market/([^/]+)/page/([0-9]{1,})/?$', 'index.php?pagename=blog&pg=$matches[2]&market=$matches[1]', 'top');
add_rewrite_rule('blog/market/([^/]+)/?$', 'index.php?pagename=blog&market=$matches[1]', 'top');
add_rewrite_rule('blog/category/([^/]+)/page/([0-9]{1,})/?$', 'index.php?pagename=blog&paged=$matches[2]&category=$matches[1]', 'top');
add_rewrite_rule('blog/category/([^/]+)/?$', 'index.php?pagename=blog&category=$matches[1]', 'top');
@pajtai
pajtai / modify-query.php
Last active April 4, 2018 14:56
modify core query
<?php
add_action('pre_get_posts', function($query) {
if ($query->is_home() && $query->is_main_query()) {
$query->set('posts_per_page', 8);
$currentMarket = get_query_var('market');
$currentCategory = get_query_var('category');
$taxQuery = getTaxonomyQuery($currentMarket, $currentCategory);
if ($taxQuery) {
<?php
$pagination = paginate_links( array(
'base' => get_pretty_url($currentMarket, $currentCategory) . '%_%',
'format' => '/page/%#%',
'current' => $paged,
'total' => $posts->pagination()->total,
'prev_next' => false
));
function get_pretty_url( $root, $marketSlug, $topicSlug ) {