在下面的示例中:
package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
p := new(Proxy)
//host := "www.google.com" // WORKS AS EXPECTED
host := "www.apple.com" // GIVES AN ERROR
u, err := url.Parse(fmt.Sprintf("http://%v/", host))
if err != nil {
log.Printf("Error parsing URL")
}
p.proxy = httputil.NewSingleHostReverseProxy(u)
http.Handle("/", p)
log.Fatal(http.ListenAndServe("localhost:8000", nil))
}
type Proxy struct {
proxy *httputil.ReverseProxy
}
func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
p.proxy.ServeHTTP(w, r)
}
Run Code Online (Sandbox Code Playgroud)
将Chrome链接到'localhost:8000'时,将'www.google.com'与'www.apple.com'交换会导致此错误:
无效的网址
请求的URL"/"无效.参考编号#9.a61a32b8.1438231668.41733295
为www.apple.com做一点挖掘,我得到:
? ~ curl --ipv4 -v …Run Code Online (Sandbox Code Playgroud) 我有这个文件结构:
/home/test
??? dirA
? ??? ClassA.py
??? dirB
??? Main.py
Run Code Online (Sandbox Code Playgroud)
文件中有以下内容:
类A.py:
class ClassA:
def __str__(self):
return 'Hi'
Run Code Online (Sandbox Code Playgroud)
主要.py:
from dirA.ClassA import ClassA
class Main:
def main():
a = ClassA()
if __name__ == '__main__':
Main.main()
Run Code Online (Sandbox Code Playgroud)
我将当前目录更改为:
$ cd /home/test/dirB
Run Code Online (Sandbox Code Playgroud)
这有效:
$ PYTHONPATH=/home/test python Main.py
Run Code Online (Sandbox Code Playgroud)
这不会:
$ python Main.py
Traceback (most recent call last):
File "Main.py", line 1, in <module>
from dirA.ClassA import ClassA
ModuleNotFoundError: No module named 'dirA'
Run Code Online (Sandbox Code Playgroud)
在 Main.py 中添加此行无效:
import os, sys
# Get the …Run Code Online (Sandbox Code Playgroud) 我有以下Mongo DB文档结构:
{
_id: channelId,
title: channelTitle,
pubDate: channelPubdate,
items:
[
{
title: newsTitle,
desc: newsDescription,
link: newsLink,
pubDate: Date,
clicks: 0
},
{/*One more*/},
{/*...*/}
]
}
Run Code Online (Sandbox Code Playgroud)
我有麻烦增加Collection中的"clicks"字段(更新嵌入在数组中的文档的字段).
我在事件处理程序(客户端)中尝试了这个:
News.update({ _id : Session.get("channelId"), "items.link" : this.link },
{ $inc: { "items.clicks": 1 } }
);
Run Code Online (Sandbox Code Playgroud)
但它给出了一个错误: Uncaught Error: Not permitted. Untrusted code may only update documents by ID. [403]
然后我尝试通过服务器方法:
Meteor.methods({
incClicks: function(id, news)
{
News.update({ _id : id, "items.link" : news.link },
{ $inc : { "items.clicks": 1 …Run Code Online (Sandbox Code Playgroud) 我是ocaml的新手,通过了一些教程,并认为下一步,我会通过阅读一些OOS来熟悉语法.所以我从Facebook 下载了Flow.
但是,我使用"|>"遇到了一些奇怪的语法,我无法弄清楚.
首先我在这里遇到了"|>" :
args = CommandSpec.ArgSpec.(
empty
|> flag "--tokens" no_arg
~doc:"Include a list of syntax tokens in the output"
|> flag "--pretty" no_arg
~doc:"Pretty-print JSON output"
|> CommandUtils.from_flag
|> anon "file" (optional string) ~doc:"[FILE]"
)
Run Code Online (Sandbox Code Playgroud)
当我在寻找它的定义时,我在另一个文件中找到了这个:
let (|>) (o : 'a) (f : 'a -> 'b) : 'b = f o
Run Code Online (Sandbox Code Playgroud)
但我不太清楚它在做什么,或者它是否相关.
你能帮忙吗?
下面的代码试图将像素设置为脱机位图,并将该位图绘制到屏幕上。不幸的是,它崩溃了。
import UIKit
class GameView: UIView {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
}
func createBitmapContext(pixelsWide: Int, _ pixelsHigh: Int) -> CGContextRef? {
let bytesPerPixel = 4
let bytesPerRow = bytesPerPixel * pixelsWide
let bitsPerComponent = 8
let byteCount = (bytesPerRow * pixelsHigh)
let colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)
let pixels = UnsafeMutablePointer<CUnsignedChar>.alloc(byteCount)
if pixels == nil {
return nil
}
let bitmapInfo = CGImageAlphaInfo.PremultipliedFirst.rawValue | CGBitmapInfo.ByteOrder32Little.rawValue
let context = CGBitmapContextCreate(pixels, pixelsWide, pixelsHigh, bitsPerComponent, …Run Code Online (Sandbox Code Playgroud) 我编写了这个不编译的代码:
String[] text = {"hello", "bye"};
IntStream.of(Arrays.stream(text).map(String::length)).sum()
Run Code Online (Sandbox Code Playgroud)
我是否需要将流转换为IntStream?当我传递String::length给map()函数时,为什么会出现错误?
当使用require时,我需要在左括号之前使用引号但是当我使用ns时:require我不必使用引号.这是为什么?
(ns foo)
(ns user)
(require '[foo :as f]) ;; quote
(ns bar (:require [foo :refer :all])) ;; no quote
Run Code Online (Sandbox Code Playgroud)
我知道引用不评估括号前面的表达式,但不完全确定为什么在括号前需要引用,因为它们不是表达式所以不应该评估任何内容.
在下面的代码片段中,传递 x 和 y 值会将点放在 (y,x) 坐标中,而绘图是在 (x,y) 中完成的。设置绘图缓冲区以便在同一坐标系中放置像素和绘图的正确方法是什么?
from PIL import Image, ImageDraw
def visual_test(x, y):
grid = np.zeros((100, 100, 3), dtype=np.uint8)
grid[:] = [0, 0, 0]
grid[x, y] = [255, 0, 0]
img = Image.fromarray(grid, 'RGB')
draw = ImageDraw.Draw(img)
draw.line((x, y, x, y-5), fill=(255,255,255), width=1)
img.show()
Run Code Online (Sandbox Code Playgroud)