Skip to content

Instantly share code, notes, and snippets.

@JoshvaR88
JoshvaR88 / sort.rb
Created February 20, 2017 14:16 — forked from aspyct/sort.rb
Sample implementation of quicksort, mergesort and binary search in ruby
# 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

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.

What is Relay?

Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).

@JoshvaR88
JoshvaR88 / gist:223533695bb6e1b7172bb2a6e2da681b
Created August 22, 2016 06:57 — forked from marty-wang/gist:5a71e9d0a6a2c6d6263c
Compile and deploy React Native Android app of Release version to device.
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"
# 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
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
@JoshvaR88
JoshvaR88 / hashes.md
Created March 4, 2016 06:06 — forked from ryansobol/hashes.md
Hashes in Ruby

What's a Hash and why is it important?

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'.

What does a Hash look like?

@JoshvaR88
JoshvaR88 / symbols.md
Created March 4, 2016 06:05 — forked from ryansobol/symbols.md
Symbols in Ruby

What's a Symbol and why is it imporant?

In Ruby, a Symbol is the most efficient way, in terms of time and memory, to represent a set of characters.

What does a Symbol look like?

Most commonly, a Symbol is a single word prefixed by a colon:

:hello
<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">
@JoshvaR88
JoshvaR88 / product_filters.rb
Created November 2, 2015 15:45 — forked from Ranger-X/product_filters.rb
OptionValue filter
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
@JoshvaR88
JoshvaR88 / custom_searcher.rb
Created October 27, 2015 09:24 — forked from killthekitten/custom_searcher.rb
Dumb way to filter products by multiple properties in Spree.
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))