Skip to content

Instantly share code, notes, and snippets.

Avatar

Niels Abildgaard hypesystem

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am hypesystem on github.
  • I am hypesystem (https://keybase.io/hypesystem) on keybase.
  • I have a public key ASAAUdHwkLmLQJRdaklSiNeae5ujL4exU0j6HXhApB6yiQo

To claim this, I am signing this object:

@hypesystem
hypesystem / about.md
Last active Aug 29, 2015
module.parent refers to the first requirer only!
View about.md

Module.parent is useless

module.parent in a node app refers to the parent module of the current module. This is useful for getting paths (for example) relative to the parent, for example used internally in fileGetter:

// Should get localPath in ./, not localPath in ./lib/some-folder
var fileGetter = require("./lib/some-folder/file-getter.js");
var text = fileGetter("./localPath.dat");
@hypesystem
hypesystem / design.json
Created Jun 19, 2015
CouchDB (Hardcoded) Multi-dimensional Query (by using List)
View design.json
{
_id: "_design/user_actions",
_rev: "some-revision",
views: {
what_ever: {
map: function(doc) {
// ...
}
}
},
@hypesystem
hypesystem / main.js
Last active Aug 29, 2015
Insignificant Order Deep-Equals for Arrays and Objects in Javascript
View main.js
function insignificantOrderDeepContains(haystack, needle) {
var matched = false;
haystack.forEach(function(straw) {
if(matched) return;
if(insignificantOrderDeepEquals(straw, needle)) {
matched = true;
}
});
return matched;
}
@hypesystem
hypesystem / api.php
Created Mar 9, 2015
Static, dynamic and browser-rendered pages
View api.php
<?php
header("Content-Type: application/json");
echo json_encode(array(
"name" => "Wilson",
"gender" => "Ball",
"age" => "13"
));
?>
@hypesystem
hypesystem / private-scoping.js
Last active Aug 29, 2015
Private scope in node.js / dirty, dirty trick to get private methods
View private-scoping.js
var PublicClass = function() {
this.state = "something";
}
PublicClass.prototype.publicMethod = function() {
privateFunction.call(this); //<-- this is a dirty, dirty trick, running *privateFunction* as a private method
};
function privateFunction() {
console.log(this.state); //<-- in order to make *this* accessible, we need to use the trick above
View test_induced_design_damage.rb
# Original Rails controller and action
class EmployeesController < ApplicationController
def create
@employee = Employee.new(employee_params)
if @employee.save
redirect_to @employee, notice: "Employee #{@employee.name} created"
else
render :new
end
View Range.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// Generic implementation of Martin Fowler's Enterprise Pattern ``Range'':
/// http://martinfowler.com/eaaDev/Range.html
///
@hypesystem
hypesystem / JobApplicant.cs
Last active Aug 29, 2015
3 Job Description - refactored
View JobApplicant.cs
using System.Collections.Generic;
using System.Linq;
///<summary>
///Original: http://3dk.easycruit.com/vacancy/1161591/3032?iso=dk
///Their own repost: https://3dk.easycruit.com/vacancy/1385970/3032?iso=dk
///</summary>
namespace JobAd
{