Skip to content

Instantly share code, notes, and snippets.

View channainfo's full-sized avatar
🎯
Focusing

Channa Ly channainfo

🎯
Focusing
  • InSTEDD, SureSwift Capital, BookMeBus, VTENH, Onthegosystems
  • Phnom Penh
  • X @channaly
  • LinkedIn in/channaly
View GitHub Profile
@channainfo
channainfo / product.rb
Created February 23, 2021 07:12
Spree search with globalize by translated fields
# spree/model/product.rb
def self.like_any_with_translation(fields, values)
tran_fields = if defined?(SpreeGlobalize)
fields.select{ |field| Spree::Product.translated_attribute_names.include?(field) }
else
[]
end
if tran_fields.blank?
@channainfo
channainfo / feed_taxon_product.rb
Last active February 19, 2021 08:26
Get 4 ( top ) products per taxon
module Feed
class TaxonProduct
attr_accessor :taxon
LIMIT = 4
def initialize(taxon:, products:)
@taxon = taxon
@products = products
end
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.2'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
GIT
remote: https://github.com/rspec/rspec-core.git
revision: e7c5d030966a7e8dad3e0a67c61920c4f2437c15
branch: master
specs:
rspec-core (3.10.0.pre)
rspec-support (= 3.10.0.pre)
GIT
remote: https://github.com/rspec/rspec-expectations.git
@channainfo
channainfo / list_map_with_index_extension.dart
Last active November 14, 2020 04:51
List map with index return List and Iterable
// lib/extensions/list_map_with_index_extension.dart
extension MapWithIndex<T> on List<T> {
List<R> mapWithIndex<R>(R Function(T, int i) callback) {
List<R> result = [];
for (int i = 0; i < this.length; i++) {
R item = callback(this[i], i);
result.add(item);
}
return result;
@channainfo
channainfo / list_map_with_index_extension_test.dart
Last active November 14, 2020 05:42
List map with index return both List and Iterable test.
//test/extensions/list_map_with_index_extension_test.dart
import 'package:flutter_test/flutter_test.dart';
import 'package:vtenh/extensions/list_map_with_index_extension.dart';
void main() {
group('.mapWithIndex', () {
test('return a new list from map value and index as original Int type', () {
List<int> items = [20, 30, 40];
List<int> result = items.mapWithIndex((value, index) => index * 2);
@channainfo
channainfo / list_map_with_index_extension.dart
Last active November 14, 2020 03:43
Map with index dart extension
import 'package:flutter_test/flutter_test.dart';
import 'package:vtenh/extensions/list_map_with_index_extension.dart';
void main() {
group('.mapWithIndex', () {
test('return a new list from map value and index as original Int type', () {
List<int> items = [20, 30, 40];
List<int> result = items.mapWithIndex((value, index) => index * 2);
expect(result.length, 3);
@channainfo
channainfo / response_nearest_point.json
Created July 4, 2020 02:08
Json response for find nearest point
{
"geocoded_waypoints": [
{
"geocoder_status": "OK",
"place_id": "ChIJ42tqxz1RCTERuyW1WugOAZw",
"types": [
"locality",
"political"
]
@channainfo
channainfo / polyline_dataset.rb
Last active July 4, 2020 01:58
Polyline data set for find-nearest-point-in-the-road-from-a-specific-address-in-ruby-and-show-in-google-map
[
{
"lat"=> 11.55597,
"lng"=> 104.92815
},
{
"lat"=> 11.55588,
"lng"=> 104.9282
},
{