Skip to content

Instantly share code, notes, and snippets.

File.readlines('input.txt').map(&:strip).chunk{|x| x != ''}.select{|x|x.first}.map{|x|x.last.join(' ').scan(/([^:]+):(\S+)\s?/).to_h}
@soedar
soedar / gist:00b238ed633f1aa76187
Created January 24, 2016 02:09
kvm passthrough
#!/bin/bash
configfile=/etc/vfio-pci.cfg
vmname="windows10vm"
vfiobind() {
dev="$1"
vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
device=$(cat /sys/bus/pci/devices/$dev/device)
if [ -e /sys/bus/pci/devices/$dev/driver ]; then
@soedar
soedar / .cvimrc
Last active October 10, 2015 16:41
cvimrc
map b :buffer<space>
map B :bookmarks<space>
let barposition = "bottom"

Docker Installation

Mac OS X

Make sure you have Homebrew and Virtualbox installed on your machine

# Install docker
brew update
brew install docker boot2docker docker-compose
class Test(object):
def __init__(self):
self.x = "hello"
t = Test()
t.something = "something"
print(t.something)
@soedar
soedar / gist:69b0fe4596960216a721
Last active August 29, 2015 14:06
Notes on Data Abstraction

The key idea behind data abstraction is that we want a way for us to reason about data at a higher level (as oppose to data at a primitive level). We would need to discuss first what are primitive types, and why there is a need to express these primitive types at a higher level for our convenience.

Primitive Types

Primitive types are languages features that are provided by the programming environment. You should be familiar with some of the primitive types: integers, floats, boolean, tuples, functions, etc.

For each primitive types, the language also provide us with a way to interact with the primitive types. For example, the + operator allows us to add between numbers, and the len function allows us to get the size a tuple.

User Defined Types

As the name clearly imply, user defined types are defined by the users, ie us. They are not provided by the language, but they allow a way for us to more easily reason about our program and their behavior. Like primitive types, we can also define ways we

@soedar
soedar / gist:54cd3e6192aff3bf50a9
Last active August 29, 2015 14:06
Notes on Higher Order Function

Higher Order Function is the idea that functions can be used as the input parameters to other functions, as well as functions can be returned from the function. It is a little harder to understand the latter, so we'll spend some more time talking about it.

The reason why we can do HOF is because our function can be stored in our variables.

Background: Creating Functions

A good way to think about functions is that they are just like any other variables types (like int, boolean, tuple). Just like how we can create new tuple by using the tuple notation ( my_tuple = (1, 2, 3)), we can also create a new function using the create function notation.

There are 2 main ways to create function, and in the following example, a variable named square is created, that 'holds' the function that is created.

def find_rate(principal, gap, monthly, years):
# principal - starting principal
# gap - number of months before 1st payment
# monthly - monthly payment
# years - number of years of payment
def remainder(interest): # monthly interest
left = principal
#compute total before starting payment
#import "hello.h"
// Anonymous class extension
@interface Hello ()
@property (nonatomic, strong) NSString *privateString;
@end
@implementation Hello
// do something with self.privateString
is_word = lambda word: word in ['hot', 'el', 'fate', 'elf', 'ate', 'hotel', 'fate']
def str_set(input_str):
if input_str == "":
return [[]]
result = []
for i in range(1, len(input_str)+1):
s = input_str[:i]