2012-01-01から1年間の記事一覧

ファイル入出力

#include <stdio.h> int main(void) { FILE *fp; char *str = "Hello World"; char file_name[100] = "./sample/"; strcat(file_name, "test.txt"); fp = fopen( file_name, "w" ); if( fp == NULL ){ printf( "ファイルが開けません\n"); return -1; } fputs( str, f</stdio.h>…

c言語でネットワークプログラミング

サーバー側 #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> int main(void) { int server_socket; struct sockaddr_in server_address; struct sockaddr_in client_address; int len; int socket0; //AF_INTF : 2ホスト間プロセス通信 SOCK_STREAM : 順</netinet/in.h></sys/socket.h></sys/types.h></unistd.h></stdio.h>…

Swing-3-

import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JLabel; public class test_gui extends JFrame { public test_gui() { this.setSize(400, 200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new …

Swing-2-

import javax.swing.JFrame; public class test_gui extends JFrame { public test_gui() { this.setSize(200, 200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { test_gui sample = new test_gui();…

Swing

import javax.swing.JFrame; public class test_gui { public static void main(String[] args) { javax.swing.JFrame frame = new JFrame("もうどうとなれと君が言う"); frame.setSize(600, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f…

'; $name = array( array('natsumi', 'reika', 'aya'), array('tae', 'kaoru', 'kiyomi') ); print_r($name); print '<br><br>マジカルインクリメント<br>'; $str = 'y'; $str++; print "{$str}<br>"; print ++$str; print '<br><br>連想配列をforeachで回す<br>'; $person = array('nats…

PHPの基本

'; $name = array( array('natsumi', 'reika', 'aya'), array('tae', 'kaoru', 'kiyomi') ); print_r($name); print '<br><br>マジカルインクリメント<br>'; $str = 'y'; $str++; print "{$str}<br>"; print ++$str; print '<br><br>連想配列をforeachで回す<br>'; $person = array('nats…

マウスドラッグ

#include<GL/glut.h> unsigned char mouseFlag = GL_FALSE; double yAngle = 0; int xStart, yStart; void init(char *name) { int width = 400, height = 400; glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(width, height); glutCreateWindow(name); glClearCo</gl/glut.h>…

スレッドの生成 for pthread

#include <stdio.h> #include <pthread.h> #include <stdlib.h> #include <unistd.h> typedef struct { char str; int sleep_time; } ThreadArgument; void *test(ThreadArgument *arg) { while (1) { fprintf(stderr, "thread\n"); sleep(arg->sleep_time); } } int main(int argc, char *argv[]) { </unistd.h></stdlib.h></pthread.h></stdio.h>…

連結リスト

いろいろ手抜きな連結リスト #include<stdio.h> #include<stdlib.h> typedef struct person { int score; struct person *next; } Person; typedef struct { Person *head; Person *current; } List; void insert_front(List *list, int score) { Person *tmp = list->head; lis</stdlib.h></stdio.h>…

相互排他制御

def test(n) n + 1 end sum = 0 mutex = Mutex.new threads = (1..10).map do Thread.new do 10000.times do mutex.synchronize {sum = test(sum) } end end end threads.each(&:join) p sum

JDBCその1

import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; class test2 { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Drive…

Rubyで簡単なUDPサーバーを立てる

require "socket" socket = UDPSocket.open socket.bind("127.0.0.1", 13) loop do message, sender = socket.recvfrom(1024) puts "#{Time.now} : #{sender[3]} : #{message}" STDOUT.flush end netcatで接続$ nc -u 127.0.0.1 13 sekai kouiti simada nats…

Rubyでスレッド

スレッドの生成 ary = ('a'..'c').to_a threads = Array.new ary.each do |elem| threads << Thread.new(elem) do |s| sleep(rand(0.1)) 3.times{|i| print "#{s} : #{i}\n" } end end threads.each{|thread| thread.join} 実行結果D:\workplace>ruby test.r…

スレッドの同期

夜空と星奈が銀行から3000円を引き出す。 public class Bank { static Account account; public static void main(String[] args) { account = new Account(3000); class Person extends Thread { public Person(String name) { super(name); } public v…

スレッドの停止

public class test3 extends Thread { static boolean flag = false; public static void main(String[] args) throws InterruptedException{ test3 test = new test3(); test.start(); Thread.sleep(30); System.out.println("flag sets true."); flag = tr…

スレッドの生成

Threadクラスをextendsしてスレッドを生成する。 public class test1 extends Thread { public static void main(String[] args) { test1 test = new test1(); test.start(); System.out.println(Thread.currentThread().getName()); } public void run() { …

wait()とnotify()

import java.util.ArrayList; public class test4 extends Thread { private ArrayList<String> arraylist = new ArrayList<String>(); public void add(String s) { synchronized (arraylist) { arraylist.add(s); arraylist.notify(); } } public void run() { while (true</string></string>…

WEBrickを少しいじる

http://localhost:8000/cocoa require 'webrick' include WEBrick cocoa_proc = lambda do|req, resp| resp['Content-Type'] = "text/html" resp.body = %{ <html> <body> <font color="brown">Cocoa</font> </body> </html> } end cocoa = HTTPServlet::ProcHandler.new(cocoa_proc) server = WEBrick::HTTPServer…

MySQLの基本的な使い方

D:\workplace>mysql -u root -p mysql> show databases -> ; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec) mysql> create datab…

キーボードから数字を読み込む

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class test1 { public static void main(String[] args) { int total = 0; for (int i = 0; i < 5; i++) { try { Buffe…

httpサーバー

index.html <html> <title>Hello WEBtick!!</title> <body> <font size = 5>Hello WEBrick!!</font> </body> </html> require 'webrick' server = WEBrick::HTTPServer.new( :DocumentRoot => File.join(Dir::pwd, "index.html"), :Port => 8000 ) ['INT', 'TERM'].each do |signal| Signal.trap(signal) { server.shutdown…

オイラー法による等加加速度運動

#include<GL/glut.h> double dt = 0.02; //秒 typedef struct{ float xPosition; float yPosition; float zPosition; float xVelocity; float yVelocity; float zVelocity; float xAcceleration; float yAcceleration; float zAcceleration; float xJerk; float yJerk; </gl/glut.h>…

シリアライズ化

import java.io.Serializable; public class say implements Serializable { void say1() { System.out.println("Patriotism is the virtue of the vicious."); } void say2(int num) { System.out.println(num); } } import java.io.FileInputStream; impor…

UDPクライアント

import java.io.IOException; import java.io.InterruptedIOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetSocketAddress; public class UDPEchoClient { public static void main(String[] args) throw…

UDPを用いたエコーサーバー

import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; public class UDPEchoServer { private static final int ECHO_MAX_SIZE = 255; public static void main(String[] args) throws IOException { DatagramSock…

オイラー法による等加速度直線運動

#include<GL/glut.h> double dt = 0.02; //秒 int step = 0; typedef struct{ float xPosition; float yPosition; float zPosition; float xVelocity; float yVelocity; float zVelocity; float xAcceleration; float yAcceleration; float zAcceleration; }PARTICLE; P</gl/glut.h>…