Skip to content

Instantly share code, notes, and snippets.

View mortenege's full-sized avatar

Ege mortenege

View GitHub Profile
# Windows 7 Memory and Space tricks
## Clear space on C drive by disabling 'Hibernation'
have a look at the `Hiberfil.sys`-file at the root of C. This will be huge and can be up to the amount of ram in the system (8gb RAM -> <8gb occupied disk space)
To disable Hibernation (A **Warning** is due, I guess) enter `powercfg -h off` and this will delete the file immediately. To enable hibernation again `powercfg -h on`.
## Manage Virtual Memory
@mortenege
mortenege / EasyTemplateEngine.js
Created September 12, 2018 15:21
Inject object data into string via templating
var fillTemplate = function (str, obj) {
var regex = /{{ *(\w+) *}}/g;
return str.replace(regex, function(lit, key){
if (!obj.hasOwnProperty(key)) return lit;
return obj[key];
})
}
// Example usage
var str = "<div><h1>{{ post_title }}</h1><small>{{ author }}</small><div>{{ content }}</div></div>";
@mortenege
mortenege / Custom Laravel user Provider.md
Created August 27, 2018 04:35
How to set up a custom user provider in laravel

In the boot method of app\Providers\AuthServiceProvider.php

Auth::provider('wpdriver', function ($app, array $config) {
    return new WPUserProvider($app['hash'], $config['model']);
});

In config\auth.php modify providers with

@mortenege
mortenege / WPUserProvider.php
Created August 27, 2018 04:30
Use a Wordpress databse structure with Laravel
<?php
namespace App\Extensions;
use App\User;
use Illuminate\Support\Str;
use MikeMcLin\WpPassword\Facades\WpPassword;
use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Contracts\Auth\Authenticatable;
@mortenege
mortenege / GitHub SSH without agent
Created August 24, 2018 04:57
How to set up using GitHub SSH with keys without agent
1. This assumes an SSH keypair exists, usually in ~/.ssh (windows C:\Users\<username>\.ssh)
2. This assumes a git repository exists, otherwise create one as usual `git init`
3. Create a Repository on GitHub
4. Add SSH key to GitHub
5. Add the remote origin from gthub
@mortenege
mortenege / reverse_proxy_with_apache_and_vagrant.md
Created March 4, 2018 07:19
Reverse Proxy with Apache and Vagrant

Reverse Proxy with Apache and Vagrant

This guide will describe how to set up a reverse proxy in Apache that can redirect traffic to a backend of our choice. For this guide we will be using Vagrant as our development environment. This guide will cover topics such as:

  • How to set up an Apache server using Vagrant
  • How to configure reverse proxy for Apache

First step is to set up an Apache server using Vagrant. More on how to use Vagrant can be found in the docs.

Step 1

@mortenege
mortenege / swap_apache_default_site.md
Created March 4, 2018 07:14
Swap Apache default site

Swap Apache default site

This post builds on top of this post where we set up reverse proxy in Apache to redirect traffic to a backend of our choice. In this guide we will swap out the default apache site on port 80 with our proxy server. We edit 001-mysite.conf to use port 80 and forward all paths to our backend.

<VirtualHost *:80>
 ProxyPass "/" "http://127.0.0.1:8080/"
 ProxyPassReverse "/" "http://127.0.0.1:8080/"
</VirtualHost>
@mortenege
mortenege / websockets_using_apache_reverse_proxy.md
Created March 4, 2018 07:10
WebSockets using Apache Reverse Proxy

WebSockets using Apache Reverse Proxy

This post will cover how to configure our already running server [1, 2] to proxy websocket connections to a backend of our choice. We will continue using Vagrant to provision the guest machine.

Step 1

Clone or download a simple websocket server into our vagrantfolder (and extract if an archive).

Step 2

Modify 001-mysite.conf to include our websocket redirect.

@mortenege
mortenege / manage_backend_servers_with_supervisord.md
Created March 4, 2018 07:06
Managing backend servers with Supervisor

Managing backend servers with Supervisor

This post will describe how we can run our different backends without any worry, mostly from crashing and then recovering. We will build on top of our already configurated Vagrant guest machine running Apache with reverse proxy [1, 2, 3]. Until now we are running our backend servers (SimpleHTTPServer and simple-websocket-server) directly from our provisioning script as a background daemon. This means that if we halt the machine and bring it back up, our servers are not running and need to be started again. It also means that if one of our backends experiences a crash (believe me, it happens) it does not recover

@mortenege
mortenege / django_backend_with_vagrant.md
Created March 4, 2018 07:01
Django backend with Vagrant

Django backend with Vagrant

This post will cover how to configure our vagrant guest machine [1, 2, 3, 4] to run a django server instead of our previous prop backends. We will continue using Vagrant and introduce virtualenv for our Django project.

Step 1

We create a virtual environment and install django. We start off by installing python virtualenv and set up an environment in our vagrantfolder so we will have it ready on boot.

$ pip install virtualenv
~/vagrant$ mkdir django