Skip to content

Instantly share code, notes, and snippets.

View ygabo's full-sized avatar
🎯
Focusing

Yel Gabo ygabo

🎯
Focusing
  • Vancouver Canada
View GitHub Profile
@ygabo
ygabo / prio.cpp
Created August 20, 2013 18:06
Priority queue with a custom class.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <fstream>
#include < ctime >
#include <algorithm>
#include <numeric>
#include <set>
@ygabo
ygabo / zipll.cpp
Created August 20, 2013 17:29
Interweave a linked list into another list.
int main(){
Node a(1), b(2), c(3);
Node d(4), e(5), f(6);
a.next = &c;
//b.next = &c;
d.next = &e; e.next = &f;
Node *temp = &a, *curr;
Node *next = &d;
while(temp){
@ygabo
ygabo / parenthesis.cpp
Last active December 21, 2015 09:18
Generate N proper pairs of parenthesis.
void parn( int index, int max, vector<set<string>> &all){
string *me, *one, *two, *three;
set<string> x;
if (index < 0 || index >= max ) return;
else if (index == 0){
string *d = new string("()");
all[index].insert(*d);
parn(index+1, max, all);
}
else{
@ygabo
ygabo / subsets.cpp
Last active December 21, 2015 08:59
Get all subsets from a given set using recursion. O(2^n) complexity.
void getss(vector<int>& x, int index, vector<vector<int>>& all){
if ( index > x.size() || index < 0 ) return;
if (index == 0 ){
vector<int> empty;
all.push_back(empty);
getss(x,index+1,all);
}
else{
vector<vector<int>> copyall(all);
for( auto i = copyall.begin(); i != copyall.end(); ++i){
@ygabo
ygabo / robot.cpp
Created August 20, 2013 14:02
Robot nxn board. Can only go right or go down. How many paths?
int main() {
rbtree<int> tree;
int n = 10;
vector<int> cur(n), prev(n,1);
vector<vector<int>> board(n, vector<int>(n));
///
//iota(prev.begin(), prev.end(), 0);
cout <<endl;
@ygabo
ygabo / mod.cpp
Last active December 21, 2015 07:18
Sometimes it is necessary to keep a variable with in a certain range. ex. 0 - 255, 0 - 127, etc. I will show you an easy way to do modulo base 2 numbers with bitwise masking.
First off, a little background on what modulus does. Modulus finds the remainder after division of two numbers. So the result of a % b will always be in between 0 and one less than b.
Secondly, you need to know how the bitwise AND, &, works. It will compare the corresponding bits in each term, and only set the bit in the result if both bits in each term are set.
0101
AND 0011
= 0001
import socket
HOST = 'google.com' # The remote host
PORT = 80 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('GET / HTTP/1.1\r\nHost: google.com\r\n\r\n')
data = s.recv(1024)
s.close()
print 'Received', repr(data)
@ygabo
ygabo / BalanceN.cpp
Last active December 21, 2015 05:29
Write an algorithm which is given an integer, 1 <= N <= 1066, produces a list weightPositions. An item in the list weightPositions, is L if the corresponding weight is only in the left pan. It is R if the corresponding weight is only in the right pan, and it is O if the corresponding weight is in neither pan or in both pans. For example, if left…
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <fstream>
using namespace std;
vector<int> x;
struct pan {
@ygabo
ygabo / stringperm.cpp
Created August 12, 2013 09:12
Generate all the permutations of a string.
#include <iostream>
#include <string>
void perm(std::string x, int last){
if( last == 0 ){
std::cout << x << std::endl;
return;
}
for( int i = 0; i <=last; i++){
@ygabo
ygabo / gist:6199683
Created August 10, 2013 09:00
Send email.
def send_email():
import smtplib
gmail_user = "[email protected]"
gmail_pwd = "secret"
FROM = '[email protected]'
TO = ['[email protected]'] #must be a list
SUBJECT = "Testing sending using gmail"
TEXT = "Testing sending mail using gmail servers"