Skip to content

Instantly share code, notes, and snippets.

@OscarGalindo
OscarGalindo / index.html
Created April 15, 2015 11:19
Tree view in angularjs
<!doctype html>
<html ng-app="ctz">
<head>
<title>CategoryTree</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script>
angular.module('treeApp', []);
angular.module('treeApp').controller('treeCtrl', treeCtrl);
treeCtrl.$inject = ['$scope', '$http'];
@OscarGalindo
OscarGalindo / arraydiff.py
Created May 15, 2015 13:00
Array.diff @ Codewars
array_diff = lambda y,x: [i for i in y if i not in x]
@OscarGalindo
OscarGalindo / vhost
Created May 27, 2015 07:49
Dynamic vhost to nginx
server {
index index.html index.htm index.php;
set $basepath "/var/www";
set $domain $host;
if ($domain ~ "^(.[^.]*)\.dev$") {
set $domain $1;
set $rootpath "${domain}";
set $servername "${domain}.dev";
}
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@OscarGalindo
OscarGalindo / Terminator.md
Created July 25, 2015 20:23
Shortcuts for terminator

Terminator Shortcuts

  • Ctrl - Shift - E - Split vertically
  • Ctrl - Shift - O - Split horizontally
  • Ctrl - Shift - P - Focus next view
  • Ctrl - Shift - N - Focus previous view
  • Ctrl - Shift - W - Close focused view
  • Ctrl - Shift - Q - Exit terminator
  • Ctrl - Shift - X - Enlarge active view
@OscarGalindo
OscarGalindo / FileUpload.php
Created January 27, 2016 15:24
Unit testing is_uploaded_file and move_uploaded_file
<?php
class FileUpload
{
private $from;
private $destination;
public function __construct($file, $id, $destination = '/tmp', $validExtensions = array())
{
if (!is_array($file) || empty($file['tmp_name']) || !$file['tmp_name']) {
@OscarGalindo
OscarGalindo / ultimate-ut-cheat-sheet.md
Created February 10, 2016 21:24 — forked from yoavniran/ultimate-ut-cheat-sheet.md
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai and Sinon

The Ultimate Unit Testing Cheat-sheet

For Mocha, Chai and Sinon

using mocha/chai/sinon for node.js unit-tests? check out my utility: mocha-stirrer to easily reuse test components and mock require dependencies


@OscarGalindo
OscarGalindo / nextTick.js
Created February 21, 2016 21:14 — forked from mmalecki/nextTick.js
process.nextTick vs setTimeout(fn, 0)
for (var i = 0; i < 1024 * 1024; i++) {
process.nextTick(function () { Math.sqrt(i) } )
}
@OscarGalindo
OscarGalindo / better-nodejs-require-paths.md
Created April 30, 2016 10:55 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

I don't love the single responsibility principle

Did you ever happen to disagree with a colleague on the single responsibility principle and its application? Let's try to understand why that could be the case.

I once worked with a colleague, whom we shall call Stan, who had a very different understanding of the single responsibility principle than I had. During code reviews, his feedback would often be that my classes "tried to do too much" and broke the single responsibility principle. My feedback to his patches was often the opposite, that his classed did too little and lacked cohesion.

How can we explain this disagreement? Let's assume that we both know the SRP and try to apply it at the best of our abilities: I can only see two alternatives.

The first possibility is that the classes are actually the wrong size. People are wrong all the time: maybe I was wrong and he was right or vice versa. While this sometimes happens, I would expect any reasonably competent developer who is aware of the SRP to onl