OS X, Elixir, Ecto, Crypto, MySQL - mysql

Trying out Elixir & Ecto (not Phoenix) in a sample app to help me learn the language.
Running my program results in the following error:
=INFO REPORT==== 7-Apr-2016::16:23:28 ===
application: logger
exited: stopped
type: temporary
** (Mix) Could not start application tpos: exited in: Tpos.start(:normal, [])
** (EXIT) exited in: GenServer.call(#PID<0.164.0>, {:get_all, Tpos.Data.Models.ProfitCenter}, 5000)
** (EXIT) exited in: GenServer.call(#PID<0.163.0>, {:checkout, :run}, 5000)
** (EXIT) exited in: GenServer.call(#PID<0.168.0>, {:connect, [hostname: "localhost", timeout: 5000, otp_app: :tpos, repo: Tpos.Repo, adapter: Ecto.Adapters.MySQL, database: "tpos", username: "tpos", password: "tpos", port: 3306]}, 5000)
** (EXIT) an exception was raised:
** (UndefinedFunctionError) undefined function :crypto.hash/2 (module :crypto is not available)
(crypto) :crypto.hash(:sha, "tpos")
(mariaex) lib/mariaex/protocol.ex:150: Mariaex.Protocol.mysql_native_password/2
(mariaex) lib/mariaex/protocol.ex:47: Mariaex.Protocol.dispatch/2
(mariaex) lib/mariaex/connection.ex:284: Mariaex.Connection.process/2
(mariaex) lib/mariaex/connection.ex:251: Mariaex.Connection.handle_info/2
(stdlib) gen_server.erl:615: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:681: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
If I do a mix deps.clean --all and a mix.deps get and run the program again, it works. But only once. If I exit and attempt to run it again, I receive the above error.
The line that causes the error is:
data = Repo.all(ProfitCenter)
As I said, the first time through this runs fine and returns the expected data. It's only on subsequent runs that the error pops up.
From mix.exs:
defmodule Tpos.Mixfile do
use Mix.Project
def project do
[app: :tpos,
version: "0.0.1",
elixir: "~> 1.2",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps]
end
def application do
[ applications: [:mariaex, :ecto],
mod: { Tpos, [] } ]
end
defp deps do
[
{:credo, "~> 0.3", only: [:dev, :test]},
{:mariaex, "~> 0.5.0"},
{:ecto, "~> 1.1.5"},
{:exactor, "~> 2.2.0"}
]
end
end
I'm running OS X 10.11.1, and have tried several things to get it going based on advice like this.
Thoughts? Thanks!

The error states that you don't have :crypto module. You can verify that by running:
iex(1)> Application.start(:crypto)
:ok
If you get anything else than :ok, it means that your Erlang installation is not fully functional. It happens very often when you install Erlang via kerl. Kerl doesn't consider lack of openssl an error. It just skips crytpo libraries without warning.
To install fully functional Erlang with kerl you need to run:
brew install openssl
brew install unixodbc
After that create ~/.kerlrc file with following contents:
KERL_INSTALL_MANPAGES=yes
KERL_CONFIGURE_OPTIONS="--disable-hipe --enable-smp-support --enable-threads
--enable-kernel-poll --with-wx
--with-ssl=/usr/local/opt/openssl
--with-odbc=/usr/local/opt/unixodbc"
And try to reinstall Erlang. This config also adds wx-widgets which are handy if you want to run :observer application. Unixodbc also may come in handy, but less often.
If you are using different tool to install Erlang, you still need to point it to openssl path during compilation.
Alternatively, you can use packages provided by Erlang Solutions: https://www.erlang-solutions.com/resources/download.html They should install all required dependencies including crypto.

Related

lighttpd daemon failed to start after adding python support to read from cgi-bin

getting python to run from cgi-bin causes lighttpd daemon failed to start
$HTTP["url"] =~ "^/cgi-bin/" {
alias.url += ( "/cgi-bin/" => "/var/www/cgi-bin" )
cgi.assign = (".py" => "/usr/bin/python")
}
Am I doing something wrong
I also have below added in the beginning of /etc/lighttpd/lighttpd.conf
server.modules = (
"mod_indexfile",
"mod_setenv",
"mod_access",
"mod_alias",
"mod_redirect",
"mod_cgi"
)
Look in the lighttpd error log and review the trace for what you broke.
Alternatively, run lighttpd pre-flight tests on your config:
lighttpd -tt -f /etc/lighttpd/lighttpd.conf

How to fix “unexpected directory layout” error when Installing go-ethereum?

All, I hope this question belongs here.
I am following a Blockgeeks tutorial, trying to set up my environment for Ethereum blockchain development. I have basically gotten to the final step, installing swarm, but I am receiving an error that seems to be related to the structure of a folder on github. How should I fix this?
Handy info:
-OS: Windows 10, running this project within cygwin with proper gcc dependencies installed
-Go version: 1.11.4
I have tried to find a solution for days now, but nothing I've found has worked. Any help is appreciated.
Basically, everyone says these steps work for them: https://swarm-guide.readthedocs.io/en/latest/installation.html#generic-linux
Maybe it's something with cygwin?
When I attempt this command: $ go install -v ./cmd/swarm
I expect it to install properly, but i get this error:
unexpected directory layout:
import path: github.com/naoina/toml
root: C:\cygwin64\home\di203179\go\src
dir: C:\cygwin64\home\di203179\go\src\github.com\ethereum\go-ethereum\vendor\github.com\naoina\toml
expand root: C:\cygwin64\home\di203179\go\src
expand dir: C:\cygwin64\home\di203179\go\src\github.com\ethereum\go-ethereum\vendor\github.com\naoina\toml
separator: \
Any help is appreciated.
Update:
I think I found the code that throws this error here: https://golang.org/src/cmd/go/internal/load/pkg.go
And here is the snippet:
// dirAndRoot returns the source directory and workspace root
// for the package p, guaranteeing that root is a path prefix of dir.
func dirAndRoot(p *Package) (dir, root string) {
dir = filepath.Clean(p.Dir)
root = filepath.Join(p.Root, "src")
if !str.HasFilePathPrefix(dir, root) || p.ImportPath != "command-line-arguments" && filepath.Join(root, p.ImportPath) != dir {
// Look for symlinks before reporting error.
dir = expandPath(dir)
root = expandPath(root)
}
if !str.HasFilePathPrefix(dir, root) || len(dir) <= len(root) || dir[len(root)] != filepath.Separator || p.ImportPath != "command-line-arguments" && !p.Internal.Local && filepath.Join(root, p.ImportPath) != dir {
base.Fatalf("unexpected directory layout:\n"+
" import path: %s\n"+
" root: %s\n"+
" dir: %s\n"+
" expand root: %s\n"+
" expand dir: %s\n"+
" separator: %s",
p.ImportPath,
filepath.Join(p.Root, "src"),
filepath.Clean(p.Dir),
root,
dir,
string(filepath.Separator))
}
return dir, root
}
It seems there are several path-related issues that could make a Go project throw this error. But I feel my path is correct, so I'm still at a loss...
Upddate 2:
I have confirmed that the first if-statement from that snippet is running, and the first three conditions of the second if statement resolve to false (meaning they are not the cause of the error), so that means the last condition that is composed of multiple AND statements must be returning true since the error is throwing. Still can't tell why, though. Thanks for any help.

Meson find_program not finding program

I'm building a Vala program with gnome-builder and flatpak. I wan't to connect to a mySQL Database. Thats why I need to run mysql_config to get the right compiler flags.
So I added mysql_config = find_program('mysql_config')to my meson.build file.
When I try to compile I get meson.build:7:0: ERROR: Program(s) ['mysql_config'] not found or not executable.
When I run whereis mysql_config on command line I get the expected result mysql_config: /usr/bin/mysql_config. Also I can run mysql_config --cflags from command line with the expected result -I/usr/include/mysql -I/usr/include/mysql.
Thats why I think that the problem is that I'm building with flatpak-builder.
My ./meson.build:
project('zeiterfassunggtk', ['c', 'vala'], version: '0.1.0',
meson_version: '>= 0.40.0',
)
i18n = import('i18n')
mysql_config = find_program('mysql_config')
mysql_vapi = meson.get_compiler('vala').find_library('mysql')
mysql_dep = declare_dependency(c_args: run_command([mysql_config, '--cflags']).stdout().split(),
link_args: run_command([mysql_config, '--libs']).stdout().split(),
dependencies: [mysql_vapi])
subdir('data')
subdir('src')
subdir('po')
meson.add_install_script('build-aux/meson/postinstall.py')
My ./src/meson.build
zeiterfassunggtk_sources = [
'main.vala',
'window.vala',
'mysql.vala',
]
zeiterfassunggtk_deps = [
dependency('gio-2.0', version: '>= 2.50'),
dependency('gtk+-3.0', version: '>= 3.22'),
]
gnome = import('gnome')
zeiterfassunggtk_sources += gnome.compile_resources('zeiterfassunggtk-resources',
'zeiterfassunggtk.gresource.xml',
c_name: 'zeiterfassunggtk'
)
executable('zeiterfassunggtk', zeiterfassunggtk_sources,
vala_args: '--target-glib=2.50', dependencies: zeiterfassunggtk_deps,
install: true,
)
The full output of the build process:
flatpak build --env=LANG=de_AT.UTF-8 --env=USER=g.zehetner --env=HOME=/home/g.zehetner --env=PATH=/usr/bin:/bin --env=TERM=xterm-256color --env=V=0 --env=CCACHE_DIR=/home/g.zehetner/.cache/gnome-builder/flatpak-builder/ccache --env=PATH=/app/bin:/usr/bin --build-dir=/home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/builds/org.gnome.Zeiterfassunggtk.json-flatpak-org.gnome.Platform-x86_64-3.26-master --share=network --nofilesystem=host --filesystem=/home/g.zehetner/.cache/gnome-builder --filesystem=/home/g.zehetner/Projekte/ZeiterfassungGtk --filesystem=/home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/builds/org.gnome.Zeiterfassunggtk.json-flatpak-org.gnome.Platform-x86_64-3.26-master --env=V=1 '--env=CFLAGS=-O2 -g' '--env=CXXFLAGS=-O2 -g' --env=NOCONFIGURE=1 /home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/flatpak/staging/x86_64-master ninja
[0/1] Regenerating build files.
The Meson build system
Version: 0.46.0
Source dir: /home/g.zehetner/Projekte/ZeiterfassungGtk
Build dir: /home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/builds/org.gnome.Zeiterfassunggtk.json-flatpak-org.gnome.Platform-x86_64-3.26-master
Build type: native build
Project name: zeiterfassunggtk
Native C compiler: ccache cc (gcc 6.2.0 "cc (GCC) 6.2.0")
Appending CFLAGS from environment: '-O2 -g'
Appending LDFLAGS from environment: '-L/app/lib '
Native Vala compiler: valac (valac 0.38.2)
Appending LDFLAGS from environment: '-L/app/lib '
Build machine cpu family: x86_64
Build machine cpu: x86_64
Program mysql_config found: NO
meson.build:7:0: ERROR: Program(s) ['mysql_config'] not found or not executable
A full log can be found at /home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/builds/org.gnome.Zeiterfassunggtk.json-flatpak-org.gnome.Platform-x86_64-3.26-master/meson-logs/meson-log.txt
FAILED: build.ninja
/usr/bin/python3 /usr/bin/meson --internal regenerate /home/g.zehetner/Projekte/ZeiterfassungGtk /home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/builds/org.gnome.Zeiterfassunggtk.json-flatpak-org.gnome.Platform-x86_64-3.26-master --backend ninja
ninja: error: rebuilding 'build.ninja': subcommand failed
You can find the full code at Github.com

Gulp Build command is failing with error " EISDIR: Illegal operation on directory"

I am trying to run the gulp build task for the dev environment on the server but its failing. However, The same gulp build is working on my local machine. The function and error are given below.
Function:
// S3 Upload for dev
gulp.task('s3sync:dev', function () {
var config = {
accessKeyId: "-Key-",
secretAccessKey: "-Key-"
};
var s3 = require('gulp-s3-upload')(config);
return gulp.src("./dist/**")
.pipe(s3({
Bucket: 'example',
ACL: 'public-read'
}, {
maxRetries: 5
}))
});
Command:
Gulp build:development
Error:
[09:01:04] Starting 's3sync:dev'...
events.js:160
throw er; // Unhandled 'error' event
^
Error: EISDIR: illegal operation on a directory, read
at Error (native)
Any idea?
Finally, This problem has been solved by removing a system symlink which was created after the deployment from the capistrano which is also running below npm commands.
npm run clean && npm run build
After removing the system file. I have run the below command and it works fine.
gulp build:development

Issues while connecting to mysql using ruby

require 'rubygems'
require 'mysql'
db = Mysql.connect('localhost', 'root', '', 'mohit')
//db.rb:4: undefined method `connect' for Mysql:Class (NoMethodError)
//undefined method `real_connect' for Mysql:Class (NoMethodError)
db.query("CREATE TABLE people ( id integer primary key, name varchar(50), age integer)")
db.query("INSERT INTO people (name, age) VALUES('Chris', 25)")
begin
query = db.query('SELECT * FROM people')
puts "There were #{query.num_rows} rows returned"
query.each_hash do |h|
puts h.inspect
end
rescue
puts db.errno
puts db.error
end
error i am geting is:
undefined method `connect' for Mysql:Class (NoMethodError)
OR
undefined method `real_connect' for Mysql:Class (NoMethodError)
EDIT
return value of Mysql.methods
["private_class_method", "inspect", "name", "tap", "clone", "public_methods", "object_id", "__send__", "method_defined?", "instance_variable_defined?", "equal?", "freeze", "extend", "send", "const_defined?", "methods", "ancestors", "module_eval", "instance_method", "hash", "autoload?", "dup", "to_enum", "instance_methods", "public_method_defined?", "instance_variables", "class_variable_defined?", "eql?", "constants", "id", "instance_eval", "singleton_methods", "module_exec", "const_missing", "taint", "instance_variable_get", "frozen?", "enum_for", "private_method_defined?", "public_instance_methods", "display", "instance_of?", "superclass", "method", "to_a", "included_modules", "const_get", "instance_exec", "type", "<", "protected_methods", "<=>", "class_eval", "==", "class_variables", ">", "===", "instance_variable_set", "protected_instance_methods", "protected_method_defined?", "respond_to?", "kind_of?", ">=", "public_class_method", "to_s", "<=", "const_set", "allocate", "class", "new", "private_methods", "=~", "tainted?", "__id__", "class_exec", "autoload", "untaint", "nil?", "private_instance_methods", "include?", "is_a?"]
return value of Mysql.methods(false)
is []... blank array
EDIT2
mysql.rb file
# support multiple ruby version (fat binaries under windows)
begin
require 'mysql_api'
rescue LoadError
if RUBY_PLATFORM =~ /mingw|mswin/ then
RUBY_VERSION =~ /(\d+.\d+)/
require "#{$1}/mysql_api"
end
end
# define version string to be used internally for the Gem by Hoe.
class Mysql
module GemVersion
VERSION = '2.8.1'
end
end
I had this same problem and solved this way:
make sure you have installed only the gem ruby-mysql
and not the gem mysql. For me, now:
$ gem list --local | grep mysql
ruby-mysql (2.9.2)
If that is not the case, uninstall
$ sudo gem uninstall mysql
(I uninstalled every gem with mysql in its name)
and then reinstalled ruby-mysql.
In my case, because I have mysql installed in a usb disk
the installation command was:
sudo env ARCHFLAGS="-arch i386" gem install ruby-mysql --
--with-mysql-config=/Volumes/usb/opt/bin/osx/mysql/bin/mysql_config
--with-mysql-lib=/Volumes/usb/opt/bin/osx/mysql/lib/
--with-mysql-dir=/Volumes/usb/opt/bin/osx/mysql
(and I was using the 32bits binary for MacOs, don't know if that applies for you)
Finally, my ruby test program was
require 'rubygems'
require 'mysql'
dbh = Mysql.real_connect('localhost', 'root', 'your password', 'TEST')
res = dbh.query("select * from Persons;");
puts res.class
res.each do |row|
puts row.join(" ")
end
Short answer:
Remove mysql-ruby
Rebuild mysql-ruby
Reinstall mysql-ruby.
Alternative answer
Remove mysql-ruby
Install ruby-mysqlThe pure ruby MySQL protocol client.
Longer Explanation:
This just happened to me. My 2.8.1 mysql-ruby bindings had been built against libmysqlclient.so.15, and worked fine until I upgraded my MySQL installation and replaced that client library with .so.16. Rebuild resolved this issue.
The 3rd-party gem you used (I used it, too) introduces faulty logic in the mysql.rb file it supplies to trap an error on Windows systems. Notice that in the excerpt you posted, that this mysql.rb file does not re-raise the LoadError on non-Windows platforms. Bummer.
Edit
I contacted the gemspec author, and he has corrected the error! (2010-05-25) With luck no one else will be baffled by this silent failure.