小编Kev*_*ker的帖子

显示CGRect边框的简单方法?

我正在尝试找到一种方法来显示CGRect我的iOS程序中某些s 的边框以进行调试.有一个相当简单的方法来做到这一点?我只需要看看程序在哪里创建这些矩形,所以我可以追踪一些奇怪的触摸行为(或缺乏它).

我的班级init方法:

// Initialize with points and a line number, then draw a rectangle 
// in the shape of the line
-(id)initWithPoint:(CGPoint)sP :(int)w :(int)h :(int)lN :(int)t {
    if ((self = [super init])) {
        startP = sP;
        lineNum = lN;
        width = w;
        height = h;
        int type = t;
        self.gameObjectType = kPathType;

        // Draw the path sprite
        path = [CCSprite spriteWithFile: @"line.png" rect:CGRectMake(0, 0, 5, height)];
        ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
        [path.texture setTexParameters:&params];

        if(type == 1) …
Run Code Online (Sandbox Code Playgroud)

cocos2d-iphone ios cgrect

2
推荐指数
1
解决办法
6980
查看次数

Clojure:map函数没有返回我可以评估的东西

我正在写一个小小的"秘密圣诞老人"程序,让我的手弄脏了Clojure,而且我对我的输出感到磕磕绊绊.

该程序采用一组集(圣诞老人),将他们的电子邮件提取到另一个列表,然后随机将收件人分配给圣诞老人.我想我已经得到了它,但当我尝试输出我的结果时map,我得到了#<Fn@dc32d15 clojure.core/map$fn__4549>,

(ns secret-santas-helper.core
  (:require [clojure.pprint :as pprint])
  (:gen-class))

(def santas [{:name "Foo" :email "foo@gmail.com"}
             {:name "Bar" :email "bar@gmail.com"}
             {:name "Baz" :email "baz@gmail.com"}])

(defn pluck
  "Pull out the value of a given key from a seq"
  [arr k]
  (map #(get % k) arr))

(defn find-first
  "Find the first matching value"
  [f coll]
  (first (filter f coll)))

(defn assign-santas
  "Iterate over a list of santas and assign a recipient"
  [recipients santas]
  (let [r (atom recipients)])
  (map …
Run Code Online (Sandbox Code Playgroud)

dictionary clojure

2
推荐指数
1
解决办法
93
查看次数

Clojurescript:合并两个地图会生成两个地图的列表,而不是一个包含新值的地图

试图写入一个函数,它接受一个url,api-key和的查询参数的可选地图.

如果没有查询参数,此代码有效:

(defn get-api
  [url api-key & query]
  (let [api-map {:apikey api-key}]
    (let [params (if query
                  (merge query api-map)
                  api-map)]
      (.log js/console (pr-str params))
      (GET url {:params params}))))

(get-api "some/url" "some-key") ;works just fine
(get-api "some/url" "some-key" {:id 123}) ;ends up producing ({:apikey "some-key"} {:id 123})
Run Code Online (Sandbox Code Playgroud)

生成具有我需要的值的单个地图我错过了什么?

clojure clojurescript

2
推荐指数
1
解决办法
91
查看次数

Javascript:根据对象上嵌套数组中的值查找数组中对象的索引

我有一个看起来像这样的数组:

[{
    name: 'foobar',
    fields: [{
        label: 'argle'
    },{
        label: 'bargle'
    }]
},{
    name: 'baz',
    fields: [{
        label: 'rar'
    },{
        label: 'hoogah'
    }]
}]
Run Code Online (Sandbox Code Playgroud)

我正在寻找具有匹配的对象的索引,因此我可以更新该特定字段.有没有最佳方法来实现这一目标?我知道不会让我自己,但我正在努力与逻辑.fieldlabel === 'rar'indexOf

javascript arrays

2
推荐指数
1
解决办法
54
查看次数

复杂的选择集,Rails方式?

假设你有一个"作者"对象,它有几本书,你想要在模型中构建一些方法.您的基本设置如下所示:

class Author
  def book_count(fiction = nil, genre = nil, published = nil)
  end
end
Run Code Online (Sandbox Code Playgroud)

对于每个参数,您有几种方法可以操作:

fiction = true #retrieve all fiction books
fiction = false #retrieve all nonfiction
fiction = nil #retrieve books, not accounting for type

genre = nil #retrieve books, not accounting for genre
genre = some_num #retrieve books with a specific genre id

published = true #retrieve all published
published = false #retrieve all unpublished
published = nil #retrieve books, not accounting for published
Run Code Online (Sandbox Code Playgroud)

现在,我为其中的一些写了一个基本的select语句,类似于:

if …
Run Code Online (Sandbox Code Playgroud)

ruby activerecord select ruby-on-rails

1
推荐指数
1
解决办法
168
查看次数

Ruby:生成添加到另一个数字的随机整数

我正在尝试随机生成两个整数,这些整数加起来先前选择的整数.

例如,如果我有一个先前选择的值12,我需要一个可以生成的方法[6,6],或者[11,1]等等.

ruby random

1
推荐指数
1
解决办法
527
查看次数

基于Rails的javascript应用程序的安全性:如何在呈现的javascript中验证用户的权限?

如果这是这个问题的错误堆栈,请道歉.如果是这样,请指引我到正确的网站.

我有一个Rails应用程序,其中的用户可以是三种角色之一的成员:user,admin,或system.我的rails应用程序基本上用作骨干应用程序的JSON后端.所有客户端繁重的工作都是通过coffeescript文件完成的,这些文件在资产管道中处理.

现在,我通过我在application.html.slim关卡中创建的对象将一些用户属性传递到javascript中.看起来像这样的东西:

APP.currentUser = 
  name: "#{@current_user.name}"
  role: "#{@current_user.role}"
Run Code Online (Sandbox Code Playgroud)

在我的主干应用程序的几个地方洒满了这样的调用:

if APP.currentUser.role is 'admin'...
Run Code Online (Sandbox Code Playgroud)

这似乎是非常不安全的,因为任何人的知识可以打开一个开发者控制台中,修改的实例App.currentUseradmin,然后访问前端的管理功能.现在,rails侧面足够聪明,可以检查并确保@current_user在尝试这样做之前可以执行这些功能,但似乎应该有一种方法可以在前端阻止它,而不会将角色发布到javascript中.

我是否过于谨慎或遗失了什么?

javascript security ruby-on-rails coffeescript backbone.js

1
推荐指数
1
解决办法
178
查看次数

Clojurescript:如何有条件地更新哈希映射?

我试图绕过一些CLJS和Reagent,当我尝试将一个或另一个更新应用于原子时,我遇到了一个问题.

我有一个增量函数,incDieCount它增加地图中特定键的值.我试过写一个函数,它也应该减少一个键的值.如果值为0(它不会递减到该值以下),则它起作用,但不是将当前值递减1,而是始终将值设置为零.我错过了什么?

(defonce app-state
  (reagent/atom
   {:dice
    {:d4 0
     :d6 0
     :d8 0
     :d10 0
     :d12 0
     :d20 0
     :d100 0}}))

(defn incDieCount [die]
  #(swap! app-state update-in [:dice die] inc))

(defn decDieCount [die]
  (let [count (get-in app-state [:dice die])]
    (if (> 0 count)
      #(swap! app-state update-in [:dice die] dec)
      #(swap! app-state assoc-in [:dice die] 0))))


(defn diceEl [[die count]]
  ^{:key die} [:li
               (str (name die) ": " count)
               [:button {:on-click (incDieCount die)}
                "Add"]
               [:button {:on-click (decDieCount die)} …
Run Code Online (Sandbox Code Playgroud)

clojure clojurescript reagent

1
推荐指数
1
解决办法
280
查看次数

Javascript:使用变量引用数组,而不是复制它

假设我有两个javascript数组,如下所示:

arrA = [1,2,3]
arrB = [4,5,6]
Run Code Online (Sandbox Code Playgroud)

有没有办法可以用不同的变量名称引用它们然后再路上?如果我这样做:

arrC = arrA
arrD = arrB
Run Code Online (Sandbox Code Playgroud)

它创建初始数组的副本,而不是指向它们的指针/引用.所以,如果我搞砸了价值arrC,arrA就不会更新.有办法解决这个问题吗?

谢谢.

javascript arrays pointers reference

0
推荐指数
1
解决办法
124
查看次数

Require.js&Marionette:定义包括扩展类时

我正在使用Require.js,Backbone和Marionette开发一个项目define/function,我文件顶部的调用变得有点荒谬.我想找到一种方法将"包含"移出最顶层的define块,并进入extend相关的位置.

所以我的结构大致如下:

define(['underscore','jquery','handlebars','someTemplate','someModel',etc...], function(_,$,Handlebars,template,model,etc...){
  var someView = Backbone.Marionette.ItemView.extend({
    // code here
  });
  return someView;
});
Run Code Online (Sandbox Code Playgroud)

因此,当我向文件添加更多视图时,该define列表实际上非常长.我尝试过这样的事情:

var someView = define(['someTemplate','someModel'], function(template, model){
  return Backbone.Marionette.ItemView.extend({
    // code here
  });
]);
Run Code Online (Sandbox Code Playgroud)

但是someView当我稍后调用它时,它是未定义的.我做错了,还是不可能?

requirejs backbone.js marionette

0
推荐指数
1
解决办法
636
查看次数