Skip to content

Instantly share code, notes, and snippets.

View Se7soz's full-sized avatar

Hussein Elsayed Se7soz

View GitHub Profile
@Se7soz
Se7soz / codeforces427C.cpp
Last active October 19, 2015 09:21
Codeforces 427 C
#ifndef __MYLIB_H
#define __MYLIB_H
#include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<climits>
@Se7soz
Se7soz / Model.proto
Created September 21, 2015 18:14
Protocol buffer example
syntax = "proto2";
package model;
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
}
@Se7soz
Se7soz / ProtocolBufferSample.java
Last active September 21, 2015 18:43
Protocol buffer example
package sample;
import model.Model.*;
import java.io.*;
public class ProtocolBufferSample {
private static String DATA_SOURCE;
@Se7soz
Se7soz / pom.xml
Last active September 21, 2015 18:34
Protocol Buffer Example
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>protocol.buffer</groupId>
<artifactId>sample</artifactId>
<version>1.0-SNAPSHOT</version>
@Se7soz
Se7soz / Student.java
Last active August 29, 2015 14:16
Lombok example
import lombok.Data;
public @Data class Student {
String name;
String address;
int age;
double gpa;
}
// javac -cp lombok.jar Student.java -> That's not too much right? ;)
public class Student {
String name;
String address;
int age;
double gpa;
public String getName() {
return name;
}
@Se7soz
Se7soz / queries.cpp
Created January 19, 2015 12:07
Can you answer these queries I
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring>
#include <map>
#include <climits>
#include <set>
class MaxTriangle {
public:
double calculateArea(int a, int b) {
vector<pair<int, int> > va = getVectors(a);
vector<pair<int, int> > vb = getVectors(b);
double ret = -2;
for(int i = 0; i < sz(va); i++) {
for(int j = 0; j < sz(vb); j++) {
@Se7soz
Se7soz / getVectors
Created April 9, 2014 13:22
Function to get all valid vectors given a magnitude value
vector<pair<int, int> > getVectors(int x) {
vector<pair<int, int> > ret;
for(int i = 0; i*i <= x; i++) {
int y = sqrt(x-i*i);
if(i*i+y*y == x) {
ret.push_back(make_pair(i, y));
ret.push_back(make_pair(-i, y));
@Se7soz
Se7soz / prob170.cpp
Last active August 29, 2015 13:56
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
#define LINE_WIDTH_TOO_SMALL -1
vector<string> split(string text) {
vector<string> ret;
int cur = 0;
for(int i = 0; i < text.size(); i++) {
if(text[i] == ' ' || text[i] == '\n') {
ret.push_back(text.substr(cur, i-cur));
cur = i+1;