Skip to content

Instantly share code, notes, and snippets.

View gistfrojd's full-sized avatar

Fröjd Fröjdson gistfrojd

  • Fröjd Interactive
  • Stockholm
View GitHub Profile
@gistfrojd
gistfrojd / default.vcl
Last active March 24, 2016 07:48
Varnish 4.0 Configuration for Wordpress (Beware - Needs more testing) (this file has moved to https://github.com/Frojd/Manual)
#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples.
@gistfrojd
gistfrojd / mongoose-sorting.js
Created July 15, 2015 07:26
How to perform sorting in mongoose (from http://stackoverflow.com/a/15081087)
Room.find({}).sort('-date').exec(function(err, docs) { ... });
Room.find({}).sort({date: -1}).exec(function(err, docs) { ... });
Room.find({}).sort({date: 'desc'}).exec(function(err, docs) { ... });
Room.find({}).sort({date: 'descending'}).exec(function(err, docs) { ... });
Room.find({}, null, {sort: {date: -1}}, function(err, docs) { ... });
Room.find({}, null, {sort: [['date', -1]]}, function(err, docs) { ... });
@gistfrojd
gistfrojd / boilerplate-function.js
Last active March 24, 2016 07:48
Javascript Styleguide (these files has moved to https://github.com/Frojd/Manual)
/**
* Example of a Email utils library
*
* Usage:
* var EmailUtils = require("./utils");
* EmailUtils.validateEmail("hello@frojd.se");
*/
"use strict";
@gistfrojd
gistfrojd / default.vcl
Last active March 24, 2016 08:10
Varnish 3.0 Configuration for Wordpress (this file has moved to https://github.com/Frojd/Manual)
# Normal users
backend default {
.host = "127.0.0.1";
.port = "8080";
}
# WP-Admin users
backend admin_backend {
.host = "127.0.0.1";
.port = "8080";
@gistfrojd
gistfrojd / gist:7fba207ab44272741ac0
Created December 11, 2014 09:58
How to handle separate read and write servers in mongoose
var uri = "mongodb://write.server.com/mydatabase,read.server.com/mydatabase?replicaSet=rs-test&readPreference=nearest";
connection = mongoose.connection;
mongoose.connect(uri, {});
@gistfrojd
gistfrojd / gist:193e640b0bf74db5020f
Created November 20, 2014 13:49
mongoose mocha ensureIndex
// Mongoose.js and mocha/should testing with unique index constraints
// Use this snippet in your test, change the values to match your indexes
beforeEach(function(done) {
mongoose.connection.models.YourModelNameHere.collection.ensureIndex(
{
fieldWithConstraint: 1,
anotherFieldWithConstraint: 1
},
{
@gistfrojd
gistfrojd / gist:58eb1597b55eea15c799
Created November 3, 2014 07:18
SQL server update statistics
/* Updates all statistics */
USE <database>
EXEC sp_updatestats
@gistfrojd
gistfrojd / gist:d0d08581ee08a891e0ea
Created October 14, 2014 07:47
.NET MVC Bundles when 404 not found
<!-- To get bundles to work when not debugging (as in minified) you might need this in web.config -->
<!-- It's only the bundlemodule you need, the other is just to show where it should be placed -->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="BundleModule" type="System.Web.Optimization.BundleModule"/>
</modules>
</system.webServer>
@gistfrojd
gistfrojd / wp-config-custom-settings.php
Last active March 24, 2016 07:49
An example file that contains extra settings for Wordpress wp-config.php (this file has moved to https://github.com/Frojd/Manual)
<?php
// Recognize protocol from load balancer/varnish
if (isset($_SERVER["HTTP_X_FORWARDED_PROTO"]) && $_SERVER["HTTP_X_FORWARDED_PROTO"] == "https") {
$_SERVER["HTTPS"] = "on";
}
// Forward ip from load balancer/varnish
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$_SERVER["REMOTE_ADDR"] = $_SERVER["HTTP_X_FORWARDED_FOR"];
@gistfrojd
gistfrojd / bucketpolicy.txt
Last active August 29, 2015 14:06
S3 Bucket Policy - Read All
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",