Skip to content

Instantly share code, notes, and snippets.

@shaikhul
shaikhul / oh-shit-c.md
Last active September 6, 2019 04:54
Oh shit C!

Oh shit C!

Some C examples for quick reference.

Strings

// remember the null terminator!
char greet[] = {'H', 'e', 'l', 'l', 'o', '\0'};

int len = sizeof(greet) / sizeof(char);
for (i = 0; i < len; i++) {
@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)
@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 / 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 / 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
<?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");
<?php
class HTMLRenderer implements RendererInterface {
public function render($data) {
return "<p>{$data}</p>";
}
}
<?php
class PlainTextRenderer implements RendererInterface {
public function render($data) {
return $data;
}
}
<?php
/**
* RendererInterface
*/
interface RendererInterface {
public function render();
}
@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;