Skip to content

Instantly share code, notes, and snippets.

@riyadparvez
riyadparvez / clear_terminal.c
Created May 23, 2014 02:12
Clearing the terminal
//clear the whole terminal screen
printf("\033[2J\033[1;1H");
//only clear the portion for current portion of its
fputs("\033[A\033[2K\033[A\033[2K",stdout);
rewind(stdout);
ftruncate(1,0);

Pregel

Why Graph Computation Is Different

  • Poor locality of memory access
  • Very little work per vertex
  • Changing degree of parallelism over the course of execution

MapReduce

@riyadparvez
riyadparvez / Microreboot.md
Created June 23, 2014 23:52
Microreboot notes

Microreboot

Microreboots

  • restart fine-grained components “with a clean slate”
  • only take a fraction of the time needed for full system reboot
  • Separate data recovery and application recovery

Goals of confining the reboot

@riyadparvez
riyadparvez / build-llvm.sh
Last active August 29, 2015 14:15
Download and build latest llvm, clang and compiler tools.
#!/bin/bash
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm-latest
cd llvm-latest/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd clang/tools
svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
cd ../../../.. #go back to top directory
cd llvm-latest/projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
@riyadparvez
riyadparvez / addr2line-whole-exec.py
Created February 24, 2015 15:57
Run addr2line on all instructions in the binary. You need pybfd package.
#!/usr/bin/env python
# Import the disassembly library (libopcodes)
from pybfd.opcodes import Opcodes, OpcodesException
from pybfd.bfd import Bfd, BfdException
from sys import argv, exit
from subprocess import Popen, PIPE
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/APSInt.h"
#include "clang/Driver/Options.h"
#include "clang/AST/AST.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/Expr.h"
#include "clang/AST/OperationKinds.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/ASTConsumers.h"
@riyadparvez
riyadparvez / FocusablePanel.cs
Last active December 10, 2015 10:08
This panel class gets focus. On the other hand default panel control tries to get away from focus. This code is taken from Hans Passant from stackoverlfow
//This panel will get focus as the original .NET panel always tries to get away from focus
public class FocusablePanel : Panel
{
public FocusablePanel()
{
this.SetStyle(ControlStyles.Selectable, true);
this.TabStop = true;
}
@riyadparvez
riyadparvez / UnscrollableComboBox.cs
Created December 31, 2012 12:59
ComboBox class which doesn't catch mouse wheel event rather it passes to other controls
//Combobox will handle mouse wheel event, but if you want to combobox which won't handle mouse wheel
//event, rather pass to the parent, use this class
public class UnscrollableComboBox : ComboBox
{
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x20a && this.Parent != null)
{
PostMessage(this.Parent.Handle, m.Msg, m.WParam, m.LParam);
}
@riyadparvez
riyadparvez / Navigation Key Handler.cs
Created December 31, 2012 13:01
Add this code snippet to your class to handle navigational key press
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Up)
{
}
else if (keyData == Keys.Down)
{
}
@riyadparvez
riyadparvez / Connected Component Labeling.cs
Created January 2, 2013 12:03
Implementation of ConnectedComponentLabeling algorithm. It uses rooted tree data structure for members of a label. It's of O(n^2). I've used this algorithm for line detection in images (which are already converted to binary images using threshold, eliminating noise)
using System.Collections.Generic;
using System.Drawing;
namespace PatternRecognition
{
public class ConnectedComponentLabeling
{
readonly int[,] board;
readonly int w;
readonly int h;