Skip to content

Instantly share code, notes, and snippets.

View plates.py
def plates(stack, i, num_used, N, P, K):
# Brute force: O(K^N)
if i >= N:
return -1
current_total = -1
for n in range(K + 1):
if num_used + n > P:
break
elif num_used + n == P:
current_total = max(current_total, sum(stack[i][:n]))
@satojkovic
satojkovic / cudnn_version.cpp
Created Oct 18, 2017
print installed cudnn version
View cudnn_version.cpp
#include <cudnn.h>
#include <iostream>
int main(int argc, char** argv) {
std::cout << "CUDNN_VERSION: " << CUDNN_VERSION << std::endl;
return 0;
}
View http_ex.go
package main
import (
"fmt"
"net/http"
)
type String string
type Struct struct {
View test.py
# http://stackoverflow.com/questions/24685436/efficient-way-to-cluster-colors-using-k-nearest
import numpy as np
import cv2
def nearest(i, j, src, knn, colors):
sample = np.reshape(src, (-1, 3)).astype(np.float32)
retval, result, neighbors, dist = knn.find_nearest(sample, 1)
return colors[result[0, 0]]
@satojkovic
satojkovic / dfs.cpp
Created Jul 7, 2014
depth first search
View dfs.cpp
#include <cstdio>
#include <string>
int n = 4;
int k = 15;
int a[] = {1, 2, 4, 7};
bool dfs(int i, int sum)
{
printf("i == %d, sum == %d\n", i, sum);
View cv_view.py
#-*- coding: utf-8 -*-
import cv2
from collections import defaultdict
class ImageFlip(object):
def __init__(self):
self._observers = []
View gh_2fa_sample.py
#-*- coding: utf-8 -*-
from pit import Pit
import requests
import getpass
import json
HTTPUnauthorized = 401
HTTPCreated = 201
View openglcv.cpp
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <glut.h>
static void display(void)
{
cv::Mat img = cv::imread("test.jpg");
cv::flip(img, img, 0);
cv::cvtColor(img, img, CV_BGR2RGB);
View hist_bar.py
import matplotlib.pyplot as plt
import numpy as np
from collections import Counter
# hist
m = np.asarray([2058, 2059, 2058, 2100, 2100, 2102, 2101, 2058, 2059, 2100])
print sorted(Counter(m).items())
plt.subplot(211)