我的其中一个页面上有 og 标签:
%meta{property:"og:image", content:"https://stars-et-metiers.s3.amazonaws.com/posters/attachments/000/000/990/large/rsz_sm_01_rvb.jpg?1478271329" }
%meta{property:"og:url", content: votes_url }
%meta{ property: 'og:description', content: "J’ai voté pour mon lauréat coup de ? Stars & Métiers 2016 ! Et vous, quel est votre coup de cœur ? avec lien minimisé vers la page lauréat du site" }
Run Code Online (Sandbox Code Playgroud)
这个想法是告诉 facebook 实际上检查来自另一个页面的 ogs 以创建丰富的帖子:
%meta{property:"og:url", content: votes_url }
Run Code Online (Sandbox Code Playgroud)
因此 facebook 实际上应该从 votes_url 路径中删除 ogs :
%meta{ property: 'og:title', content: "J’ai voté pour mon lauréat Stars et Metiers" }
/ %meta{ property: 'og:url', content: …Run Code Online (Sandbox Code Playgroud) 我从反应原生开始。我从 giphy API 请求一个 gif,然后更新我的 giphyUrl 状态(状态已更改),但 gif 没有更改(组件未重新渲染)。
class QuoteList extends Component {
state = { quotes: [],
giphyUrl: 'https://media.giphy.com/media/nZQIwSpCXFweQ/giphy.gif'
};
componentWillMount() {
console.log('Again?')
axios.get('https://api.tronalddump.io/search/quote?query='+this.props.characterName)
.then(response => this.setState({ quotes: response.data._embedded.quotes }))
this.getGiphy()
}
getGiphy() {
console.log('getgif')
const GiphyUrl = "https://api.giphy.com/v1/gifs/search?api_key=tutu&limit=1&q=" + this.props.characterName.replace(" ", "+");
console.log(GiphyUrl)
axios.get(GiphyUrl)
.then(response => {
console.log(response)
console.log(response.data.data[0].url)
this.setState({ giphyUrl: response.data.data[0].url })
console.log(this.state)
})
}
renderQuotes() {
return this.state.quotes.map(
quote => <QuoteDetail key={quote.quote_id} quote={quote}/>
);
}
render() {
return (
<ScrollView>
<Image
source={{uri: this.state.giphyUrl}}
style={styles.gifStyle}
/> …Run Code Online (Sandbox Code Playgroud) 我在 macOS Catalina 版本 10.15.1 下运行当我在项目上运行 Rails 控制台并尝试执行如下查询时User.first:
objc[57093]:调用 fork() 时,+[__NSCFConstantString 初始化] 可能已在另一个线程中进行。objc[57093]:调用 fork() 时,+[__NSCFConstantString 初始化] 可能已在另一个线程中进行。我们不能在 fork() 子进程中安全地调用它或忽略它。反而崩溃了。在 objc_initializeAfterForkError 上设置断点进行调试。
我按照这个答案添加OBJC_DISABLE_INITIALIZE_FORK_SAFETY到我的.zshrc文件中,如下所示:
ZSH=$HOME/.oh-my-zsh
# You can change the theme with another one:
# https://github.com/robbyrussell/oh-my-zsh/wiki/themes
ZSH_THEME="robbyrussell"
# Useful oh-my-zsh plugins for Le Wagon bootcamps
plugins=(git gitfast zsh-autosuggestions last-working-dir zsh-syntax-highlighting common-aliases history-substring-search)
# Prevent Homebrew from reporting - https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Analytics.md
export HOMEBREW_NO_ANALYTICS=1
# Actually load Oh-My-Zsh
source "${ZSH}/oh-my-zsh.sh"
unalias rm # No interactive rm by …Run Code Online (Sandbox Code Playgroud) 我无法理解红宝石中特征类或单例类的概念。我读了很多,认为 eigenclass是一个类的类。这对我来说没有意义,因为对我来说,类的类实际上是Class因为所有类实际上都是类的实例Class。
另一件我不太明白的事情是下面的说法:类方法实际上是类 eigenclass 的实例方法。特征类可以通过以下方式访问:
YourClass = Class.new
class << YourClass
def class_method
end
end
Run Code Online (Sandbox Code Playgroud)
但是,如果特征类确实是 YourClass 类(即Class),那么前面的代码不应该打开该类Class并向其添加实例方法class_method,使其可供所有未来的实例访问(即在未来)?
我实际上感觉单例类与Class. 当你这样做时:
class MyClass
end
MyClass.singleton_class
Run Code Online (Sandbox Code Playgroud)
你得到的#<Class:MyClass>结果与输出不同MyClass.class => Class
#<Class:MyClass>那个输出是什么?这与命名空间无关,否则会有两个:Class::MyClass...
我正在寻找对本征类概念的简单且明确的解释,以澄清我的想法。
我想在ruby中实现我自己的静态数组类。这将是一个具有固定容量的数组,并且该数组中的所有元素都是单一类型。为了直接访问内存,我正在使用FFI gem https://github.com/ffi/ffi,它可以创建您自己的C函数并将其用于ruby程序。我创建了一个非常简单的C函数,该函数为整数数组分配内存,并返回指向内存空间的指针:
int * create_static_array(int size) {
int *arr = malloc(size * sizeof(int));
return arr;
}
Run Code Online (Sandbox Code Playgroud)
这是我的ruby static_array类,它使用create_static_array:
require 'ffi'
class StaticArray
attr_accessor :pointer, :capacity, :next_index
extend FFI::Library
ffi_lib './create_array/create_array.so'
attach_function :create_static_array, [:int], :pointer
def initialize(capacity)
@capacity = capacity
@pointer = create_static_array(capacity)
@next_index = 0
end
# adds value to the next_index in array
def push(val)
@pointer[@next_index].write(:int, val)
@next_index += 1
end
# reads value at index
def [](index)
raise IndexOutOfBoundException if index >= @capacity
self.pointer[index].read(:int)
end
# …Run Code Online (Sandbox Code Playgroud) 我有一个名为 session 的表,其中包含一个名为 lms_data 的 jsonb 属性。我想创建一个范围以按 jsonb 列中的特定字段进行排序。以下查询运行良好select * from sessions ORDER BY lms_data->>'startDate' ASC
,但是会话模型中的以下范围不会执行:
scope :order_by_start_date_asc, -> { order("lms_data->>'startDate' ASC ") }
Run Code Online (Sandbox Code Playgroud)
它失败了Query method called with non-attribute argument(s): "lms_data->>'startDate' ASC "
如何创建基于 jsonb 列中的字段进行排序的范围?
在我的fullcalendar http://fullcalendar.io/ 我想阻止用户能够在多天内创建一个事件
$('#calendar').fullCalendar({
defaultView: 'agendaWeek',
lang: "fr",
header: false,
timezone: 'local',
minTime: "08:00:00",
columnFormat: 'dddd',
selectHelper: true,
selectable: true,
select: function(start, end, id, allDay) {
var eventData = {
start: start,
end: end,
id: 1,
block: true,
editable: true,
backgroundColor: "#469278"
};
// console.log(moment(eventData.start["_d"]).format("dddd"));
// console.log(moment(eventData.end["_d"]).format("dddd"));
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
// console.log(eventData);
if (moment(eventData.start["_d"]).format("dddd") != moment(eventData.end["_d"]).format("dddd")) {
$('#calendar').fullCalendar('unselect');
};
var day = moment(eventData.start["_d"]).format("dddd");
var start_time = moment(eventData.start["_d"]).format("HH:mm");
var end_time = moment(eventData.end["_d"]).format("HH:mm");
var id = moment(eventData.end["_id"]);
var …Run Code Online (Sandbox Code Playgroud) 我刚刚开始开发另一个开发人员开发的新 Rails 应用程序,我必须承担该项目。当我尝试在开发模式下本地运行应用程序时,我在设置级别遇到了困难。该应用程序无法加载资源(css、js、图像)。我得到ERR_CONNECTION_REFUSED每个资产文件:

我必须补充一点,该项目正在使用
gem 'asset_sync', '~> 1.0.0'
Run Code Online (Sandbox Code Playgroud)
它用于同步 Rails 和 S3 之间的资产,但我认为它不应该在开发模式中发挥任何作用。
您知道为什么应用程序在开发模式下不加载资源吗?
我已经创建了一个模块来在类中的方法调用之前挂钩方法:
module Hooks
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
# everytime we add a method to the class we check if we must redifine it
def method_added(method)
if @hooker_before.present? && @methods_to_hook_before.include?(method)
hooked_method = instance_method(@hooker_before)
@methods_to_hook_before.each do |method_name|
begin
method_to_hook = instance_method(method_name)
rescue NameError => e
return
end
define_method(method_name) do |*args, &block|
hooked_method.bind(self).call
method_to_hook.bind(self).(*args, &block) ## your old code in the method of the class
end
end
end
end
def before(*methods_to_hooks, hookers)
@methods_to_hook_before = methods_to_hooks
@hooker_before = hookers[:call]
end …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Ruby 来理解流程。我正在从我的父进程创建 4 个子进程。主进程首先写入文件,然后创建子进程,每个子进程都写入同一个文件:
require 'csv'
a = [1, 2, 3, 4]
CSV.open("temp_and_cases_batch_parallel.csv", "ab") do |target_file|
target_file << ["hello from parent process #{Process.pid}"]
a.each do |num|
pid = Process.fork do
target_file << ["hello from child Process #{Process.pid}"]
end
puts "parent, pid #{Process.pid}, waiting on child pid #{pid}"
end
end
Process.wait
puts "parent exiting"
Run Code Online (Sandbox Code Playgroud)
我期望的文件输出
hello from parent process 3336
hello from child Process 3350
hello from child Process 3351
hello from child Process 3349
hello from child Process 3352 …Run Code Online (Sandbox Code Playgroud) ruby ×4
activerecord ×1
arrays ×1
assets ×1
c ×1
class ×1
csv ×1
eigenclass ×1
ffi ×1
fork ×1
fullcalendar ×1
hook ×1
javascript ×1
jquery ×1
jsonb ×1
memory ×1
module ×1
process ×1
react-native ×1
rerender ×1
sql-order-by ×1
zsh ×1