小编Pie*_*eau的帖子

UIImage:调整大小,然后裁剪

我一直在this this for for for for for for and and and while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while

我认为,在我的设计的概念阶段提前,从iPhone的相机或库中获取图像,将其缩小到指定高度,使用与Aspect Fill选项相当的功能将是一件小事. UIImageView(完全在代码中),然后裁掉任何不适合传递给CGRect的东西.

从相机或图书馆获取原始图像非常简单.我很惊讶其他两个步骤的难度.

附图显示了我想要实现的目标.有人请你好好握住我的手吗?到目前为止我发现的每个代码示例似乎都会破坏图像,颠倒过来,看起来像废话,画出界限,或者其他方法都不能正常工作.

iphone core-graphics image-processing ios

187
推荐指数
6
解决办法
12万
查看次数

Connect.js methodOverride有什么作用?

Connect.js 非常简洁的文档methodOverride

提供虚拟HTTP方法支持.

那是什么意思?在明显的谷歌搜索不到有帮助的.为什么methodOverride有用?

node.js connect.js

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

带有node-jwt-simple的本地护照

如何在本地身份验证后,将本地护照与JWT令牌结合使用?

我想使用node-jwt-simple并查看passport.js我不知道该怎么做.

var passport = require('passport')
  , LocalStrategy = require('passport-local').Strategy;

passport.use(new LocalStrategy(
  function(username, password, done) {
    User.findOne({ username: username }, function(err, user) {
      if (err) { return done(err); }
      if (!user) {
        return done(null, false, { message: 'Incorrect username.' });
      }
      if (!user.validPassword(password)) {
        return done(null, false, { message: 'Incorrect password.' });
      }
      return done(null, user);
    });
  }
));
Run Code Online (Sandbox Code Playgroud)

调用done()时是否可以返回令牌?像这样......(只是伪代码)

if(User.validCredentials(username, password)) {
  var token = jwt.encode({username: username}, tokenSecret);
  done(null, {token : token}); //is this possible? …
Run Code Online (Sandbox Code Playgroud)

authentication token node.js jwt passport.js

87
推荐指数
2
解决办法
4万
查看次数

如果32位整数溢出,我们可以使用40位结构而不是64位长结构吗?

例如,如果一个32位整数溢出,而不是升级intlong,如果我们需要一个仅在2 40之内的范围,我们可以使用一些40位类型,这样我们就可以节省24(64-40)位整数?

如果是这样,怎么样?

我必须处理数十亿和空间是一个更大的约束.

c c++ memory-management integer-overflow

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

Node.js的文件存储抽象模块?

在PHP中使用应用程序,我喜欢使用文件存储抽象层(例如Flysystem).这使得它琐碎到文件应该被保存到位置间切换(云存储,本地驱动器,ZIP,不管).

目前我开始使用Node.js,所以我想知道节点是否存在类似的模块?

搜索NPM站点给了我大量与文件系统相关的命中,但没有涉及这种抽象级别.

file-io node.js cloud-storage

14
推荐指数
4
解决办法
4232
查看次数

使用Usemin时如何向Concat选项添加分隔符

我正在使用Grunt-usemin.但是连接的JS没有用';'正确分隔.我怎么告诉usemin只为JS文件而不是CSS文件添加分隔符?

目前,我的usemin任务看起来像这样:

    useminPrepare: {
        options: {
            dest: '<%= config.dist %>'
        },
        html: '<%= config.app %>/index.html'
    },

    // Performs rewrites based on rev and the useminPrepare configuration
    usemin: {
        options: {
            assetsDirs: ['<%= config.dist %>', '<%= config.dist %>/images']
        },
        concat: {
            separator: ';'
        },
        html: ['<%= config.dist %>/{,*/}*.html'],
        css: ['<%= config.dist %>/styles/{,*/}*.css']
    },
Run Code Online (Sandbox Code Playgroud)

另一个用例是将每个连接模块包装在IIFE中,这需要这种配置,但只应该应用于*.js文件:

concat: {
    options: {
        banner: ';(function () {',
        separator: '})(); (function () {',
        footer: '})();'
    }
}
Run Code Online (Sandbox Code Playgroud)

group-concat gruntjs grunt-usemin

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

Node.js SSE res.write() 未在流中发送数据

我正在尝试在 NodeJs 中添加 SSE(服务器发送事件),但是当我使用res.write()数据发送响应时,数据没有被发送,而是只有在写入后res.end()所有数据才会同时发送。

我已经在 Github、StackOverflow 上找到了很多关于这个问题的帖子,并且到处都提到要在res.flush()every 之后使用res.write(),但这对我来说也不起作用,而且我也没有明确使用任何压缩模块。

服务器端代码

谁能告诉我有什么办法可以让这项工作成功吗?

const express = require('express')

const app = express()
app.use(express.static('public'))

app.get('/countdown', function(req, res) {
  res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive'
  })
  countdown(res, 10)
})

function countdown(res, count) {
  res.write("data: " + count + "\n\n")
  if (count)
    setTimeout(() => countdown(res, count-1), 1000)
  else
    res.end()
}

app.listen(3000, () => console.log('SSE app listening on port 3000!'))
Run Code Online (Sandbox Code Playgroud)

客户端代码

<html>
<head>
<script>
  if (!!window.EventSource) {
    var …
Run Code Online (Sandbox Code Playgroud)

node.js server-sent-events

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

WooCommerce - 数量变更时自动更新总价

我一直在寻找好几天,但我还没回答.基本上,我正在尝试用ajax调用替换woocommerce标准"更新购物车"按钮,这会在数量变化时自动更新订单总价.这是我的HTML

<div class="cart_item">
    <div class="product-thumbnail">
        <a href="http://example.com"><img width="90" height="90" src="path to thumbnail"/></a>
    </div>

    <div class="product-name">
        <a class="cart-page-product__title" href="http://example.com">Product1 name</a>
    </div>

    <div class="product-quantity">
        <div class="quantity">
            <input type="number" step="1"   name="cart[some_security_key][qty]" value="1" class="input-text qty text" size="4"/>
        </div>
    </div>

    <div class="product-subtotal"><span class="amount">2 000</span></div>
        <div class="product-remove">
            <a class="product-remove_link" href="http://example.com/?remove_item">&times;</a>
        </div>
</div>
<div class="cart_item">
    <div class="product-thumbnail">
        <a href="http://example.com"><img width="90" height="90" src="path to thumbnail"/></a>
    </div>

    <div class="product-name">
        <a class="cart-page-product__title" href="http://example.com">Product2 name</a>
    </div>

    <div class="product-quantity">
        <div class="quantity">
            <input type="number" step="1"   name="cart[some_security_key][qty]" value="1" class="input-text qty text" size="4"/>
        </div>
    </div> …
Run Code Online (Sandbox Code Playgroud)

php wordpress jquery woocommerce

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

使用Angular JS调用restful API时的跨域问题

我正在尝试访问一个安静的API.这给出了错误.如何克服这个跨域问题?

错误是 'Access-Control-Allow-Origin' header is present on the requested resource

function Hello($scope, $http) {

$http.get('http://api.worldweatheronline.com/free/v1/weather.ashx?q=London&format=json&num_of_days=5&key=atf6ya6bbz3v5u5q8um82pev').
    success(function(data) {
        alert("Success");
    }).
    error(function(data){
       alert("Error");
    });
}
Run Code Online (Sandbox Code Playgroud)

这是我的小提琴http://jsfiddle.net/U3pVM/2654/

angularjs

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

Symfony2 Doctrine从一个类别中获取随机产品

我有以下数据库方案:

table 'products'
id
category_id
Run Code Online (Sandbox Code Playgroud)

当然还有一个类别表,只有一个id.

数据看起来像这样:

Products
--------------------
| id | category_id |
--------------------
| 0  | 1           |
| 1  | 1           |
| 2  | 1           |
| 3  | 2           |
| 4  | 2           |
| 5  | 1           |
--------------------
Run Code Online (Sandbox Code Playgroud)

我想选择一个类别(例如类别1),因此我在product-repository类中选择该类别中的所有行:

return $this
    ->createQueryBuilder('u')
    ->andWhere('u.category = :category')
    ->setMaxResults(1)
    ->setParameter('category', $category->getId())
    ->getQuery()
    ->getSingleResult()
;
Run Code Online (Sandbox Code Playgroud)

我现在如何选择随机产品?另外:是否有可能通过关系来解决这个问题?

我在实体"类别"和"产品"之间有一个OneToMany关系,所以我也可以通过category-> getProducts()得到所有产品......

任何帮助都非常有用,谢谢

php entity doctrine relationships symfony

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

在请求中Symfony 2.3 locale中的翻译

如何更改Symfony 2.3中的语言环境?

我创建了这个控制器:

public function changelocaleAction($lang)
{
    $request = $this->get('request');
    $request->setLocale($lang);
    return $this->redirect($request->headers->get('referer'));
}
Run Code Online (Sandbox Code Playgroud)

刷新页面时不显示更改.为什么?

symfony symfony-2.3

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