Skip to content

Instantly share code, notes, and snippets.

View ramhoj's full-sized avatar

Nicklas Ramhöj Holtryd ramhoj

View GitHub Profile
@ramhoj
ramhoj / Gemfile
Created April 6, 2021 13:54
Elasticsearch test setup working on Travis CI
gem "rails", "6.0.3.6"
gem "bonsai-elasticsearch-rails", "~> 7"
gem "elasticsearch-model", github: "elastic/elasticsearch-rails", branch: "master"
gem "elasticsearch-rails", github: "elastic/elasticsearch-rails", branch: "master"
@ramhoj
ramhoj / wait_for_elasticsearch.sh
Created March 30, 2021 06:39
wait_for_elasticsearch.sh
#!/usr/bin/env bash
# Credit: https://stackoverflow.com/a/59795634/1686364
host="localhost:9200"
response=""
attempt=0
until [ "$response" = "200" ]; do
if [ $attempt -ge 25 ]; then

Shortcut to prepend module that checks an argument and only calls original implementation if argument evals to false. Other versions could instead execute super(*args) and do different things depending on the result.

@ramhoj
ramhoj / issue.md
Last active June 5, 2020 08:37
ActionText issue

Steps to reproduce

  1. rails new actiontexttest --webpacker
  2. cd actiontexttest
  3. rails action_text:install
  4. rails db:migrate RAILS_ENV=development
  5. Add a root route, controller and view file
  6. bin/rails server
  7. bin/webpack-dev-server
  8. goto http://localhost:3000 (in Internet Explorer 11)
export default [
{
table: 32,
from: 1,
to: 1600,
value: 0
},
{
table: 32,
from: 1601,
@ramhoj
ramhoj / file.json
Created February 13, 2017 10:56
JSON parse example
{
"status": 1,
"list": {
"229279689": {
"item_id": "229279689",
"resolved_id": "229279689",
"given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview",
"given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland",
"favorite": "0",
"status": "0",
@ramhoj
ramhoj / phoenix-generate.sh
Created July 5, 2016 08:21
phoenix-generate.sh
brew install erlang
brew install elixir
git clone https://github.com/phoenixframework/phoenix.git
cd phoenix
mix do deps.get, compile
mix phoenix.new ../my_app
cd ../my_app
mix do deps.get, compile
mix phoenix.server
require "aws-sdk"
require "pry"
filename = File.expand_path("./deploy/video.rb", File.dirname(__FILE__))
config_file = File.open(filename, "w")
client = Aws::EC2::Client.new(
region: "eu-west-1",
access_key_id: "access_key_id",
secret_access_key: "secret_access_key"
@ramhoj
ramhoj / s3_read_only_policy.json
Last active August 16, 2017 17:42
AWS IAM S3 read/write only policy
{
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
@ramhoj
ramhoj / verify_push.exs
Created April 11, 2016 08:33
verify_push.exs
# Run with iex -S mix run script/verify
defmodule Pitch.VerifyPush do
@valid_tokens [
"7a61a279e0a35396d08ce13131fa6e2278a404f53683f17a16e1d6566223c712" # add more here
]
@number_of_bad_tokens 10
@pool :my_pool_name