Skip to content

Instantly share code, notes, and snippets.

import cv2
import numpy as np
from sklearn.cross_decomposition import PLSRegression
from sklearn.linear_model import LinearRegression
from sklearn.decomposition import PCA
import scipy.sparse as sp
import sys
reference_colors = [[115, 82, 68], [194, 150, 130], [98, 122, 157], [87, 108, 67], [133, 128, 177], [103, 189, 170], [214, 126, 44], [80, 91, 166], [193, 90, 99], [94, 60, 108], [157, 188, 64], [
224, 163, 46], [56, 61, 150], [70, 148, 73], [175, 54, 60], [231, 199, 31], [187, 86, 149], [8, 133, 161], [243, 243, 242], [200, 200, 200], [160, 160, 160], [121, 122, 121], [85, 85, 85], [52, 52, 52]]
#include <iostream>
#include <typeinfo>
#include <stdexcept>
using namespace std;
class A {
public:
virtual void print() { cout << "A" << endl; }
};
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#include <string.h>
using namespace std;
int f(int argc, char* argv[]) {
for(int i=0;i<argc;++i) cout << argv[i] << endl;
return 0;
# regularize filenames
for f in `ls *.png`; do
echo $f
filename=`echo "$f" | cut -d'.' -f1`
echo $filename
mv $f $filename.png
done
import java.util.Random;
import java.util.concurrent.*;
import java.util.Vector;
public class Main {
static class TimeConsumingTask implements Runnable {
public Vector<Integer> results = new Vector<>();
@Override
public void run() {
@phg1024
phg1024 / memtracker.cpp
Created November 16, 2016 19:40
Memory tracker with overloaded new/delete.
#include <iostream>
#include <memory>
#include <cstdlib>
#include <unordered_map>
#include <stdexcept>
using namespace std;
template <int MAX_TABLE_SIZE=1024>
class MemTracker {
pair<void*, bool> mem_tbl[MAX_TABLE_SIZE];
all_plates = 'ABC'
state = {
'A': [],
'B': [],
'C': []
}
def print_state():
print 'A:', state['A'], 'B:', state['B'], 'C:', state['C']
#include <math.h> // smallpt, a Path Tracer by Kevin Beason, 2008
#include <stdlib.h> // Make : g++ -O3 -fopenmp smallpt.cpp -o smallpt
#include <stdio.h> // Remove "-fopenmp" for g++ version < 4.2
struct Vec { // Usage: time ./smallpt 5000 && xv image.ppm
double x, y, z; // position, also color (r,g,b)
Vec(double x_=0, double y_=0, double z_=0){ x=x_; y=y_; z=z_; }
Vec operator+(const Vec &b) const { return Vec(x+b.x,y+b.y,z+b.z); }
Vec operator-(const Vec &b) const { return Vec(x-b.x,y-b.y,z-b.z); }
Vec operator*(double b) const { return Vec(x*b,y*b,z*b); }
Vec mult(const Vec &b) const { return Vec(x*b.x,y*b.y,z*b.z); }
(define (change c) '(Change c))
(define (insert c) '(Insert c))
(define copy '(Copy))
(define delete '(Delete))
(define kill '(Kill))
(define (cost x)
(length (filter (lambda (z) (not (eq? (car z) 'Copy))) x)))
(define (best edits)
#include <iostream>
#include <queue>
#include <vector>
#include <climits>
#include <unordered_map>
using namespace std;
template <typename Key, typename Value, typename Comp=std::greater<Value>>
class priorty_queue {
public: