Skip to content

Instantly share code, notes, and snippets.

View tamanobi's full-sized avatar

Kohki YAMAGIWA tamanobi

View GitHub Profile
@tamanobi
tamanobi / imageviewer.js
Last active August 29, 2015 14:05
Display image(Only anchor linked to png, jpg, gif) overlapped to webpage.
(function() {
var bd = document.getElementsByTagName("body")[0];
var cw = document.documentElement.clientWidth;
var an = document.getElementsByTagName("a");
var cf = document.getElementById("iv");
if(cf){bd.removeChild(cf);return null;}
var li = [];
for (var i = 0; i < an.length; i++) {
var ref = an[i].getAttribute("href");
var re = new RegExp("(.*)[.](jpg|gif|png)");
@tamanobi
tamanobi / compile_error
Created September 7, 2014 11:53
compile error(libwebsockets)
test.cpp:83:44: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
#define LOCAL_RESOURCE_PATH INSTALL_DATADIR"/libwebsockets-test-server"
^
test.cpp:84:23: note: in expansion of macro 'LOCAL_RESOURCE_PATH'
char *resource_path = LOCAL_RESOURCE_PATH;
^
test.cpp: In function 'void dump_handshake_info(libwebsocket*)':
test.cpp:155:35: error: invalid conversion from 'int' to 'lws_token_indexes' [-fpermissive]
if (!lws_hdr_total_length(wsi, n))
^
@tamanobi
tamanobi / Tribonacci.cpp
Last active August 29, 2015 14:14
トリボナッチ数列(非再帰型)
#include <iostream>
#include <sstream>
using namespace std;
// tribonacci sequence
long tribonacci(int n){
long a=1, b=2, c=4;
if(1>n){
return 0;
}else if(1==n){
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Here your code !
process.stdin.on('data', function (chunk) {
var Naive = function(list1, list2){
var res = [];
for(var i = 0; i < list1.length; i++){
for(var j = 0; j < list2.length; j++){
if(list1[i] == list2[j]) res.push(list1[i]);
}
@tamanobi
tamanobi / howtouse_intersection.cpp
Last active August 29, 2015 14:14
C++で、与えられた2つの配列から共通集合を取り出す
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
int primary[] = { 1, 2, 4, 3, 5, 7, 11, 13 };
int number[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
int result[256];
int* ret;
@tamanobi
tamanobi / knuth_shuffle.cpp
Last active August 29, 2015 14:15
Knuth Shuffle(Fisher-Yates Shuffle)を実装。
#include <iostream>
#include <vector>
#include <random>
#include <cmath>
// knuth shuffle
void shuffle(std::vector<int>& ary){
std::random_device rd;
std::mt19937 mt(rd());
long N = ary.size();
@tamanobi
tamanobi / rotation.cpp
Created February 14, 2015 08:36
配列の左回転の実装比較
#include <iostream>
#include <vector>
#include <random>
// shift array left 1 time
int shiftLeft(std::vector<int>& ary) {
using std::vector;
if(ary.size() > 2) {
int t = ary[0];
for(int i=1; i<ary.size(); i++){
@tamanobi
tamanobi / mergesort.cpp
Created February 15, 2015 05:33
merge sort
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
void merge_inplace(std::vector<int>& ary, long head, long mid, long tail) {
if ( ary.size() > 1 ) {
std::vector<int> L,R;
// copy
for (long i=head; i<=mid; i++) { L.push_back(ary[i]); }
@tamanobi
tamanobi / quick.cpp
Created February 15, 2015 18:36
Quick Sortのプログラムです。乱択クイックソート
#include <iostream>
#include <random>
#include <vector>
#include <algorithm>
template<typename T>
long choosePivot (const std::vector<T>& ary, long head, long tail) {
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_int_distribution<long> dist(head, tail);
@tamanobi
tamanobi / bfs.cpp
Created February 17, 2015 07:11
bfsの練習
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <limits>
#include <functional>
#include <queue>
#include <array>