Skip to content

Instantly share code, notes, and snippets.

View sorindragan's full-sized avatar
🔨

Sorin Dragan sorindragan

🔨
  • Utrecht, Netherlands
  • 05:19 (UTC +02:00)
View GitHub Profile
@sorindragan
sorindragan / topologicalSort.java
Created May 12, 2017 22:02
Topological Sort in Java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Stack;
import java.util.StringTokenizer;
class GeneratedGraph {
public boolean error = false; // eroare graf ciclic
public int n; // numar de noduri
@sorindragan
sorindragan / 3d_matrix.c
Created November 5, 2017 18:25
3D matrix in C with memory allocation
int main() {
grid = (int***)malloc(num_players * sizeof(int**));
for (int i = 0; i < num_players; i++) {
grid[i] = (int**)calloc(num_lines, sizeof(int*));
for (int j = 0; j < num_lines; j++) {
grid[i][j] = (int*)calloc(num_cols, sizeof(int));
}
}
}
@sorindragan
sorindragan / index.js
Last active July 17, 2024 20:41
Simplest node.js http server (http://localhost:3000)
const http = require('http')
const port = 3000
const requestHandler = (request, response) => {
console.log(request.url)
response.end("Running")
}
const server = http.createServer(requestHandler)
@sorindragan
sorindragan / linux-cmd.sh
Last active October 9, 2019 19:19
Linux commands that I saved over years.
Ctrl+Alt+F1 to open virtual console.
Ctrl+Alt+F7 to return to desktop.
uname -a = printeaza informatii despre sistem
inxi -Fxz = informatii despre drivere sistem
dmidecode = informatii RAM
grep MHz /proc/cpuinf = frecventa procesoare
@sorindragan
sorindragan / isBinaryTree.java
Created March 19, 2018 16:16
A function that checks if a given tree is a BST.
boolean checkBST(Node root) {
return checkHelper(root, Integer.MIN_VALUE, Integer.MAX_VALUE);
}
boolean checkHelper(Node node, int min_left, int max_right) {
if (node == null) {
return true;
}
if (node.data <= min_left || node.data >= max_right) {
@sorindragan
sorindragan / recMethod.java
Last active December 6, 2018 16:32
In a recursive method print something only once.
public class recursiveMethod {
// print something only once in a recursive method
public static int y = 0;
public static boolean recursiveMethod(int x) {
if (x > 4) {
return true;
}
Exception e = new Exception();
e.fillInStackTrace();
if (e.getStackTrace().length == 2) {
@sorindragan
sorindragan / sumlist.hs
Created March 20, 2018 18:41
Sum up all the elements from a list.
suml [] = 0
suml (x:xs) = x + suml xs
@sorindragan
sorindragan / insertionSort.hs
Created March 20, 2018 18:42
InsertionSort algorithm in Haskell
sort [] = []
sort [x] = [x]
sort (x:xs) = insert (sort xs)
where insert [] = [x]
insert (y:ys) | x <= y = x : y : ys
| otherwise = y : insert ys
@sorindragan
sorindragan / shift_overflow.c
Last active March 22, 2018 22:03
A small test for understanding bytes shifting and when you get an overflow.
#include<stdio.h>
#include<limits.h>
int main(void) {
unsigned int x = 1;
int x2 = 1;
printf("unsigned: %u\n", x << 31);
printf("signed:(-1) %d\n", (x2 << 31) - 1);
printf("signed: %d\n", x2 << 31);
@sorindragan
sorindragan / feature_computer.py
Created December 6, 2018 17:10
feature_computer: Function that computes features before training a model using sklearn pipeline. train_model: Function that tains a sklearn model and writes it in a pickle. train_utils: Helper function
import numpy as np
from scipy.sparse import csr_matrix
from sklearn.base import BaseEstimator, TransformerMixin
class FeatureComputer(BaseEstimator, TransformerMixin):
def __init__(self, train_data):
self.data = train_data