Skip to content

Instantly share code, notes, and snippets.

View cristipufu's full-sized avatar

Cristi Pufu cristipufu

View GitHub Profile
@cristipufu
cristipufu / elasticsearch.yml
Created September 23, 2016 12:28
Base configuration for a write heavy cluster
##################################################################
# /etc/elasticsearch/elasticsearch.yml
#
# Base configuration for a write heavy cluster
#
# Cluster / Node Basics
cluster.name: logng
# Node can have abritrary attributes we can use for routing
@cristipufu
cristipufu / dining_philosophers.py
Last active February 28, 2017 23:59
dining_philosophers.py
import sys
import random
import time
from threading import *
class Philosopher(Thread):
def __init__(self, waiter, lfork, rfork):
Thread.__init__(self)
self.waiter = waiter
self.lfork = lfork
@cristipufu
cristipufu / producer_consumer.py
Created March 1, 2017 00:35
Producer-consumer problem in python
import sys
import random
import time
from threading import *
class Producer(Thread):
def __init__(self, items, can_produce, can_consume):
Thread.__init__(self)
self.items = items
self.can_produce = can_produce
@cristipufu
cristipufu / hashtable.c
Created March 2, 2017 17:50
Hashtable implementation
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
#include "hash.h"
#include "hashtable.h"
#define DEBUG 0
hashtable *create_hashtable(int length)
@cristipufu
cristipufu / lib.h
Last active March 3, 2017 10:10
Simple stop wait transfer protocol
#ifndef LIB
#define LIB
typedef struct {
int type;
int len;
char payload[1400];
} msg;
void init(char* remote,int remote_port);
@cristipufu
cristipufu / matrix_basic_optimization.c
Last active March 22, 2017 12:07
Matrix multiply optimizations
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
double **new_matrix(int n)
{
double **m;
double *buf;
buf = (double *) calloc(n * n, sizeof(double));
int i;
@cristipufu
cristipufu / AddressController.cs
Created January 4, 2018 17:46
OData AutoMapper translate DTO queries to POCO queries
[HttpGet]
public async Task<IEnumerable<AddressModel>> GetAddresses(ODataQueryOptions<AddressModel> queryOptions, CancellationToken cancellationToken)
{
var repository = new AddressRepository(_context);
var service = new AddressService(repository);
var filter = queryOptions.ToModelQueryFilter<AddressModel>();
return await service.QueryByStreetAsync("StreetName", filter, cancellationToken);
}
extern alias redis;
using Castle.Core.Logging;
using redis::StackExchange.Redis;
using System;
using System.Net;
using UiPath.Core;
namespace UiPath.Web.Communication
{
public static class RedisConnector
@cristipufu
cristipufu / EFCoreDatabaseExtensions.cs
Last active April 8, 2018 15:54
SqlQuery<T> EFCore
public static class DatabaseExtensions
{
public static SqlQuery<T> SqlQuery<T>(this DatabaseFacade database, string sqlQuery, object parameters = null)
where T : class
{
return new SqlQuery<T>
{
Database = database,
Query = sqlQuery,
Parameters = GetParameters(parameters)
/* TRUNCATE ALL TABLES IN A DATABASE */
DECLARE @dropAndCreateConstraintsTable TABLE
(
DropStmt VARCHAR(MAX)
,CreateStmt VARCHAR(MAX)
)
/* Gather information to drop and then recreate the current foreign key constraints */
INSERT @dropAndCreateConstraintsTable
SELECT DropStmt = 'ALTER TABLE [' + ForeignKeys.ForeignTableSchema
+ '].[' + ForeignKeys.ForeignTableName + '] DROP CONSTRAINT ['