Skip to content

Instantly share code, notes, and snippets.

View koraysels's full-sized avatar

Koray S. koraysels

View GitHub Profile
@koraysels
koraysels / 0_reuse_code.js
Created February 4, 2014 09:59
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@koraysels
koraysels / functions.php
Last active August 29, 2015 14:15
add categories to your custom post type in wordpress (post type here is 'event')
require_once 'post-types/event.php';
// WP Menu Categories
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy( 'category', 'event', array(
'hierarchical' => true,
'label' => 'Categorieën',
'query_var' => true,
@koraysels
koraysels / windowOnload.js
Created February 20, 2015 12:54
the correct way to use window.onload
module.exports = function windowOnLoad(func) {
// pass the function you want to call at 'window.onload', in the function defined above
// assign any pre-defined functions on 'window.onload' to a variable
var oldOnLoad = window.onload;
// if there is not any function hooked to it
if (typeof window.onload != 'function') {
// you can hook your function with it
window.onload = func
} else { // someone already hooked a function
window.onload = function () {
@koraysels
koraysels / angular-clientcode.js
Created March 4, 2015 17:07
make angular $http behave like jQuery.ajax
var App = angular.module('app', ['ui.bootstrap', 'angularFileUpload'], function ($httpProvider) {
// Use x-www-form-urlencoded Content-Type
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
/**
* The workhorse; converts an object to x-www-form-urlencoded serialization.
* @param {Object} obj
* @return {String}
*/
var param = function (obj) {
@koraysels
koraysels / gist:221a1cbb26ec6b1c4275
Last active August 29, 2015 14:16
get multiple dropbox accounts synced on your mac

create a folder on your hard drive labeled "Dropbox-personal" (or whatever name you want) in your home folder.

then run HOME=$HOME/Dropbox-personal /Applications/Dropbox.app/Contents/MacOS/Dropbox & in your terminal

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh

Fixing npm On Mac OS X for Homebrew Users

If you just want to fix the issue quickly, scroll down to the "solution" section below.

Explanation of the issue

If you're a Mac Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew and then try to do npm update npm -g, you will see an error like this:

$ npm update npm -g
@koraysels
koraysels / get current hostname even if behind ngix or apache (nodejs with express)
Last active August 29, 2015 14:20
When i wanted to het the current hostname of the application in nodejs I always got back ```localhost``` and not the real hostname.. This was because it was behind an Apache webserver :D solution below
var hostname = req.headers['x-forwarded-server'];
if (typeof hostname == "undefined") {
hostname = ( req.headers.host.match(/:/g) ) ? req.headers.host.slice(0, req.headers.host.indexOf(":")) : req.headers.host;
}
@koraysels
koraysels / deploy-ignore.txt
Last active September 30, 2015 07:45
deploy script via ssh & rsync with txt to ignore specific files
web/app/themes/stash/bower
web/app/uploads
.idea
.env
.bowerrc
bower.json
Capfile*
Gemfile*
deploy.sh
deploy-ignore.txt
@koraysels
koraysels / web.config
Created March 7, 2016 13:33
web.config for Wordpress pretty Permalinks
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0"/>
</system.web>
<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimeType="text/css" enabled="true"/>