问题列表 - 第155505页

Rails:控制器中的JSON.pretty_generate(obj)不会产生漂亮的输出

我需要一个漂亮的JSON输出,用于rails控制器中的activerecord对象.基于jpatokal 对这个问题的回答,我尝试了以下方法:

respond_to do |format|
  format.json { render :json => JSON.pretty_generate(record) }
end 
Run Code Online (Sandbox Code Playgroud)

哪里

record 
Run Code Online (Sandbox Code Playgroud)

是一个活跃的记录对象.它不会产生美化输出.但是,当我尝试使用相同的代码输出哈希时,即,

respond_to do |format|
  format.json { render :json => JSON.pretty_generate({"abc" => "1", "def" => "2"}) }
end 
Run Code Online (Sandbox Code Playgroud)

它确实产生了一个美化输出(所以pretty_generate正在工作,我的浏览器也是如此).

如何使用pretty_generate生成activerecord对象的漂亮输出?

json ruby-on-rails ruby-on-rails-3.2

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

批处理或 PowerShell 命令以获取 Windows 中所有打开的应用程序的名称

我们有一个命令行实用程序,可以在服务器上打开 MS Office 文档并将它们转换为 PDF。对于其中包含宏的 Office 文档,将弹出安全警告消息,并且在有人启用宏之前,该实用程序不会继续完成工作。

例如,Visio 文件的警告消息对话框的标题为“Microsoft Visio 安全通知”。我们需要点击启用按钮。

此标题显示在 Windows 任务管理器的应用程序窗格中,但不在进程列表中。

我想编写一个实用程序来在发生这种情况时通知我。

您能否让我知道可以使用哪些批处理或 PowerShell 命令根据名称读取/搜索任务列表(即,获取 Windows 任务管理器的应用程序窗格中显示的所有应用程序名称)。

我试过 tasklist 和 get-process。它们提供有关进程的信息,但不提供应用程序窗口标题的详细信息。

请您分享一种获取应用程序窗口名称列表的方法或一种检查是否有通过脚本打开的安全警告的方法。

powershell batch-file taskmanager ms-office

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

Ruby中有多少个星期一在一段时间内

我有两个DateTime对象(date0date1).

我想知道星期一之间有多少个星期一[date0..date1]

在Ruby中执行此操作的最佳方法是什么?

ruby

2
推荐指数
3
解决办法
270
查看次数

Marching Cubes实现 - 网格中缺少三角形

我目前正致力于通过在OpenGL中渲染样本数据集来理解和实现使用C++的Marching Cubes算法.

我遇到了一个问题,我渲染的网格缺少三角形.我看到几乎一半的三角形丢失,可以在下面看到.

填写三角形和创建四边形是解决问题的正确方法,还是我错过了一些明显的东西?

我使用的边缘交叉表来自以下链接:http: //paulbourke.net/geometry/polygonise/

我没有使用12位条目的边标志数组,而是有12个if语句(其中显示了2个).我使用索引进入3D数组,根据边值确定x,y,z的值(0-11)

    if ((edge.point1 == 0 && edge.point2 == 1) ||
        (edge.point1 == 1 && edge.point2 == 0))
    {
        p1.x = x;   p1.y = y; p1.z = z;
        p2.x = x+1; p2.y = y; p2.z = z;
    }
    else if ((edge.point1 == 1 && edge.point2 == 2) ||
             (edge.point1 == 2 && edge.point2 == 1))
    {
        p1.x = x+1; p1.y = y;   p1.z = z;
        p2.x = x+1; p2.y = y+1; p2.z = …
Run Code Online (Sandbox Code Playgroud)

c++ opengl 3d marching-cubes

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

格式'%d'需要类型为'int'的参数,但参数2的类型为'int*'

我正在使用Linux,当我尝试使用此代码显示时:

#include <stdio.h>
#include <math.h>

int main()
{
    int a,b,c;
    int result;

    printf( "How Many Times Would You Like to Add: ");
    scanf( "%d", &a );
    //getchar();

    printf( "What Number Would You Like to Add: ");
    scanf( "%d", &b );
    //getchar();

    printf( "What Number Would You Like to Add to It?: ");
    scanf( "%d", &c );
    //getchar();

    for( int $i = 0; $i < a; $i++ )
    {
        result = b + c;
        printf( "%d", &result );
        printf( "\n" ); …
Run Code Online (Sandbox Code Playgroud)

c printf

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

Sprite Kit - 将对象移动到触摸位置

我的场景中有一个物体.当我触摸屏幕时,我希望对象的y位置成为我触摸的y位置.为此,我有以下代码:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    SKNode *player = [self childNodeWithName:@"player"];

    UITouch *touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];
    player.position = CGPointMake(player.position.x, positionInScene.y);
}
Run Code Online (Sandbox Code Playgroud)

它适用于此代码,但如何让对象以稳定的速度移动到触摸位置?因此,不是跳到触摸y位置,而是以预定义的速度移动到它.

objective-c ios sprite-kit

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

For循环不会在strlen上停止

我最大的问题是这一行:

for(i = 0; i <= strlen(enc); i ++) - >

函数decifrar的第7行: 它使用memset来保持循环,用于清除内存(它甚至比字符串长度还要大)

请注意,如果我使用该行中字符串的实际长度,代码确实有效(即用60替换strlen(enc))

void decipher(int k, char *enc){
     char alfa[]="9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA";
     char *pch;
     int i;
     for(i=0;i<=strlen(enc);i++){
        pch=strchr(alfa, enc[i]);
        if (pch) enc[i] = *(pch + k),enc[i]=tolower(enc[i]);
     }
     printf("%s",enc);
}
int main(){
    int keys[6]={1,4,15,24,12,20},i;
    char *txt="rfgr r hz grkgb fvzcyrf dhr cergraqr fre grfgnqb ab cebtenzn";
    char *txttemp=malloc(sizeof(char)*1024);

    for(i=0;i<6;i++){
        printf("\n\n\t Attempt number: %d\n\n",i+1);
        memset(txttemp,'\0',sizeof(char)*strlen(txt)+30);
        memcpy(txttemp, txt, strlen(txt));
        decipher(keys[i],txttemp);
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我错过了什么意思?strlen的用法是错误的吗?

c string for-loop

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

用imageview线性布局覆盖textview

我有一些线性布局相互叠放,中间的一个有imageview。我正在尝试在中间的imageview顶部获取textview,但是遇到了麻烦。我尝试了相对布局,但是它弄乱了我所有其他布局。有什么简单的解决方案吗?编辑----

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:orientation="horizontal"
    android:paddingLeft="50dp"
    android:paddingRight="50dp" >

    <ImageButton
        android:id="@+id/btnBck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@null"
        android:src="@drawable/ic_launcher" />

    <ImageButton
        android:id="@+id/btnHome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@null"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="6"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/picPreview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000"
        android:contentDescription="@string/imageDesc"
        android:src="@null" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:orientation="horizontal"
    android:paddingLeft="50dp"
    android:paddingRight="50dp" >

    <ImageButton
        android:id="@+id/btnAccept"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@null"
        android:src="@drawable/ic_launcher" />

    <ImageButton
        android:id="@+id/btnDecline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@null"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我正在尝试使文本视图位于id / picPreview图像视图之上

java eclipse android textview imageview

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

本地处理路由的Javascript框架(改变状态)

在使用meteor之后,我意识到meteor对路由处理没有原生支持.所以我一直在环顾四周,现在想知道什么是处理路由的完整堆栈JS框架.

基本上具有类似于Meteor的功能,但能够本地处理路由.构建一个页面应用程序,实质上在URL更改时更改其状态.

有利弊(最积极开发)等等.

javascript frameworks routes meteor

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

预定义的Meteor登录电​​子邮件域

我想创建一个Meteor应用程序,用户只能在他们的电子邮件以@ mydomain.com结尾时创建一个帐户.

最后,他们实际上只需输入用户名而不是@mydomain.com部分.

因此,create user字段如下所示:

Name:       __________
eMail:      __________@mydomain.com
Password:   __________
Renter:     __________
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

javascript accounts meteor

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