Skip to content

Instantly share code, notes, and snippets.

View sorindragan's full-sized avatar
🔨

Sorin Dragan sorindragan

🔨
  • Utrecht, Netherlands
  • 03:22 (UTC +02:00)
View GitHub Profile
@sorindragan
sorindragan / obj_not_callable.py
Created October 13, 2019 14:52
python interpreter treats 'name' as the variable 'name' that is a string other than the method name() use get_name() instead of name()
class Employee:
def __init__(self, name):
self.name = name
def get_name(self):
print(self.name)
def name(self):
print(self.name)
import pandas as pd
from sklearn.neighbors import KNeighborsRegressor
from sklearn.metrics import mean_squared_error
train = {'author': ['green', 'white'],
'age': [21, 34],
'pages': [100, 200],
}
train = pd.DataFrame(train)
[
{
"message" : "how do you feel today?",
"response" : "i feel like helping you."
},
]
<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
<category>
<pattern>A * IS A *</pattern>
<template>
Of course that <star index = "1"/> is a <star index = "2"/>.
</template>
</category>
</aiml>
@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
@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 / 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 / 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 / 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 / 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) {