我正在运行以下脚本:
cause = c(1, 1, 1, 1, 1, 2, 1, 2, 2, 2, 2);
time = c(1, 1, 2, 3, 3, 2, 2, 1, 1, 2, 2);
table(cause, time)
Run Code Online (Sandbox Code Playgroud)
我得到以下内容:
time
cause 1 2 3
1 2 2 2
2 2 3 0
Run Code Online (Sandbox Code Playgroud)
我想要的是这个:
time
cause 1 2 3
Maltreat 2 2 2
Non-Maltr 2 3 0
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是:如何重命名R中表的行?
同样,你如何重命名该表的列?
当鼠标悬停在表格中的一行上时,我想更改背景和文字颜色:
tr {
background-color:#FFF;
color:#000;
}
tr:hover {
background-color:#000;
color:#FFF;
}
Run Code Online (Sandbox Code Playgroud)
如果tr元素中没有任何链接,则此方法有效,但是当存在时,链接颜色保持黑色(因为a { color: #000; }?).如何在CSS中指定tr元素中的链接应该在鼠标悬停在tr?上时改变颜色?
我不得不将".strftime("%H:%M")"附加到我在Rails项目中显示时间的任何内容.我有每个Concert对象的开始时间和结束时间,因此每当我想显示那些时间时,我必须附加".strftime("%H:%M")".
请注意,我不是要求更改日期格式.日期看起来很好(如MM/DD/YYYY).
什么是最好的解决方法?有没有办法设置默认时间格式?
(我很确定这只是一个Ruby的东西,但我是新手,所以我不确定.)
我想以编程方式将VideoView添加到LinearLayout.LinearLayout的id为"main".
参考这个问题视频流和Android,我能够让视频显示和播放,但如果我想动态创建一个新的VideoView并将其添加到布局怎么办?
这是我试图以编程方式"复制"的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/main"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent">
<VideoView android:id="@+id/your_video_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
以下是我尝试以编程方式完成相同操作的方法:
VideoView videoView = new VideoView(this);
LinearLayout layout = (LinearLayout)findViewById(R.id.main);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layout.addView(videoView, params);
Run Code Online (Sandbox Code Playgroud)
问题是视频根本没有出现!使用XML声明的VideoView,一切正常,但从程序上来说,它根本不起作用.
为了清楚起见,我不希望在编程时以XML文件中定义VideoView.
在实际使用之前,我是否必须检查$_SERVER变量是否有密钥?REQUEST_METHOD$_SERVER['REQUEST_METHOD']
也就是说,总是检查一个键是否存在于数组变量中是否过于防守$_SERVER?
我正在尝试检查应用程序内部存储中的子目录中是否存在zip:
File file = this.getApplicationContext().getFileStreamPath(this.getFilesDir().getAbsolutePath() + "/thesubdirectory/the.zip";
if(file.exists()) {
Log.e(this.class.getName(), "file exists");
}
Run Code Online (Sandbox Code Playgroud)
这是扔了一个java.lang.IllegalArgumentException: File /data/data/my.package.name/files/thesubdirectory/the.zip contains a path separator.
为什么会这样?我认为这是你应该检查文件是否存在的方式.
在onPictureTaken,我想做以下事情:
Bitmap decodedPicture = BitmapFactory.decodeByteArray(data, 0, data.length);
Matrix matrix = new Matrix();
matrix.preScale(-1.0f, 1.0f);
Bitmap picture = Bitmap.createBitmap(decodedPicture, 0, 0, decodedPicture.getWidth(), decodedPicture.getHeight(), matrix, false);
View v1 = mainLayout.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap screenshot = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
Bitmap scaledPicture = Bitmap.createScaledBitmap(picture, screenshot.getWidth(), screenshot.getHeight(), true);
Bitmap compos = Bitmap.createBitmap(scaledPicture.getWidth(), scaledPicture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(compos);
canvas.drawBitmap(scaledPicture, new Matrix(), null);
canvas.drawBitmap(screenshot, new Matrix(), null);
MediaStore.Images.Media.insertImage(getContentResolver(), compos, "name" , "description");
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
Run Code Online (Sandbox Code Playgroud)
我唯一的要求是我想要保存高质量的照片......似乎我可能要牺牲它.
在我的Nexus 4和更新的设备上,此代码运行正常且符合预期.但是在内存较少的旧设备上,我的内存不足了!:(
如何在不遇到内存限制的情况下进行相同的图像处理?我不打算在屏幕上显示这些图像,因此与缩小图像有关的解决方案并不适用于此...
我按照本教程:http://android-er.blogspot.com/2013/03/embed-google-map-in-webview.html
我试图在WebView中使用Google Map,但它无法获取我当前的位置.我在WebView上启用了JavaScript.我还需要启用什么?
有谁知道为什么会这样?它不应该促使我使用我当前的位置?
请注意,我对使用MapView作为替代方案不感兴趣.我想知道我需要在WebView上设置什么,或者可能在设备的位置服务上?
google-maps android-maps android-4.0-ice-cream-sandwich google-places-api google-places
你能追加一个base从标签到文档的头部div在body使用JavaScript文件?我的意思是,这样做有什么缺点?我担心的是,我会遇到某种竞争状况,因为该base标签被理解为存在于标签中,head因此如果页面已经被渲染,它将不会受到尊重。我还没有遇到这个问题,但是我想知道是否应该关注这个问题。
要清楚,我知道如何通过JavaScript做到这一点。我的问题是,如果在页面加载/渲染后将标签附加到DOM,该标签是否会受到尊重/兑现?
我的代码是HTML片段,可能会出现在中body,但是我需要设置base标签,因为我的资产是相对引用的。让我们假设我无法更改此设置(因为我无法更改,至少不是立即更改)。您还可以假设设置base不会破坏任何不是我的HTML片段的东西,并且base永远没有其他标签。
我正在创建一个新表,需要使用基于用户帐户(超过几十万)的数据进行回填,并执行以下一次性佣金任务.
我决定要为每2000个用户创建一个大的INSERT字符串并执行该查询.
这是代码大致的样子:
task :backfill_my_new_table => :environment do
inserts = []
User.find_each do |user|
tuple = # form the tuple based on user and user associations like (1, 'foo', 'bar', NULL)
inserts << tuple
end
# At this point, the inserts array is of size at least 20,000
conn = ActiveRecord::Base.connection
inserts.each_slice(2000) do |slice|
sql = "INSERT INTO my_new_table (ref_id, column_a, column_b, column_c) VALUES #{inserts.join(", ")}"
conn.execute(sql)
end
end
Run Code Online (Sandbox Code Playgroud)
所以我想知道,有更好的方法吗?我采取的方法有哪些缺点?我该怎样改进它?如果我没有对inserts数组进行切片并且只执行一个INSERT超过几十万个VALUES元组的单个怎么办?这种方法的缺点是什么?
谢谢!
postgresql ruby-on-rails query-optimization rails-activerecord
android ×3
html ×2
android-4.0-ice-cream-sandwich ×1
android-maps ×1
css ×1
google-maps ×1
javascript ×1
php ×1
postgresql ×1
r ×1
rename ×1
rows ×1