In Ruby, a Symbol is the most efficient way, in terms of time and memory, to represent a set of characters.
Most commonly, a Symbol is a single word prefixed by a colon:
:hello
class CustomSearch < Spree::Core::Search::Base | |
protected | |
def add_search_scopes(base_scope) | |
statement = nil | |
search.each do |property_name, property_values| | |
property = Spree::Property.find_by_name(property_name.gsub("_any", "")) | |
next unless property | |
substatement = product_property[:property_id].eq(property.id).and(product_property[:value].eq(property_values.first)) |
def ProductFilters.option_with_values(option_scope, option, values) | |
# get values IDs for Option with name {@option} and value-names in {@values} for use in SQL below | |
option_values = Spree::OptionValue.where(:presentation => [values].flatten).joins(:option_type).where(OptionType.table_name => {:name => option}).pluck("#{OptionValue.table_name}.id") | |
return option_scope if option_values.empty? | |
option_scope = option_scope.where("#{Product.table_name}.id in (select product_id from #{Variant.table_name} v left join spree_option_values_variants ov on ov.variant_id = v.id where ov.option_value_id in (?))", option_values) | |
option_scope | |
end | |
# option scope |
<html> | |
<head> | |
<title>Google Maps Multiple Markers</title> | |
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> | |
</head> | |
<body> | |
<div id="map" style="height: 400px; width: 500px;"> | |
</div> | |
<script type="text/javascript"> |
A Hash is a collection of key-value pairs. To add, fetch, modify, and delete a value from a Hash, you refer to it with a unique key.
While an Array is indexed by Integers only, a Hash is keyed by any object -- Strings, Integers, etc.
In other programming languages, a Hash might be known as an 'associative array', 'dictionary', or 'HashMap'.
class Car | |
attr_reader :mileage, :service | |
def initialize(mileage = 0, service = 3000) | |
@mileage, @service = mileage, service | |
@observers = [Notifier.new] | |
end | |
def log(miles) | |
@mileage += miles | |
notify_observers(self, miles) | |
end |
# install openjdk | |
sudo apt-get install openjdk-7-jdk | |
# download android sdk | |
wget http://dl.google.com/android/android-sdk_r24.2-linux.tgz | |
tar -xvf android-sdk_r24.2-linux.tgz | |
cd android-sdk-linux/tools | |
# install all sdk packages |
Disclaimer: The instructions are the collective efforts from a few places online. | |
Nothing here is my original. But I want to put them together in one place to save people from spending the same time as I did. | |
First off, bundle. | |
================== | |
1. cd to the project directory | |
2. Start the react-native packager if not started | |
3. Download the bundle to the asset folder: | |
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle" |
2015-01-29 Unofficial Relay FAQ
Compilation of questions and answers about Relay from React.js Conf.
Disclaimer: I work on Relay at Facebook. Relay is a complex system on which we're iterating aggressively. I'll do my best here to provide accurate, useful answers, but the details are subject to change. I may also be wrong. Feedback and additional questions are welcome.
Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).
# Sample implementation of quicksort and mergesort in ruby | |
# Both algorithm sort in O(n * lg(n)) time | |
# Quicksort works inplace, where mergesort works in a new array | |
def quicksort(array, from=0, to=nil) | |
if to == nil | |
# Sort the whole array, by default | |
to = array.count - 1 | |
end |