- The person you are assisting is User.
- Assume User is an experienced senior backend/database engineer, familiar with mainstream languages and their ecosystems such as Rust, Go, and Python.
- User values "Slow is Fast", focusing on: reasoning quality, abstraction and architecture, long-term maintainability, rather than short-term speed.
- Your core objectives:
- As a strong reasoning, strong planning coding assistant, provide high-quality solutions and implementations in as few interactions as possible;
- Prioritize getting it right the first time, avoiding superficial answers and unnecessary clarifications.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::{ | |
| fs::File, | |
| io::{self, BufReader}, | |
| }; | |
| use hyper::{ | |
| server::conn::AddrIncoming, | |
| service::{make_service_fn, service_fn}, | |
| Body, Method, Request, Response, Server, StatusCode, | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: extensions/v1beta1 | |
| kind: Ingress | |
| metadata: | |
| annotations: | |
| spanner.ingress.kubernetes.io/service-weights: | | |
| revision-0001: 90% | |
| revision-0002: 10% | |
| name: my-app | |
| spec: | |
| rules: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // AtomicWriteFile atomically writes data to a file by first writing to a | |
| // temp file and calling rename. | |
| func AtomicWriteFile(filename string, data []byte, perm os.FileMode) error { | |
| buf := bytes.NewBuffer(data) | |
| return atomicWriteFile(filename, buf, int64(len(data)), perm) | |
| } | |
| // atomicWriteFile writes data to a file by first writing to a temp | |
| // file and calling rename. | |
| func atomicWriteFile(filename string, r io.Reader, dataSize int64, perm os.FileMode) error { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const assert = require('assert'); | |
| function reverse(sentences) { | |
| const tokens = sentences.split(' '); | |
| const half = Math.floor(tokens.length / 2) | |
| for(let i = 0; i < half; i++) { | |
| const a = tokens[i]; | |
| const b = tokens[tokens.length - (i + 1)]; | |
| if (b === undefined) { | |
| return; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "sync" | |
| "time" | |
| "github.com/xujihui1985/safemap/safemap" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Continue: F8 or Command-/ (forward slash) on Mac or Control-/ (forward slash) on other platforms. | |
| Step over: F10 or Command-' (apostrophe) on Mac or Control-' (apostrophe) on other platforms. | |
| Step into: F11 or Command-; (semi-colon) on Mac or Control-; (semi-colon); on other platforms. | |
| Step out: Shift-F11 or Shift-Command-; (semi-colon) on Mac or Shift-Control-; (semi-colon) on other platforms. | |
| Next call frame: Control-. (period) on all platforms. | |
| Previous call frame: Control-, (comma) on all platforms. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function flatten(arr) { | |
| var result=[], | |
| concat = Array.prototype.concat, | |
| push = Array.prototype.push, | |
| element, | |
| array = arr.slice(); //shadow copy the array | |
| for(var i = 0, l = array.length; i < l; i++) { | |
| element = arr[i]; | |
| if(isArray(element)) { | |
| //for proformance reason, if all element flattened already, do not recurcivly call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function request(url) { | |
| // this is where we're hiding the asynchronicity, | |
| // away from the main code of our generator | |
| // `it.next(..)` is the generator's iterator-resume | |
| // call | |
| makeAjaxCall( url, it.next.bind(it) ); | |
| // Note: nothing returned here! | |
| } | |
| //otherwise I got Method Generator.prototype.next called on incompatible receiver undefined |