Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Use spy when we want to be sure that the authorize method was called
* Warning: the more we spy, the tighter we couple our tests to the implementation of our system which leads to fragile tests
*/
class AcceptingAuthorizerSpy extends Authorizer {
$authorize_was_called = false;
public function authorize() {
@shaikhul
shaikhul / Book.php
Last active January 21, 2017 07:26
<?php
/**
* Book Plain Old PHP class
*/
class Book {
private $title;
private $author;
private $current_page;
<?php
/**
* RendererInterface
*/
interface RendererInterface {
public function render();
}
<?php
class PlainTextRenderer implements RendererInterface {
public function render($data) {
return $data;
}
}
<?php
class HTMLRenderer implements RendererInterface {
public function render($data) {
return "<p>{$data}</p>";
}
}
<?php
/**
* Single Responsiblity Principle client code
*/
// create a book instance, book has no knowledge about rendering
$book = new Book();
$book->setTitle("Some Title");
$book->setAuthor("Some Author");
@shaikhul
shaikhul / tmux_cheatsheet.md
Last active January 26, 2017 17:45
My cheatsheet

Start new session

tmux new -s session_name

Prefix Key - Ctrl+b

Panes (split window)

  • vertical: Ctrl+b %
  • horizontal: Ctrl+b "
  • kill pane: Ctrl+b x
@shaikhul
shaikhul / strace.md
Last active September 5, 2022 02:46
Strace cheat sheet

Strace cheat sheet

  • trace an executable: strace ls
  • trace specific system call: strace -e open ls
  • trace multiple system call: strace -e trace=open,read,write ls
  • save trace output: strace -o ls.txt ls
  • trace a running linux process: sudo strace -p pid
  • print timestamp: strace -t ls
  • gerate stat: strace -c ls
@shaikhul
shaikhul / this.java
Created January 17, 2018 03:43
Java Context/this in action
/**
Run it at https://repl.it/repls/PunyDisguisedDalmatian
*/
class Foo {
public void helloFoo() {
System.out.println("Hello Foo");
}
public Foo getContext() {
return this;
@shaikhul
shaikhul / python_dunder_example.py
Created February 17, 2019 06:06
Python data model example
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return 'Stringified Point: ({x}, {y})'.format(x=self.x, y=self.y)
def __repr__(self):
return 'Representing Point: ({x}, {y})'.format(x=self.x, y=self.y)