我正在使用本教程学习Heroku上的clojure .我在其他教程中也遇到过同样的问题.
无论如何,在环中使用jetty适配器,你有这样的事情:
(defroutes routes
...)
(defn start []
(ring/run-jetty #'routes {:port 8080 :join? false}))
Run Code Online (Sandbox Code Playgroud)
我不明白是什么#'routes意思.如果我用它替换它routes似乎工作正常.什么是#'symbol符号是什么意思?研究起来非常困难.
我刚刚开始与Elm合作,使用我正在研究的Rest API进行一些前端原型设计.通常,API返回可以解码的"合理"数据结构,因为键和值类型是众所周知的,但是几种资源类型返回的data条目只有具有没有预定结构的原始json.
到目前为止我读过的所有东西似乎都假设你知道你正在解码的数据的结构,而在普通的js中,相对容易循环键并反映类型以确定它们应该如何在运行时处理.我还没有看到在Elm中处理这类数据的明确路径.
例如,
{
"name":"foo",
"data": {
"bar": [{"baz":123}, "quux"]
},
...
}
Run Code Online (Sandbox Code Playgroud)
我想知道目前是否可以data用类似的东西来解析条目的值
function go(obj)
for key in keys(foo)
if foo[key] is an object
go(foo[k])
else if foo[key] is an array
map(go, foo[k])
...
Run Code Online (Sandbox Code Playgroud)
特别:
我正在使用XAMPP Mac进行本地开发,但我在工作时使用了这些代码(使用Windows和其他相同的开发环境)并且它工作正常:
$objPHPExcel = new PHPExcel();
$sheet = $objPHPExcel->createSheet();
$sheet->fromArray($a);
...
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//$objWriter->save('P:/Projects/Mess3/Sadness.xlsx');
$objWriter->save('/Users/tjb1982/Desktop/sadness.xlsx');
Run Code Online (Sandbox Code Playgroud)
已注释掉的文本可与我的Windows系统一起使用.我试图将文件输出到'php:// output'并得到一个乱码(这是预期的吗?).
我似乎无法找到任何在遇到权限问题或者在尝试保存文件时打开文件的人之外遇到此问题的人.请帮忙!
我被告知有机会做VoiceXML - 我没有任何经验,但显然可能没问题.然而,我做了一些关于这项技术的初步研究,它看起来很旧,从未获得过多的牵引力等等,但我无法弄清楚什么技术(y,ies)取而代之.VoiceXML现在是一项很好的技能,还是它正在消失/从未真正陷入那么多?如果它正在消亡,它取代了什么?为什么?
我是一名音乐家,我正在玩Clojure中的一个功能,在A4和A5的音高(分别是440Hz和880Hz频率)之间重现一个简单的滑音,带有指数曲线,但我遇到了麻烦.基本上我想像这样使用它:
(def A4 440)
(def A5 880)
(gliss A4 A5)
Run Code Online (Sandbox Code Playgroud)
哪个应该给我这样的东西:
=>(441 484 529 576 625 676 729 784 841)
Run Code Online (Sandbox Code Playgroud)
除了我最终还想给它一个采样率作为第三个参数.
这种作品:
(defn gliss
[start-pitch end-pitch s-rate]
(let [f (fn [x]
(expt x 2))]
(remove nil?
(map
(fn [x]
(when (and
(>= (f x) start-pitch)
(<= (f x) end-pitch))
(f x)))
(range 0 10000 s-rate)))))
Run Code Online (Sandbox Code Playgroud)
我想问题是我想要使用该功能的方式.而不是说"glissando从x1到x2,其中f(x)= x ^ 2",我真的想说"glissando从f(x)== 440到f(x)== 880"所以我'我最初没有给出一个x的范围,因此为什么我在这种情况下只硬编码0到10000,但这很难看.
有什么更好的方法来完成我想要做的事情?
更新:我在需要修复的术语中犯了一个错误(对于所有来到这里寻找在Clojure中记录一个glissando的人来说).第三个参数不是真正的采样率,它应该是样本数.换句话说,采样率(可能是44100Hz或48000Hz等)决定了特定持续时间内所需的采样数.如果你需要一个带有e从A4到A5 的指数曲线的滑音,持续时间为500毫秒,采样率为44100,你可以使用这些函数:
(defn gliss
[start end samples]
(map #(+ start
(*
(math/expt (/ (inc %) …Run Code Online (Sandbox Code Playgroud) 我们正在开发一个有一些Clojure-Java互操作的项目.在这一点上,我们有一个具有各种依赖关系的类,我们将它们放入Eclipse中的用户库进行开发,但当然使用Leiningen(2.x)时没有任何帮助.我们的大多数依赖项都是专有的,因此它们不在某个存储库中.
这样做最简单/最直接的方法是什么?
我见过leiningen - 如何为本地jar添加依赖项?,但它似乎已过时了?
更新:所以我按照这些说明和github上的lein部署文档为我的jar创建了一个本地maven存储库,并编辑了我的project.clj文件,如下所示:
:dependencies [[...]
[usc "0.1.0"]]
:repositories {"usc" "file://maven_repository"}
Run Code Online (Sandbox Code Playgroud)
maven_repository位于项目目录下(因此不使用file:///).当我跑"lein deps"时 - 我收到了这条消息:
Retrieving usc/usc/0.1.0/usc-0.1.0.pom from usc
Could not transfer artifact usc:usc:pom:0.1.0 from/to usc (file://maven_repository): no supported algorithms found
This could be due to a typo in :dependencies or network issues.
Could not resolve dependencies
Run Code Online (Sandbox Code Playgroud)
什么是"找不到支持的算法",我该如何解决?
Update2:在这里找到答案的最后一点.
我正在测试Clojure/Java互操作.我创建了一个新的Leiningen项目并创建了这个project.clj文件,其中包含一些我将使用的依赖项:
(defproject kente "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.4.0"]
[ring/ring-jetty-adapter "1.0.0-RC1"]
[compojure "0.6.5"]
[hiccup "0.3.7"]
[cheshire "5.0.1"]]
:java-source-paths ["src/java"]
:plugins [[lein-ring "0.8.2"]]
:ring {:handler kente.core/application}
:main kente.core)
Run Code Online (Sandbox Code Playgroud)
我还包括了"java-source-paths"列表,并将一个hello.java文件放入src/java目录中,如下所示:
public class hello {
private String msg = "Hello World";
public String sayHello() {
return this.msg;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我从模板创建了这个core.clj文件:
(ns kente.core
(:require [java/hello]))
(defn application
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
(defn -main [] (application "Say: …Run Code Online (Sandbox Code Playgroud) 我正在创建一个生成.wav文件的函数.我已经设置了标题,但是我遇到了麻烦data.我有一个函数用于创建880Hz的正弦波(至少我认为这是它的作用,但这不是我的问题) - 问题是,如何将字节数组的集合转换为只有一个字节数组及其内容?这是我最好的尝试:
(defn lil-endian-bytes [i]
(let [i (int i)]
(byte-array
(map #(.byteValue %)
[(bit-and i 0x000000ff)
(bit-shift-right (bit-and i 0x0000ff00) 8)
(bit-shift-right (bit-and i 0x00ff0000) 16)
(bit-shift-right (bit-and i 0xff000000) 24)]))))
(def leb lil-endian-bytes)
(let [wr (io/output-stream (str name ".wav") :append true)]
(.write wr
(byte-array (flatten (concat (map
(fn [sample] (leb (* 0xffff (math/sin (+ (* 2 3.14 880) sample)))))
(range (* duration s-rate)) )))))
Run Code Online (Sandbox Code Playgroud)
但它没有做我想做的事情:将所有字节数组连接成一个向量,然后连接到单个字节数组.这对我来说有意义为什么它不能:它不能连接/压平一个字节[]因为它不是一个向量; 它是一个字节[].并且它不能将byte []转换为字节.但是我需要做些什么来实现这个目标呢?
我有一个AngularJS $resource:
App.factory("pjApi", ["$resource", function($resource) {
return $resource("/api/:user/:action/:post_id/", {action:"posts"});
}]);
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我基本上像这样使用它:
$scope.deletePost = function(post_id) {
$scope.posts.forEach(function(post) {
if (post_id === post.id)
post.$delete({user:"tjb1982",action:"delete",post_id:post.id});
});
}
Run Code Online (Sandbox Code Playgroud)
服务器给出状态为200,application/json和body的响应:"1"
Angular对此响应的作用是删除已删除的Resource对象实例,但随后Angular将其替换为来自服务器的响应(即"1"),就好像我正在创建或更新:
posts
[Resource { 0="1", $$hashKey="00D", $get=function(), more...}]
等等
所以我的模板更新了这个新的(大部分是空白的)信息,这是我想要避免的.我已经尝试从服务器返回任何内容或"0" - 没有返回任何导致资源实例被完全保留并且返回"0"导致与返回"1"相同.
Angular要求什么响应才能完全删除此Resource实例,以便我的模板正确呈现?
我正在教自己C和有趣的我认为写一个小的Web框架会很酷.我目前正在处理的代码是注册路由/处理程序.
我遇到了一个分段错误malloc,但奇怪的是只在第四次被调用时.我在代码中标记了发生分段错误的点.除了用printfs和putss 包装代码区域之外,我不确定如何调试它.我尝试使用valgrind来调试它,但是当我运行valgrind时,实际上并没有发生分段错误.Valgrind 确实告诉我,同样存在内存泄漏malloc.显然我在那里做错了,但我不知道是什么.
destroy_routes仅在子进程终止之前调用FYI .
struct route {
char *path;
enum method method;
int(*handler)(struct request *, int sock);
struct route *next;
};
static struct route *routes;
void
register_route(char *path, enum method method,
int(*handler)(struct request *, int))
{
struct route *route;
if (routes == NULL)
routes = route = malloc(sizeof(struct route));
else {
route = routes;
while (route->next)
route = route->next;
route->next = malloc(sizeof(struct route));
route = route->next;
}
route->path …Run Code Online (Sandbox Code Playgroud)