Skip to content

Instantly share code, notes, and snippets.

@junjis0203
junjis0203 / ev3-sensor.c
Created November 21, 2013 14:27
Example of getting sensor value from EV3. Sorry, I can't describe how to fetch sensor value in English.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include "lms2012.h"
@junjis0203
junjis0203 / ev3-display.c
Created November 21, 2013 14:29
Example of drawing display for EV3. Sorry, I can't describe how to draw display in English.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <stdio.h>
#include <stdlib.h>
@junjis0203
junjis0203 / ev3-sound.c
Created November 21, 2013 14:31
Example of playing sound in EV3. Sorry, I can't describe how to play sound in English.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
/*
* OpenCVのチュートリアルにあるサンプルでassertionエラーになるので
* カメラが動き出すまで待たないといけないのかと思いコードを追加したら
* ビンゴだった・・・
*/
#include "opencv2/opencv.hpp"
using namespace cv;
/*
* 画像処理をparallel_forを使って並列にしてみた例
* mosaicはプラットフォーム(VS2013)依存な方法
* mosaic2はOpenCVの方法をぱくったのだがparallel_for_ってユーザが使っていいのだろうか
*/
#include "opencv2/opencv.hpp"
using namespace cv;
# Usage: create_db_seed(Person) => "Person.first_or_create([{name: \"Jon\",age:23},{name: \"Mary\",age:31}])"
def create_db_seed(model)
records = model.all.map {|r|
attrs = r.attributes.map {|k,v|
next if /^id|created_at|updated_at$/ =~ k
"#{k}: #{v.inspect}"
}.compact.join(',')
"{#{attrs}}"
}.join(",\n")
@junjis0203
junjis0203 / get-db-adapter.rb
Created July 31, 2014 07:47
降順で並べるときにnullを最後に持ってきたいが書き方はDBMSに依存するようなので、利用しているDBMSを取得する方法を調べた
Rails.configuration.database_configuration[Rails.env]['adapter']
@junjis0203
junjis0203 / file0.py
Created July 24, 2017 14:37
Djangoでモデル保存時(初回)に実行されるSQLを確認する ref: http://qiita.com/junjis0203/items/8ce6fcfe857e45dc8561
>>> from polls.models import Question, Choice
>>> from django.utils import timezone
>>> question = Question(question_text="What's new?", pub_date=timezone.now())
>>> question.save()
@junjis0203
junjis0203 / onemax_2d.py
Created October 13, 2017 03:37
2D gene example derived from onemax_short.py
import random
import numpy
from deap import algorithms
from deap import base
from deap import creator
from deap import tools
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
@junjis0203
junjis0203 / sample1.html
Created January 31, 2018 14:08
vis.js network example
<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.css" rel="stylesheet">
<style type="text/css">
#network {
width: 400px;
height: 400px;
border: 1px solid #000;
}
</style>