小编mr-*_*-sk的帖子

插入OSX,我的功能没有被调用

所以,我正在搞乱OSX上的一些插入代码(gcc 4.2.1),我试图让以下内容工作:

当我使用DYLD_INSERT_LIBRARIES = my.dylib调用./login时,它应该覆盖默认的登录实现并使用我的自定义实现.虽然这是一个人为的例子,但它只是为了帮助我理解这一点.

我的来源:

cat libinterposers.c

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include "login.h"

typedef struct interpose_s
{
  void *new_func;
  void *orig_func;
} interpose_t;

int my_open(const char *, int, mode_t);
int my_close(int);
int my_login();


static const interpose_t interposers[] __attribute__ ((section("__DATA, __interpose"))) = 
{
     { (void *)my_open,  (void *)open  },
     { (void *)my_close, (void *)close },
     { (void *)my_login, (void *)login },
};

int my_login()
{
  printf("--> my_login()\n");
  return 1;
}

int my_open(const char *path, int flags, mode_t mode) …
Run Code Online (Sandbox Code Playgroud)

c macos interposing

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

使UIImage / UIScrollView的区域“可单击”

所以我有两个问题要解决:

  1. 检测UIImageView中某个区域的单击。
  2. 检测到UIScrollView中某个区域的单击。

我正在考虑两者,因为我有来自客户端的x / y坐标,所以我将以编程方式实例化一个UIButton(自定义/透明)并将其放在UIImageView和UIScrollViews的所需区域上。

当用户选择按钮时,我还会触发一个事件。我正在考虑提供标签并使用像

- (IBAction) btnPress:(id)sender
Run Code Online (Sandbox Code Playgroud)

这样我就可以查询发件人

 [sender tag]
Run Code Online (Sandbox Code Playgroud)

然后根据标签做出决定。每个按钮将具有唯一的ID。我的问题是:

  1. 这是一个好方法吗?有什么会更好?
  2. 我知道如何在IB中完成所有这些操作,但不是以编程方式完成。我的印象是,连接(对于IBActions)仅在IB中进行,因此如何将按钮连接到事件中的所有代码(我将立即开始谷歌搜索)。

TIA。

iphone uiscrollview uiimageview ipad

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

THREE.js - 无法读取未定义的属性'lib'(THREE.ShaderUtils.lib ["normal"])

我正在完成Oreilly在WebGL入门书中找到的练习.

以下行导致运行时错误.我用Google搜索,没有看到其他人有问题,所以我做错了什么?

var specularMap= THREE.ImageUtils.loadTexture("WebGLBook/images/earth_specular_2048.jpg");

var shader   = THREE.ShaderUtils.lib[ "normal" ]; <-- fails
var uniforms = THREE.UniformsUtils.clone(shader.uniforms);

uniforms['tNormal'].texture   = normalMap; 
uniforms['tDiffuse'].texture  = surfaceMap;
Run Code Online (Sandbox Code Playgroud)

注意到的行失败,出现以下错误:

Uncaught TypeError: Cannot read property 'lib' of undefined solar-system-spec-map.html:60
Earth.createGlobe solar-system-spec-map.html:60
Earth.init solar-system-spec-map.html:51
EarthApp.init solar-system-spec-map.html:33
(anonymous function) solar-system-spec-map.html:93
deferred.resolveWith jquery-1.6.4.js:1016
jQuery.extend.ready jquery-1.6.4.js:437
DOMContentLoaded
Run Code Online (Sandbox Code Playgroud)

同样奇怪的是,"ShaderUtils"没有列在THREE.js文档中...... http://mrdoob.github.com/three.js/docs/55/

这是怎么回事?!

javascript webgl three.js

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

使用 github 配置 EMR 笔记本

我正在运行一个 EMR 集群,并且正在尝试将笔记本链接到 github。

我有:

  • 添加了对 EMR 角色的 AWS 秘密访问(这是我的第一个错误)
  • 向所有 EMR 安全组添加了出站 HTTPS/443

尝试使用我的用户/密码密钥将笔记本链接到私人存储库,但出现以下错误:

Unable to reach repository https://github.com/<my repo>. Ensure network and security groups have valid configurations. Ensure that the repository information provided is correct.
Run Code Online (Sandbox Code Playgroud)

我在文档中看到它谈到了 NAT 和 VPG 选项,而我没有这两个选项。有这个必要吗?这些文档对细节/配置的描述非常简单。

https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-management-notebooks-git-considerations.html

任何帮助表示赞赏。

amazon-ec2 amazon-web-services amazon-emr amazon-vpc jupyter-notebook

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

访问以整数值开头的stdClass变量名

可能重复:
如何访问此对象属性?

请求中返回的数据是(JSON):

stdClass Object
(
[USD] => stdClass Object
    (
        [7d] => 23.3414
Run Code Online (Sandbox Code Playgroud)

我打电话给:

json_decode(...);
Run Code Online (Sandbox Code Playgroud)

并尝试通过以下方式访问它:

echo $json->USD->7d;
Run Code Online (Sandbox Code Playgroud)

但是失败了,因为变量名不能以整数开头.PHP中是否有任何语法可以访问它?

否则我会通过这样做解决这个问题:

$set = (array) $json->USD;
echo $set['7d'];
Run Code Online (Sandbox Code Playgroud)

php arrays json

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

无法构建zpipe.c(Zlib示例程序)

我正在尝试构建zpipe.c.我通过configure安装了zlib 1.2.5; 使; make install.我已将zpipe.c文件移动到实际的zlib-1.2.5目录中,其中包含zlib.h头文件.

这是我尝试构建时获得的:

[sk@lldma zlib-1.2.5]$ gcc zpipe.c 
/tmp/ccZ2OBz0.o: In function `def':
zpipe.c:(.text+0x3c): undefined reference to `deflateInit_'    
zpipe.c:(.text+0x8f): undefined reference to `deflateEnd'
zpipe.c:(.text+0xe2): undefined reference to `deflate'
zpipe.c:(.text+0x163): undefined reference to `deflateEnd'
zpipe.c:(.text+0x1df): undefined reference to `deflateEnd'
/tmp/ccZ2OBz0.o: In function `inf':
zpipe.c:(.text+0x22d): undefined reference to `inflateInit_'
zpipe.c:(.text+0x280): undefined reference to `inflateEnd'
zpipe.c:(.text+0x2c1): undefined reference to `inflate'
zpipe.c:(.text+0x312): undefined reference to `inflateEnd'
zpipe.c:(.text+0x36e): undefined reference to `inflateEnd'
zpipe.c:(.text+0x398): undefined reference to `inflateEnd'
Run Code Online (Sandbox Code Playgroud)

自述文件没有说明在Linux上构建的任何具体内容,我看到deflate.h和其他.h文件都位于目录中......

zpipe.c的源代码如下:http://www.zlib.net/zpipe.c

有任何想法吗?TIA

[sk@lldma zlib-1.2.5]$ …
Run Code Online (Sandbox Code Playgroud)

c linux compression gcc zlib

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

从Magento中提取国家/地区名称(或缩写)

我正在尝试将国家名称命名为"United States"(或缩写为"USA"/"US").我在下面尝试了很多变化:

echo Mage::getSingleton('customer/session')->getCustomer()->getCountry();
$countryName = Mage::getModel('directory/country')->load(Mage::getSingleton('customer/session')->getCustomer()->getCountry())->getName();
error_log("countryName = $countryName");
Run Code Online (Sandbox Code Playgroud)

第一个电话"似乎"起作用,因为我得到了6回(美国).但在那之后,我无法找到如何将其映射到正确的名称或slug.

我已经看过程序员获取所有国家名称和id的列表的帖子,但我不想迭代所有组合来查找名称.

TIA!

编辑:根据clockworkgeeks的建议,我试过:

$customer = Mage::getSingleton('customer/session')->getCustomer();
error_log(print_r($customer, true));
$countryCode = $customer->getDefaultBillingAddress()->getCountry();
Run Code Online (Sandbox Code Playgroud)

但是,第3行无法调用getCountry().也许getDefaultBillingAddress()不会返回对象.错误信息:

PHP Fatal error:  Call to a member function getCountry() on a non-object in ...
Run Code Online (Sandbox Code Playgroud)

思考?$ customer对象正确返回,虽然CLASS是MYCLIENT_Customer_Model_Customer对象...也许它不会扩展正确的父对象以使其访问getCountry?

编辑:(解决方案):添加为答案.

php country magento

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

使用"$ gte"和"$ lte"时Pymongo返回错误

我试图从mongo中选择(使用pymongo),查询纪元时间戳.我的数据库中的一个样本(为了简洁起见):

{
    "_id": "",
    "tweet": {
        "iso_language_code": "en",
        "to_user_name": null,
        "timestamp": 1355325948,
        "created_at": "Wed, 12 Dec 2012 15:25:48 +0000"
    }
}
Run Code Online (Sandbox Code Playgroud)

以及代码和python控制台中的查询:

<console>
db.tweets.find({
    "tweet.timestamp":{'$gte':1355391000},
    "tweet.timestamp":{'$lte':1355414400}
})

<code>
cursor = db.tweets.find({"tweet.timestamp":{'$gte':startEpoch},
                         "tweet.timestamp":{'$lte':endEpoch}})
Run Code Online (Sandbox Code Playgroud)

哪个是 星期四,2012年12月13日09:30:00 GMT和星期四,2012年12月13日16:00:00 GMT.

它应该说,让我所有的推文gte这个int和lte这个其他int.但是,它会返回所有内容 - 它似乎根本不限制这些值.

例如,返回此条目,时间戳为:1355325948,即:Wed,12 Dec 2012 15:25:48 GMT

另外,我理解使用params列表查找(...)是一个隐含的AND.

天哪!

python datetime epoch mongodb pymongo

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

Python - 用很多参数调用popen

我试图用一个参数列表调用popen.

    execString = "java -jar {} {} {} {} {} {}".format(os.path.join(config.java_root,
                                                                   config.java_jar),
                                               self.canvasSize,
                                               self.flightId,
                                               self.domain,
                                               self.defPath,
                                               self.harPath)
    execStringList = execString.split()
    print execStringList
    subprocess.Popen([execStringList])
Run Code Online (Sandbox Code Playgroud)

execStringList是:

['java', '-jar', '/Users/me/Projects/reporting-test/build/clickunit-0.1.jar', '300x1050', '123', 'dev.me.net', '/Users/me/Projects/reporting-test/src/definitions/300x1050.yml', '/Users/me/Projects/reporting-test/out/01/15112']
Run Code Online (Sandbox Code Playgroud)

根据:Python OSError:[Errno 2]是正确的格式.但是,我收到以下错误:

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
AttributeError: 'list' object has no attribute 'rfind'
Run Code Online (Sandbox Code Playgroud)

如果我将execString视为字符串,我会得到一个不同的错误:

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
OSError: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)

即使我从终端运行此命令,它仍然有效.

$> java …
Run Code Online (Sandbox Code Playgroud)

python exec popen

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

使用 Boto3 访问 S3 中的嵌套存储桶

我知道我想要访问的存储桶的路径/bucket1/bucket2/etc/,但我不知道如何通过 boto3 访问它。

我可以从源开始枚举所有存储桶,但无法到达我想要的存储桶。

例如我可以这样做:

prod_bucket = s3.Bucket('prod')
Run Code Online (Sandbox Code Playgroud)

但我不能这样做:

prod_bucket = s3.Bucket('prod/prod2/')
Run Code Online (Sandbox Code Playgroud)

TIA

python amazon-s3 amazon-web-services boto3

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

Gradle"setup"任务(pre-build/compile/jar)

相对较新的java和gradle - 试图做"正确"的事情.在构建我的应用程序之前(我添加了gradle"应用程序"插件)我想设置一些环境和系统的东西 - 例如,我想创建log /目录和log.txt文件.

所以我做的事情如下:

task setup {
    println 'Setup task executing ...'

    File d = new File('log');
    d.mkdir();
    f = new File(d.getPath() + '/log.txt');
    f.createNewFile();
}
Run Code Online (Sandbox Code Playgroud)

哪个有效 - 但是在运行> gradle setup时我收到了一堆stdout警告

Setup task executing ...
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "f" on "task ':setup'", value: "log/log.txt".
:setup UP-TO-DATE
Run Code Online (Sandbox Code Playgroud)

所以有一个问题:利用Gradle执行设置/安装任务的正确方法是什么?(这应该只在部署应用程序时执行一次)

java groovy gradle

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

将 JSON 列表转换/处理为字典(或其他结构)

看起来很容易,但试图完成这件事却是脑抽筋。我有一个 API 请求,它接收以下内容作为响应。

[{u'text': u'test ASDF', u'ts': u'1453578721.000005', u'user': u'U0K7P5EBG', u'team': u'T0K7K1KEH', u'type': u'message', u'channel': u'D0K7P9MCJ'}]
Run Code Online (Sandbox Code Playgroud)

或者

[{u'type': u'hello'}]
Run Code Online (Sandbox Code Playgroud)

我想处理该响应,检查键、数据等。我尝试从列表中创建 dict(),尝试加载为 json(),但我似乎无法将数据转换为易于处理。

>>> a = [{u'text': u'test ASDF', u'ts': u'1453578721.000005', u'user': u'U0K7P5EBG', u'team': u'T0K7K1KEH', u'type': u'message', u'channel': u'D0K7P9MCJ'}]
>>> dict(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: dictionary update sequence element #0 has length 6; 2 is required
>>> a = [{u'text': u'test ASDF', u'ts': u'1453578721.000005', u'user': u'U0K7P5EBG', u'team': u'T0K7K1KEH', u'type': u'message', u'channel': u'D0K7P9MCJ'}]
>>> …
Run Code Online (Sandbox Code Playgroud)

python validation json dictionary data-cleaning

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