Archivos para Octubre 2008
Ahh…
#include <windows.h>
#include <stdio.h>
Esta BAaaal. Tiene que ser:
#include <stdio.h>
#include <windows.h>
Usando el mysql-connector-java aka. JDBC driver de Java o entendiendo cómo funciona el -classpath
Como estoy en Linux, decidí utilizar el OpenJDK, así que cuando instalo el JDBC driver, esto es un simple
yum install mysql-connector-java
. Compile mi clase de mysql que se conecta a la base de datos como lo haría normalmente. Sim embargo, al momento de correrlo…
javac conectarseadb.java
java conectarseadb
Esto no funciona y te va a decir que no encuentra el driver. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver. o bien, Exception in thread “main” java.lang.NoClassDefFoundError: conectarseadb. Para resolver este problema, lo que tuve que hacer es buscar cúal era el path donde se encontra el driver–en mi caso fue /usr/share/java/mysql-connector-java.jar– y DECLARAR el classpath de tal forma que al momento de correr el programa la JVM encuentre ambas clases, la del driver que se encuentra en com.mysql.jdbc.Driver y la que se acaba de compilar. Lo más difícil fue encontrar el comando que lograra esto. Puesto que
java -classpath "/usr/share/java/mysql-connector-java.jar" conectarseadb
NO INCLUYE al mismo directorio en el lo estas ejecutando (!?). Para poder incluirlo se tiene que hacer de la siguiente manera
java -classpath .:"/usr/share/java/mysql-connector-java.jar" conectarseadb
De ésta forma el programa correrá normalmente. De nuevo, gracias al IRC.
…
…
…
Ok, ya una vez que se logró hacer eso, cada vez que queremos utilizar el flymake mientras se programa algo en as3. Se hace lo siguiente:
- Se tiene que crear el script de ruby con el que vamos a realizar la magia. Pongo un ejemplo a continuación:
#!E:/ruby/bin/ruby
require 'webrick'
include WEBrick
require 'net/http'
require 'fileutils'COMPILE_COMMAND = "mxmlc Wally.as"
SWF_TO_RUN = "Wally.swf"
PORT = 2001
HOST = "localhost"############################################
# If a parameter was provided, take action #
############################################begin
case ARGV[0]
when "compile"
http = Net::HTTP.new(HOST, PORT)
resp, date = http.get('/compile')
puts resp.body
exit
when "compile_and_show"
http = Net::HTTP.new(HOST, PORT)
resp, date = http.get('/compile_and_show')
puts resp.body
exit
when "exit"
http = Net::HTTP.new(HOST, PORT)
resp, date = http.get('/exit')
puts resp.body
exit
end
rescue => e
puts "Command failed: #{e}"
exit(1)
end#################################################################
# Otherwise, if there are no parameters, start the build server #
#################################################################def read_to_prompt(f)
f.flush
output = ""
while chunk = f.read(1)
STDOUT.write chunk
output << chunk
if output =~ /^\(fcsh\)/
break
end
end
STDOUT.write ">"
output
endfcsh = IO.popen("fcsh.exe 2>&1", "w+")
read_to_prompt(fcsh)
fcsh.puts COMPILE_COMMAND
read_to_prompt(fcsh)#####################################################
# Now expose the shell through a small http server #
#####################################################s = HTTPServer.new(
:Port => PORT,
:Logger => Log.new(nil, BasicLog::WARN),
:AccessLog => []
)s.mount_proc("/compile"){|req, res|
fcsh.puts "compile 1"
output = read_to_prompt(fcsh)
res.body = output
res['Content-Type'] = "text/html"
}s.mount_proc("/compile_and_show"){|req, res|
fcsh.puts "compile 1"
output = read_to_prompt(fcsh)
res.body = output
res['Content-Type'] = "text/html"
if output =~ /#{SWF_TO_RUN} \([0-9]/
system "SAFlashPlayer.exe #{SWF_TO_RUN}"
end
}s.mount_proc("/exit"){|req, res|
s.shutdown
fcsh.close
exit
}trap("INT"){
s.shutdown
fcsh.close
}s.start
- Ahora tenemos que agregarle lo siguiente al .emacs
(require 'actionscript-mode)
(add-to-list 'auto-mode-alist '("\\.as$" . actionscript-mode))(require 'compile)
;; Find error messages in flex compiler output:
(push '("^\\(.*\\)(\\([0-9]+\\)): col: \\([0-9]+\\) Error: \\(.*\\)$" 1 2 3 2) compilation-error-regexp-alist)(require 'flymake)
(defvar as3-build-file nil)
(defvar as3-default-build-file-name "build_manager.rb")
(defun flymake-as3-mode (&optional file)
(interactive
(list (read-file-name "Build file: " default-directory as3-default-build-file-name)))
(message file)
(flymake-mode 0)
(let* ((build-file
(if file (expand-file-name file)
(if as3-build-file as3-build-file
(expand-file-name (concat default-directory as3-default-build-file-name))))))
(if (file-exists-p build-file)
(progn
(setq as3-build-file build-file)
(flymake-mode 1)
(message (concat "Set flymake mode with build file, " build-file ".")))
(message (concat "Build file, " build-file ", does not exist.")))))(defun flymake-as3-init ()
(if as3-build-file
(progn
(remove-hook 'after-save-hook 'flymake-after-save-hook t)
(save-buffer)
(add-hook 'after-save-hook 'flymake-after-save-hook nil t)
(list "ruby" (list as3-build-file "compile")))))(defun flymake-as3-cleanup () (message "Flymake finished checking AS3."))
(defun flymake-as3-get-real-file-name (tmp-file) tmp-file)(setq flymake-allowed-file-name-masks
(cons '(".+\\.as$\\|.+\\.mxml$"
flymake-as3-init
flymake-as3-cleanup
flymake-as3-get-real-file-name)
flymake-allowed-file-name-masks))(setq flymake-err-line-patterns
(cons '("^\\(.*\\)(\\([0-9]+\\)): col: \\([0-9]+\\) Error: \\(.*\\)$" 1 2 3 4)
flymake-err-line-patterns))(define-key actionscript-mode-map (kbd "C-c p") 'flymake-goto-prev-error)
(define-key actionscript-mode-map (kbd "C-c n") 'flymake-goto-next-error)(defun as3-compile ()
"Launch an emacs compile for the current project"
(interactive)
(if as3-build-file
(let ((command (concat "ruby " as3-build-file " compile_and_show")))
(save-some-buffers (not compilation-ask-about-save) nil)
(setq compilation-directory (file-name-directory as3-build-file))
(compilation-start command))))(define-key actionscript-mode-map (kbd "C-c k") 'as3-compile)
(add-hook 'actionscript-mode-hook
'(lambda ()
(flymake-as3-mode)
))
- Cada vez que utilizamos el flymake, se tiene que correr primero el script en ruby: ruby build_manage.rb en la shell. Ahora nos metemos al emacs y abrimos algún archivo para Action Script 3.0 . Tenemos que hacer M-x as3-compile. Ahí nos va a pedir el nombre del build_manage file que hicimos.
Una vez hecho esto correctamente, el flymake revisará la sintaxis del AS3. Uff
¿Las coincidencias existen?
Estaba buscando un kanji en el kanjimap de rikai.com 「削」porque
algunas veces el kanji se muestra diferente dependiendo del tipo de
fuente japonesa que se esté usando en la computadora. Al principio, para
verificar que se trataba en realidad del mismo kanji y no de otro de los engaños
del cerebro, busqué las palabras que contenían este kanji. En este
momento comencé a tararear la canción de Erasure, (la única buena de
ellos: "I try to discover…").¿Por qué comencé a tararear ésta canción?
Seguí con mi búsqueda del kanji, y encontré una de las palabras con las
que estaba familiarizado: 削除. Aunque ya sabía lo que significaba
(borrar de manera abstracta, o bien, en una computadora), desplegué la
lista de significados de la palabra. Sigo tarareando la canción y ahora
recordando el capítulo de Scrubs donde a todos se les pegó la misma
canción. Cuando salen los resultados de la lista aparece la palabra
‘erasure’. 削除 = erasure. Es decir, a pesar de que yo tuve la duda de
que el kanji podría ser diferente, mi cerebro supo que se trataba del
mismo kanji todo este tiempo e incluso me obligó a cantarle la canción
de Erasure, mientras yo me ponía a verificarlo. Bien podría haber dicho
que era una coincidencia たまたま pero la verdad es que así es como
funciona nuestro cerebro. Ni hablar.
Primero, para hacer tomar el xml se utiliza de la siguiente forma.
$xml = simplexml_load_file('http://whoismyrepresentative.com/whoismyrep.php?zip=20005');
Si le hacemos ‘print_r’ nos va a imprimir en pantalla esto:
SimpleXMLElement Object ( [@attributes] => Array ( [n] => 1 ) [rep] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => Eleanor Holmes Norton [state] => DC [district] => 1 [phone] => (202) 225-8050 [office] => 2136 Rayburn [link] => http://www.house.gov/norton/ ) ) )
Lo cual proviene de un xml de esta forma:
<result n='1' >
<rep name='Eleanor Holmes Norton' state='DC' district='1' phone='(202) 225-8050' office='2136 Rayburn' link='http://www.house.gov/norton/' />
</result>
Entonces, si queremos tomar los atributos del tag ‘rep’ tenemos que hacerlo de la siguiente manera:
$xml->rep->attributes()->name
Porque si se hace de la siguiente manera:
$xml->rep[0]->attributes()->name
Algo sale mal y no tengo idea qué será. De hecho no tengo idea de cómo funciona esta cosa. orz-.PHP
Consejo de Linus Torvalds
“Nobody should start to undertake a large project. You start with a small _trivial_ project, and you should never expect it to get large. If you do, you’ll just overdesign and generally think it is more important than it likely is at that stage. Or worse, you might be scared away by the sheer size of the work you envision. So start small, and think about the details. Don’t think about some big picture and fancy design. If it doesn’t solve some fairly immediate need, it’s almost certainly over-designed. And don’t expect people to jump in and help you. That’s not how these things work. You need to get something half-way _useful_ first, and then others will say “hey, that _almost_ works for me”, and they’ll get involved in the project.”
Orz Orz orz orz
やっぱり mejor me quedo con este blog. Sí… mejor me voy a quedar
acá. Acabo de descubrir que lo de orz puede ser un poco 汚い: orz-.
Muchas cosas por hacer…
- Un juego para Web, celular y Facebook de la clase de Diseño Web
- Lo de la casa mágica para la clase de Redes III
- Una máquina virtual Linux-Windows para la clase de Operativos
- Lo del Proyecto del Gobierno para la clase de Aplicaciones distribuidas
- Y lo más importante… TERMINAR DE ESTUDIAR 日本語!!!
Todo va a salir bien, todo va a salir bien…
