小编Che*_*eng的帖子

在Windows中创建Zip文件并在Linux中提取Zip文件

我在Windows下创建了一个zip文件(连同目录),如下所示(代码摘自http://www.exampledepot.com/egs/java.util.zip/CreateZip.html):

package sandbox;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 *
 * @author yan-cheng.cheok
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // These are the files to include in the ZIP file
        String[] filenames = new String[]{"MyDirectory" + File.separator + "MyFile.txt"};

        // Create a buffer for reading the files
        byte[] buf = new byte[1024];

        try {
            // Create the …
Run Code Online (Sandbox Code Playgroud)

java

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

从C代码调用C++静态成员函数

我有一堆C代码.我无意将它们转换为C++代码.

现在,我想调用一些C++代码(我不介意修改C++代码,以便它们可以通过C代码调用).

class Utils {
public:
    static void fun();
}

class Utils2 {
public:
    static std::wstring fun();
}
Run Code Online (Sandbox Code Playgroud)

如果我倾向于使用以下语法调用它们,它们将不会编译(我使用的是VC++ 2008,扩展名为.c的C代码文件)

Utils::fun();
// Opps. How I can access std::wstring in C?
Utils2::fun();
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

c c++

7
推荐指数
2
解决办法
7230
查看次数

为什么将对象列表从一个活动传递到另一个活动是如此麻烦

我想知道,为什么谷歌很难将对象列表从1个活动传递到另一个活动,即使我的活动都在一个进程中?

他们为什么不能拥有类似的东西

intent.putExtra("histories", listOfHistoryObjects);
Run Code Online (Sandbox Code Playgroud)

它们是否过于设计?

android

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

如何平滑路径图的WPF线段

以下是Android代码.

path.moveTo(xx, yy);
for (...) {
    path.lineTo(xx, yy);
}
canvas.drawPath(this.path, paint);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

为了消除尖角,我正在使用

final CornerPathEffect cornerPathEffect = new CornerPathEffect(50);
paint.setPathEffect(cornerPathEffect);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

来到WPF时,我使用以下代码.

PathFigure pathFigure = new PathFigure();
pathFigure.StartPoint = new Point(xx, yy);
for (...) {
    LineSegment lineSegment = new LineSegment(new Point(xx, yy), true);
    lineSegment.IsSmoothJoin = true;
    pathFigure.Segments.Add(lineSegment);
}
PathGeometry pathGeometry = new PathGeometry(new PathFigure[] { pathFigure });
drawingContext.DrawGeometry(null, new Pen(Brushes.White, 3), pathGeometry);
Run Code Online (Sandbox Code Playgroud)

我得到以下效果.

在此输入图像描述

请注意,我避免使用PolyQuadraticBezierSegmentPolyBezierSegment.它往往变得不稳定.这意味着,每当我向线图添加新的传入点时,新添加的点将倾向于更改已在屏幕上绘制的旧路径.作为最终效果,您可以观察整个线图是否在颤抖

我可以在WPF中知道如何消除线段吗?虽然我已经习惯了lineSegment.IsSmoothJoin = true;,但我仍然可以看到尖角.我可以拥有与Android的CornerPathEffect相同的东西吗?

c# wpf android

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

正确使用scipy.signal.spectral.lombscargle的方法

我正在参考以下帖子:使用scipy.signal.spectral.lombscargle进行句点发现

我意识到某些情况下答案是正确的.

sin(x)的频率,即1 /(2*pi)

# imports the numerical array and scientific computing packages
import numpy as np
import scipy as sp
from scipy.signal import spectral

# generates 100 evenly spaced points between 1 and 1000
time = np.linspace(1, 1000, 100)

# computes the sine value of each of those points
mags = np.sin(time)

# scales the sine values so that the mean is 0 and the variance is 1 (the documentation specifies that this must be done)
scaled_mags = …
Run Code Online (Sandbox Code Playgroud)

python signal-processing numpy scientific-computing scipy

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

抛出IOException时是否需要使用HttpURLConnection的错误流

根据Oracle Java的技术指南,我们应该HttpURLConnectionIOException抛出时消耗错误流

http://docs.oracle.com/javase/6/docs/technotes/guides/net/http-keepalive.html

你能做些什么来帮助Keep-Alive?不要忽略响应主体而放弃连接.这样做可能会导致TCP连接空闲.当它们不再被引用时,需要进行垃圾收集.

如果getInputStream()成功返回,请读取整个响应正文.

从HttpURLConnection调用getInputStream()时,如果发生IOException,请捕获异常并调用getErrorStream()以获取响应主体(如果有).

即使您对响应内容本身不感兴趣,阅读响应正文也会清除连接.但是如果响应体很长并且在看到开头之后你对其余部分不感兴趣,你可以关闭InputStream.但是你需要意识到更多的数据可能会在路上.因此,可能无法清除连接以便重复使用.

这是符合上述建议的代码示例:

这是代码示例

try {
        URL a = new URL(args[0]);
        URLConnection urlc = a.openConnection();
        is = conn.getInputStream();
        int ret = 0;
        while ((ret = is.read(buf)) > 0) {
          processBuf(buf);
        }
        // close the inputstream
        is.close();
} catch (IOException e) {
        try {
                respCode = ((HttpURLConnection)conn).getResponseCode();
                es = ((HttpURLConnection)conn).getErrorStream();
                int ret = 0;
                // read the response body
                while ((ret = es.read(buf)) > 0) {
                        processBuf(buf);
                }
                // close the errorstream …
Run Code Online (Sandbox Code Playgroud)

android

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

清除JavaFX WebView中的会话/缓存/ cookie

我有一个Swing对话框,它使用JavaFX WebView显示来自Google服务器的oAuth 2.0 URL.

public class SimpleSwingBrowser extends JDialog {

    private final JFXPanel jfxPanel = new JFXPanel();
    private WebEngine engine;

    private final JPanel panel = new JPanel(new BorderLayout());

    public SimpleSwingBrowser() {
        super(MainFrame.getInstance(), JDialog.ModalityType.APPLICATION_MODAL);
        initComponents();
    }


    private void initComponents() {
        createScene();

        panel.add(jfxPanel, BorderLayout.CENTER);

        getContentPane().add(panel);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-460)/2, (screenSize.height-680)/2, 460, 680);
    }

    private void createScene() {

        Platform.runLater(new Runnable() {
            @Override 
            public void run() {

                final WebView view = new WebView();
                engine = view.getEngine();

                engine.titleProperty().addListener(new ChangeListener<String>() {
                    @Override
                    public void …
Run Code Online (Sandbox Code Playgroud)

java swing javafx webview oauth-2.0

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

什么是Firebase的等效HitBuilders.ScreenViewBuilder

以前,为了跟踪Google Analytics(分析)中的屏幕视图,我使用以下代码段。这是非常方便的,因为我需要不通过ActivityContext周围。要使用它,我只需要Utils.trackGAView("ShareDialogFragment");在代码中的任何位置调用即可。

谷歌分析

public static Tracker getTracker() {
    if (false == isGooglePlayServicesAvailable()) {
        return null;
    }

    if (tracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(JStockApplication.instance());
        tracker = analytics.newTracker(R.xml.app_tracker);
    }
    return tracker;
}

public static void trackGAView(String view) {
    Tracker tracker = Utils.getTracker();
    if (tracker == null) {
        return;
    }
    tracker.setScreenName(view);
    tracker.send(new HitBuilders.ScreenViewBuilder().build());
}
Run Code Online (Sandbox Code Playgroud)

然而,在火力地堡,它是不是真的那么方便易,因为它需要一个Activity- https://firebase.google.com/docs/analytics/screenviews

并不是代码中的每个地方都可以访问该Activity对象。

火力基地

mFirebaseAnalytics.setCurrentScreen(activity, screenName, null /* class override */);
Run Code Online (Sandbox Code Playgroud)

是否有什么好的技术可以在Firebase中跟踪屏幕视图而无需四处走动Activity

android google-analytics firebase firebase-analytics

7
推荐指数
0
解决办法
427
查看次数

如何拥有没有破折号的models.UUIDField字段

我试图models.UUIDField通过使用default=uuid.uuid4().hex(而不是default=uuid.uuid4())

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    api_key = models.UUIDField(default=uuid.uuid4().hex, editable=False, unique=True)
    subscription = models.IntegerField(
        choices=[(s.value, s.name) for s in Subscription],
        null=False,
        blank=False
    )

    def __str__(self):
        return str(self.api_key)
Run Code Online (Sandbox Code Playgroud)

但是,结果仍然带有破折号。

django=# select * from users_profile;
 id |               api_key                | secret_key | subscription | user_id
----+--------------------------------------+------------+--------------+---------
  1 | 9da3546c-660c-46c6-adc4-6a13e6ee202b |            |            0 |       1
  2 | 9cbc3a68-7f50-4b18-9e61-7b009f22a0e8 |            |            0 |       2
(2 rows)
Run Code Online (Sandbox Code Playgroud)

我可以知道如何在没有破折号的情况下使用 models.UUIDField 字段吗?. 我想在没有破折号的情况下存储在数据库中,并在没有破折号的情况下使用它。

python django

7
推荐指数
2
解决办法
8154
查看次数

在Foreground服务中运行网络代码后,仍然收到“网络使用率过高(背景)”警告

通过引用正确的方式来解决和解决“网络使用过多(背景)”

经过几个月的调试,我们现在可以在Foreground服务中运行所有与网络相关的代码。

但是,我们仍然在Android Vital中收到“网络使用率过高(背景)”警告。

在此处输入图片说明

执行前台服务代码时,通知UI始终会显示在状态栏区域中。

在此处输入图片说明

当我们“退出”我们的应用程序时,我们使用来启动前台服务WorkManagerWorkManager启动前台服务后,会立即返回。

public class SyncWorker extends Worker {
    @NonNull
    @Override
    public Result doWork() {
        final Intent intent = new Intent(WeNoteApplication.instance(), SyncForegroundIntentService.class);

        ContextCompat.startForegroundService(
                WeNoteApplication.instance(),
                intent
        );

        return Result.success();
    }
}

public class SyncForegroundIntentService extends IntentService {
    private static final String TAG = "com.yocto.wenote.sync.SyncIntentService";

    public SyncForegroundIntentService() {
        super(TAG);
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {

        final Context context = WeNoteApplication.instance();

        NotificationCompat.Builder builder = new NotificationCompat.Builder(...

        startForeground(SYNC_FOREGROUND_INTENT_SERVICE_ID, builder.build());

        // Perform networking operation within …
Run Code Online (Sandbox Code Playgroud)

android

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