我正在尝试创建一些种子数据,并从Railcasts获得此代码.我稍微修改了它,但是当我从终端运行bundle exec rake db:seed时似乎没有工作.我在终端中收到以下错误...
wrong number of arguments (0 for 1)
Run Code Online (Sandbox Code Playgroud)
下面是我在seeds.rb文件中填充表格的代码.某处有愚蠢的错误吗?
require 'open-uri'
International.delete.all
open("international.txt") do |countries|
countries.read.each_line do |data|
code, country, currency = data.chomp.split("|")
International.create!(:code => code, :country => country, :currency => currency)
end
end
Run Code Online (Sandbox Code Playgroud)
和我的文本文件(存储在seeds.rb文件所在的目录中...
AU|Australia|AUD
CA|Canada|CAD
GB|United Kingdom|GBP
US|United States|USD
Run Code Online (Sandbox Code Playgroud) I have a data structure that adds user's data to their unique id such as follows.
"users" :
{
"user_id":
{
"name":"John Doe",
"email":"email@example.com",
"account":"limited",
"avatar" : "this will be a base64 data string"
}
}
Run Code Online (Sandbox Code Playgroud)
I want to deny users from listing other users and I also want logged in users to access their data based on their "user_id" which is gotten from auth.uid
I had tried some rules:
{
"rules" :
{
"users" :
{
".read" : "false", …Run Code Online (Sandbox Code Playgroud) 开始使用Go并浏览文档:https://golang.org/doc/code.html
名为Package paths的部分建议使用我的Github帐户作为基本路径.但是,使用GH url中的正斜杠,当我运行mkdir -p $GOPATH/src/github.com/user它时会创建一个子文件夹.所以github.com/user创建的例子如下:
src/
github.com/
user/
Run Code Online (Sandbox Code Playgroud)
但我认为这不是预期的.
我能在这做什么?
我有一个用户列表,当我点击列表项时,我希望子部分从它下面向下滑动.我对动画很好,这不是我需要帮助的领域.我的问题是,当我点击任何列表项时,所有下拉部分都会显示在所有列表项下面.
所以我现在的方法是使用id每个用户创建一个独特的ng-show.然后当我点击列表项时,会调用一个函数:
<ul id="users" ng-repeat="user in users">
<li ng-click="showUserDetail(user.id)">
{{user.name}}
<div class="slide" ng-show="dropDownSection_{{user.id}}">
//Stuff will go here
</div>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
该showUserDetail功能是:
$scope.showUserDetail = function(id) {
//not sure I can do this?
var section = "dropDownSection" + "_" + id;
$scope.section = true; //this would normally show the animation
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用 - 下拉列表不会出现.
是否有一种很好的"角度"方式来实现这样的目标?
我第一次使用指针,我有一个简单的问题.
我有两个函数main和other.如果我在main函数中有一个我想在函数中使用的变量,我other应该将它作为参数传递还是击败指针的对象?
选项1
func main() {
myVar := "hello world"
other(&myVar)
}
func other(s *string) {
println(s)
}
Run Code Online (Sandbox Code Playgroud)
方案2
func main() {
myVar := "hello world"
other()
}
func other() {
println(*myVar) //Is myVar even accessible here?
}
Run Code Online (Sandbox Code Playgroud) 这很可能是一个愚蠢的错误,但我看不出这个问题.我正在尝试在Angularjs应用程序中为图库创建一个对象数组.每张照片对象有一个thumb和img属性.该for循环创建对象细,我每次登录到控制台进行检查:
{thumb: "/10000/0_t.jpg", img: "/10000/0_l.jpg"}
{thumb: "/10000/1_t.jpg", img: "/10000/1_l.jpg"}
{thumb: "/10000/2_t.jpg", img: "/10000/2_l.jpg"}
...
Run Code Online (Sandbox Code Playgroud)
但是,运行此代码后:
var images = [];
var image = {};
for (var i = 0; i < property.images.length; i++) {
image.thumb = "/" + property.id + "/" + i + "_t.jpg";
image.img = "/" + property.id + "/" + i + "_l.jpg";
console.log(image); //this gives expected output
images.push(image);
};
console.log(images); //this gives all entries as the same
Run Code Online (Sandbox Code Playgroud)
决赛console.log给了我:
{thumb: …Run Code Online (Sandbox Code Playgroud) 我应该如何从安全区域中的网页引用我的css文件(位于非安全区域中)。我已经考虑过将其复制(将其移入安全区域),但这似乎效率很低。
任何建议,不胜感激。(ps很有可能会有一些后续问题哈哈)
我正在尝试使用 LoDash 从数组中删除一个对象。
var roomList = [
{id: '12345', room: 'kitchen'},
{id: '23456', room: 'lounge'},
{id: '34567', room: 'bathroom'},
];
console.log(roomList); //outputs all 3 rooms
_.pull(roomList, {id: '12345'});
console.log(roomList); //STILL outputs all 3 rooms!
Run Code Online (Sandbox Code Playgroud)
我以为_pull在这种情况下会起作用,但事实并非如此。如何使用 LoDash 从数组中删除对象?
我不知道如何创建一个struct存储发布到我的API的JSON对象.
JSON看起来像这样:
{
"name" : "Mr Robinson",
"email" : "test@test.com",
"username" : "robbo123",
"properties" : {
"property1" : "a property",
"property2" : "another property"
},
"permissions" : ["perm1", "perm2", "perm3"]
}
Run Code Online (Sandbox Code Playgroud)
可以有任意数量properties的permissions数组,数组可以包含任意数量的值.
我用它来解码发布的值:
err := json.NewDecoder(req.Body).Decode(my_struct)
Run Code Online (Sandbox Code Playgroud)
到目前为止我的结构看起来像这样:
type User struct {
Name string `json:"name"`
Email string `json:"email"`
Username string `json:"username"`
}
Run Code Online (Sandbox Code Playgroud) 我有一些JSON,我需要能够访问属性.由于JSON属性可能会有所不同,因此无法创建struct要解组的内容.
例
JSON可能是这样的:
{"name" : "John Doe", "email" : "john@doe.com"}
Run Code Online (Sandbox Code Playgroud)
或这个:
{"town" : "Somewhere", "email" : "john@doe.com"}
Run Code Online (Sandbox Code Playgroud)
或其他任何东西.
我如何访问每个属性?
据我了解,乘法的复杂度顺序是二次的,因此,如果将两个1位数字相乘将有1个运算,两个2位数字相加将有4个运算,两个3位数字9个运算等等上。
我想通过定时执行将两个数字相乘的程序来查看这种复杂性。出乎意料的是,无论数字的大小如何,执行时间都是相同的。
import time
num1 = 135
num2 = 342
start = time.time()
total = num1 * num2
finish = time.time()
elapsed = finish - start
print elapsed
Run Code Online (Sandbox Code Playgroud)
因此,结果是9.53674316406e-07我将两个3位数或两个30位数相乘。
我误会什么?