Skip to content

Instantly share code, notes, and snippets.

@shinaisan
shinaisan / dot_product.py
Created November 6, 2014 02:27
Python dot product sample.
def dot_product(p, q, o = None):
"""
Calculate a dot product of two vectors(tuples) p and q.
If the vector o is given, use it as an origin.
>>> dot_product((), ())
0
>>> dot_product((2,), (3,))
6
>>> dot_product((3,), (4,), (1,))
6
@shinaisan
shinaisan / zip_reduce.py
Created November 6, 2014 01:42
Python zip and reduce sample.
def in_delta(p, q, delta):
"""
Returns True if p and q are of the same length and
the elements at the same index of each are
approximately equal within the error delta.
>>> in_delta([], [], 0)
True
>>> in_delta([1], [1], 1.0e-10)
True
>>> in_delta([1], [1.01], 1.0e-10)
@shinaisan
shinaisan / kp.cpp
Created July 5, 2015 13:08
0-1 Knapsack Problem Random Sample Generation
// 0-1 Knapsack Problem Random Sample Generation.
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
#include <ctime>
#include <cstdlib>
@shinaisan
shinaisan / knapsack.cpp
Last active August 29, 2015 14:24
0-1 Knapsack Problem with Dynamic Programming and Backtracking
#include <iostream>
#include <iterator>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
@shinaisan
shinaisan / README.md
Last active August 29, 2015 14:26
Some Practice Examples of Range Minimum Query (RMQ)
@shinaisan
shinaisan / rmq.hpp
Created August 1, 2015 00:01
Range Minimum Query (RMQ) Implementation
#include <vector>
using namespace std;
template <typename T>
struct rmq_tree {
int n;
T inf;
vector<T> v;
@shinaisan
shinaisan / git-submodule-test.sh
Created August 2, 2015 02:49
Trying out git-submodule
#!/bin/bash
echo 'This script will create a temporary directory in ~/tmp.'
exit 1 # Remove this line to run this script.
set -x
DIR=`mktemp -d -p ~/tmp/`
mkdir -p $DIR/bare
@shinaisan
shinaisan / read_until_sample.rb
Created August 5, 2015 04:38
Example of read_until parameter of BinData::Array
require 'bindata'
require 'pp'
class VarString < BinData::Record
uint8 :size_bytes # Length of data (in bytes).
string :data, length: :size_bytes
end
class Child < BinData::Record
# See bindata/lazy.rb: when evaluating lambdas,
@shinaisan
shinaisan / main.c
Created April 7, 2012 04:09
Win32 sample program of bitmap waving effect
// To compile (using VC):
// cl main.c /link gdi32.lib user32.lib kernel32.lib
#include <tchar.h>
#include <math.h>
#include <windows.h>
TCHAR *szWindowClass =_T("Window Class Name");
#define PI 3.14159265
@shinaisan
shinaisan / index.html
Created April 15, 2012 06:06
Processing.js sample: dragging a circle(ellipse) using mousePressed/mouseReleased.
<html>
<head>
<title>My first processing.js sample</title>
<script type="text/javascript" src="processing.js"></script>
</head>
<body>
<h1>Sample: Dragging the ball</h1>
<script type="application/processing" src="test.processing"></script><canvas></canvas>
<br/>
Useless:)