Skip to content

Instantly share code, notes, and snippets.

View mtrolle's full-sized avatar

Morten Trolle mtrolle

View GitHub Profile
@mtrolle
mtrolle / memory-test-httparty.rb
Created November 14, 2018 13:57
High memory consumption on HTTParty, question asked on StackOverflow: https://stackoverflow.com/questions/53169751/ruby-memory-usage-gone-wild
require 'bundler/inline'
require 'json'
gemfile do
source 'https://rubygems.org'
gem 'httparty'
gem 'nokogiri'
gem 'memory_profiler'
end
@mtrolle
mtrolle / memory-test.rb
Last active December 3, 2018 02:51
High memory consumption, question asked on StackOverflow: https://stackoverflow.com/questions/53169751/ruby-memory-usage-gone-wild
require 'bundler/inline'
require 'json'
gemfile do
source 'https://rubygems.org'
gem 'rest-client'
gem 'nokogiri'
gem 'memory_profiler'
end
# Will apply a jQuery Autocomplete on an input field, given input field has data-autocomplete set to a json object
# with keys:
# - path Being path to autocomplete source, taking ?term=query as search argument
# - target Target field name, e.g. 'id'. Will create a hidden target field where name of autocomplete input field is
# replaced with this `target` name. So if input is autocomplete_name target field will be autocomplete_id.
# It will apply the object value with key of same value as target. So in above example key will be id.
# - params Allows you to append additional params to the final source URL. Formatted key:value;key:value;key:value
# For `value` we'll lookup a input field with the `value` as id and take it's value.
$(document).on 'focus', 'input[data-autocomplete]', ->
settings = $(this).data('autocomplete')
@mtrolle
mtrolle / devise_invitable.da.yml
Last active May 29, 2016 13:14
Danish translation of devise_invitable language file
da:
devise:
failure:
invited: "Du har en ventende invitation, accepter den for at færdiggøre oprettelsen af din konto."
invitations:
send_instructions: "En invitationsemail er sendt til %{email}."
invitation_token_invalid: "Invitations nøglen er ikke valid!"
updated: "Din adgangskode blev gemt. Du er nu logget ind."
updated_not_active: "Din adgangskode blev gemt."
no_invitations_remaining: "Ingen tilbageværende invitationer."
@mtrolle
mtrolle / combining_different_cache_stategies_rails.rb
Last active March 9, 2016 23:02
If you need to cache large datasets memcached / dalli_store might not be enough, in that case you could combine different cache strategies in Rails.
# Using Dalli Store gem for default caching, just use Rails.cache directly
# https://github.com/petergoldstein/dalli
Rails.cache.fetch('some-key', expires_in: 1.hour) do
#foo baa and a lot of work
end
# Now use Rails FileStore cache as alternative strategy by using ActiveSupport::Cache::FileStore directly
cache = ActiveSupport::Cache::FileStore.new File.join(Rails.root, 'tmp', 'cache', 'some-name')
cache.fetch('some-key', expires_in: 1.hour) do
# some hard work returning a huge dataset to large for memcached