Skip to content

Instantly share code, notes, and snippets.

@miguelsaddress
miguelsaddress / PHP Callbacks execution output
Last active August 29, 2015 13:57
How to use a callback in PHP
Miguel at 12:15 in path ~/Desktop
$ php test.php
doing things inside the function
I am a calback
Array
(
[0] => one
[1] => two
[2] => three
)
@miguelsaddress
miguelsaddress / 1. angular-testing-order.js
Last active August 29, 2015 14:01
Angular test execution order.
beforeEach( function(){ console.log("Global before each")} );
describe( "Describe 1", function(){
beforeEach( function(){ console.log("Describe 1 - before each 1")} );
beforeEach( function(){ console.log("Describe 1 - before each 2")} );
//do tests...
it("a test...", function(){
//if there is not a "it()", the beforeEach/afterEach does not execute
});
@miguelsaddress
miguelsaddress / testing-directive-example.js
Created May 23, 2014 14:14
Testing a directive example
var scope, compiledTemplate, UserService, deferred;
//We must load the app module
//and VERY IMPORTANT, the template the directive uses via templateUrl
var TEMPLATE_URL = 'app/account/public/views/signupForm.html'; //proper path to the template
var TEMPLATE_KEY = '/app/account/public/views/signupForm.html'; //as loaded in the directive, used as Key in the tempalteCache
beforeEach( module( 'tybaNg', TEMPLATE_URL ) );
@miguelsaddress
miguelsaddress / how-to-gource.sh
Created October 9, 2015 08:35
Install Gource in Ubuntu (gource.io)
#Install Gource in Ubuntu
========================
#Go to the folder.... and
#see http://tylerfrankenstein.com/code/install-gource-ubuntu-1010-visualize-git-repo
sudo apt-get update
sudo apt-get install libsdl2-dev libsdl2-image-dev libpcre3-dev libfreetype6-dev libglew-dev libglm-dev libboost-filesystem-dev libpng12-dev libsdl1.2-dev libsdl-image1.2-dev libtinyxml-dev
./configure
make
sudo make install
@miguelsaddress
miguelsaddress / Option.php
Created November 11, 2015 16:00 — forked from felipecrv/Option.php
The Maybe Monad [1] in PHP inspired by Scala's implementation of this concept which they call Option [2]. [1] http://en.wikipedia.org/wiki/Monad_%28functional_programming%29#The_Maybe_monad [2] http://www.scala-lang.org/api/current/scala/Option.html
<?php
interface Option/*[T]*/ {
/**
* @return T
*/
public function get();
/**
* @param => T $f
@miguelsaddress
miguelsaddress / springer-free-maths-books.md
Created December 29, 2015 12:04 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of books available for free, here are the direct links
@miguelsaddress
miguelsaddress / octave.md
Created January 6, 2016 20:25 — forked from obstschale/octave.md
An Octave introduction cheat sheet.

Octave CheatSheet

GNU Octave is a high-level interpreted language, primarily intended for numerical computations.
(via GNU Octave)

Basics

  • not equal ~=
  • logical AND &amp;&amp;
@miguelsaddress
miguelsaddress / QHelper.scala
Last active February 15, 2016 08:37
Code formatting for QHelper in Scala
// From: http://alvinalexander.com/scala/scala-class-object-function-convert-multiline-string-to-list-seq
implicit class QHelper( val sc : StringContext) {
def Q(args : Any*): Seq[String] = {
val strings = sc.parts.iterator
val expressions = args.iterator
var buf = new StringBuffer(strings.next)
while(strings.hasNext) {
buf append expressions.next
buf append strings.next
@miguelsaddress
miguelsaddress / ProgressBarExample.scala
Created February 18, 2016 11:22
Progress bar in scala. Simulates a line with progress feedback of an action in the console
import scala.util.Random
object ProgressBar extends App {
// list of times to sleep between each step of the progess, with different probabilities
val timesToSleep = List(500, 500, 500, 500, 600, 600, 600, 1000, 1000, 1000, 2000, 2000, 5000)
print("Progress [ ]")
Thread.sleep(500);
// 11 backspaces to override " ]"
@miguelsaddress
miguelsaddress / memInfo.scala
Last active October 26, 2020 16:13
Fetch info about the memory of you machine with Scala
import scala.language.postfixOps
import scala.util.{Success, Failure}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent._
import scala.util.Try
import sys.process._
import concurrent.Future
import concurrent.Promise