Skip to content

Instantly share code, notes, and snippets.

Peter Ajtai pajtai

Block or report user

Report or block pajtai

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View todos.model.js
'use strict';
const mongoose = require('mongoose');
module.exports = (app) => {
const tasksSchema = mongoose.Schema({
title: String,
done: {
type: Boolean,
View todos.controller.js
'use strict';
const express = require('express');
module.exports = (app) => {
const router = express.Router();
router.get('/', (req, res) => {
View version.controller.js
'use strict';
const express = require('express');
const { version } = require('../package');
module.exports = () => {
const router = express.Router();
router.get('/', (req, res) => {
View autoload.js
const app = {};
consign()
.include('api')
.into(app);
const flattened = flatten(app);
Object.entries(flattened).forEach(([route, router]) => {
const baseRoute = `/${route.replace(/\.controller$/, '').replace(/\./g, '/')}`;
@pajtai
pajtai / controller.js
Last active May 4, 2018
A minimal express controller
View controller.js
'use strict';
const express = require('express');
module.exports = () => {
const router = express.Router();
router.get('/', (req, res) => {
res.json([]);
});
View index.js
'use strict';
require('dotenv').config();
const express = require('express');
const app = express();
const helmet = require('helmet');
const pino = require('pino');
const logger = pino({
level: process.env.LOG_LEVEL
View paging-links.html
View paging.php
<?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 ) {
@pajtai
pajtai / modify-query.php
Last active Apr 4, 2018
modify core query
View modify-query.php
<?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) {
@pajtai
pajtai / rewrite-rules.php
Last active Mar 29, 2018
Wordpress Rewrite Rules
View rewrite-rules.php
<?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');
You can’t perform that action at this time.