Skip to content

Instantly share code, notes, and snippets.

View heri's full-sized avatar

Heri Rakotomalala heri

View GitHub Profile
@heri
heri / quarantine.rb
Last active August 29, 2015 14:25
quarantine subredits
# quarantine algorithm for subreddit
# see https://medium.com/product-dot-io/reddit-empowering-the-community-5c0ce2c266e2
def quarantine(number_of_reports, number_of_content)
# number of content is number of comments and submissions with positive upvotes
s = number_of_reports - Math.log10(number_of_content)
order = Math.log10([s.abs, 1].max)
sign = if s > 0
@heri
heri / community_ads.rb
Last active August 29, 2015 14:25
Community ads for redditors
# community ads ranking for subreddit
# see https://medium.com/product-dot-io/reddit-empowering-the-community-5c0ce2c266e2
def user_ad_ranking(ad, ups, downs)
# difference between upvotes and downvotes for user-submitted ad
# coeff is a business constant to be determined
s = ups + coeff * Math.log10(ad.budget * 10) - downs
order = Math.log10([s.abs, 1].max)
sign = if s > 0
1
# Callback hell :/
Yelp.get("restaurants").then do |response|
PlacesTasks.sort(response.json[:places]}) do |response|
Place.review(response, {ranking: -1}) do |response|
puts "All finished"
end
end
end
# More readable asynchronous calls with Promises
# Saves a comment by current user to an event
def save_event_comment
model._created_at = Time.now
model.save!.then do
flash._notices << "Thanks for adding a comment"
new_event_comment
end.fail do |err|
flash._notices << err.to_s
end
end
@heri
heri / main.html
Last active September 8, 2015 15:36
<!-- Using a top level navigation component -->
<:nav href="/about">About</:nav>
<!-- Rendered as -->
<:Nav>
<li class="{{ if active_tab? }}active{{ end }}">
<a href="{{ attrs.href }}">{{ yield }}</a>
</li>
@heri
heri / todo_index.html
Last active September 15, 2015 15:59
<h1>Let's chat</h1>
<ul>
{{ page._messages.each do |message| }}
<li>{{ message._name }}</li>
{{ end }}
</ul>
<form e-submit="add_message">
<label>Todo</label>
<input type="text" value="{{ page._new_message }}" />
@heri
heri / todo.rb
Last active September 15, 2015 15:59
def add_message
page._message << { name: page._new_message }
page._new_todo = ''
end
jQuery.getJSON('/cart.js', function(cart) {
items = cart.items;
var results = items.filter(x => x.id === 6223106801703);
if ((results.length == 0) && (items.length > 0)) {
jQuery.post('/cart/add.js', {
quantity: 1,
id: 6223106801703
});
location.reload();
@heri
heri / 3dcnn.py
Last active March 31, 2019 05:18
3D CNN to infer throttle and angle for a RC autonomous car . Implementation of https://arxiv.org/pdf/1412.0767.pdf
# A basic end-to-end autonomous car uses 2d images to infer throttle and steering. However, speed and acceleration can change this. If the car is already speeding, throttle should decrease. If the car already has speed, then steering should be proportionally less
# One way to improve this is with hardware, by adding a RPM speed sensor (optical or magnetic), a GPS, an IMU or a combination. This is used as an input to the model
# If one does not have a speed sensor, another way is to update the model so it takes into account the last frames, and by using Kera's 3d convolution methods. Reference paper to read : https://arxiv.org/pdf/1412.0767.pdf
# This can slow down inference and result in lower fps
img_in3D = Input(shape=(3, 120, 160, 3), name='img_in') # First layer, input layer, takes 3 Shapes comes from camera.py resolution, RGB
x = img_in3D x = Cropping3D(cropping = ((0, 0),(60, 0),(0, 0)))(x) # Depending on your camera angle. Most cameras are pointed downards so the top X pixels can be safely cropped
x =
@heri
heri / get lat, long
Last active December 12, 2019 21:13
var my_city = "Montreal";
var getJSON = require("async-get-json");
var geLatLng = await getJSON("https://api.opencagedata.com/geocode/v1/json?key=50adaa7181d24a7581a62fd3d9c0a2e0&q=" + my_city);
var latLng = geLatLng.results[0].geometry["lng"] + "," + geLatLng.results[0].geometry["lat"];