Skip to content

Instantly share code, notes, and snippets.

@ageekymonk
ageekymonk / hello.s
Created August 7, 2011 07:33
x86 Assembly
.section .data
hello:
.ascii "Diving into Great Assembly World"
hello_end:
.set HELLO_SIZE, hello_end-hello
.section .text
.global _start
@ageekymonk
ageekymonk / emacs.el
Created January 23, 2012 01:35
Emacs snippet for compiling code in c and cpp
;; Compilation for gcc / g++
(defun ramz/code-compile ()
(interactive)
(unless (file-exists-p "Makefile")
(set (make-local-variable 'compile-command)
(let ((file (file-name-nondirectory buffer-file-name)))
(format "%s -o %s %s"
(if (equal (file-name-extension file) "cpp") "g++" "gcc" )
(file-name-sans-extension file)
file)))
@ageekymonk
ageekymonk / an_bug.S
Created January 24, 2012 02:37 — forked from ice799/an_bug.S
an bug
# can you spot the bug?
#
# if so, boundary is hiring: jobs@boundary.com
#
c03bc00c <atomic64_add_return_cx8>:
c03bc00c: 55 push %ebp
c03bc00d: 53 push %ebx
c03bc00e: 56 push %esi
c03bc00f: 57 push %edi
@ageekymonk
ageekymonk / endian.h
Created February 3, 2012 02:10
Optimized Inline Function for ntohl and htonl
// Using the X86 instruction bswap and gcc inline assembly
inline unsigned int ntohl(unsigned int x)
{
asm("bswapl %1" : "=a" (x) : "a"(x));
}
inline unsigned int htonl(unsigned int x)
{
@ageekymonk
ageekymonk / eightqueen.cpp
Created February 6, 2012 15:48
Solution For Eight Queen Problem
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
void printChess(vector<vector<int> > &board)
{
static int i = 1;
@ageekymonk
ageekymonk / ncents.cpp
Created February 6, 2012 17:30
Minimum Number of coin with given denom for a given amount
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int denom[] = { 1, 5, 10, 25 };
int ncents(int val, vector<unsigned int> &numCoins)
@ageekymonk
ageekymonk / highlight.el
Created February 8, 2012 06:42
Highlight the current word in buffer. Similar to F8 highlight in Source Insight.
;; Shift F8 will highlight all the words that match underlying word in the buffer
(defun is-word-highlighted ()
(interactive)
(let ((face (or (get-char-property (point) 'read-face-name)
(get-char-property (point) 'face))))
(if (facep face) (if (face-equal face "hi-yellow") t nil) nil)))
(defun toggle-highlight-word ()
(interactive)
(setq sym (concat "\\<" (current-word) "\\>"))
@ageekymonk
ageekymonk / cedet_config.emacs
Created February 10, 2012 09:13
Emacs file for cedet + ecb
;;============EDIT THESE LINES with your path==========
(add-to-list 'load-path "<path_to_cedet-1.0.1>")
(load-file "<path_to_cedet-1.0.1>/common/cedet.el")
(add-to-list 'load-path "<path_to_ecb_folder>")
(require 'ecb)
(semantic-load-enable-excessive-code-helpers)
(require 'semantic-ia)
@ageekymonk
ageekymonk / reverese_word.rb
Created February 19, 2012 03:21
Ruby snippets
def reverse_word str
str.reverse.split(" ").map { |n| n.reverse }.join(" ")
end
reverse_word "This is really awesome"
@ageekymonk
ageekymonk / scrapeBooks.rb
Created February 26, 2013 06:34
Download Books and Authors list from goodread.com site
require 'rubygems'
require 'mechanize'
require 'nokogiri'
@filename = "bookslist.txt"
@book_list = {}
@a = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'