Skip to content

Instantly share code, notes, and snippets.

@joost
joost / README.md
Last active January 8, 2024 20:03
How to fix invalid byte sequence in UTF-8 rack in Rails

Add the utf8_sanitizer.rb to your Rails 3.2 project in app/middleware. Instead of removing the invalid request characters and continuing the request (as some gems do) it returns a 400 error.

Add the following line to your config/application.rb:

config.middleware.use 'Utf8Sanitizer'

If you only need it in production add to config/environments/production.rb. This can be without quotes:

config.middleware.use Utf8Sanitizer
@staltz
staltz / introrx.md
Last active May 3, 2024 13:00
The introduction to Reactive Programming you've been missing
package com.andraskindler.sandbox.activity;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.RenderScript;
import android.widget.FrameLayout;
import android.widget.ImageView;
@chrisbanes
chrisbanes / FloatLabelLayout.java
Last active March 15, 2024 06:39
FloatLabelLayout
/*
* Copyright 2014 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@mperham
mperham / bench.rb
Last active August 29, 2015 13:57
Sidekiq performance 2014
require 'sidekiq'
class LazyWorker
include Sidekiq::Worker
def perform
# nothing
end
end
Sidekiq.configure_client do |config|
@seanlilmateus
seanlilmateus / values_for_keys_with_dictionary.rb
Last active May 12, 2018 21:43
Using Cocoa’s KVC to assign JSON keys and values to Rubymotion models <Objects>
class User
MAPPING_KEYS = Hash[ 'user_name', :name, 'total_video_count', :videosCount]
attr_accessor *MAPPING_KEYS.values, :age
def initialize(args={})
if args.is_a?(Hash)
dictionary = Hash[ args.map { |k, v| [MAPPING_KEYS.fetch(k, k) , v] } ]
setValuesForKeysWithDictionary(dictionary)
end
end
@seanlilmateus
seanlilmateus / async_await.rb
Last active December 27, 2020 08:34
whenever Rubymotion returns a symbol of the def-expr, async and await like c# will be possible
module AsyncAwait
class Task < NSOperation
def self.new(&block)
alloc.initWithBlock(block)
end
def initWithBlock(block)
init.tap do
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 4.0"
gem "railties", "~> 4.0"
gem "tzinfo"
# Let's use thin
@bf4
bf4 / rails32_http_patch_support.rb
Last active June 4, 2018 09:04
HTTP PATCH support in Rails 3.2
# Rails 3.2 support for HTTP PATCH.
fail "Remove this patch" if Rails::VERSION::MAJOR > 3
# see http://weblog.rubyonrails.org/2012/2/26/edge-rails-patch-is-the-new-primary-http-method-for-updates/
# https://github.com/rails/rails/pull/505
# Be very conservative not to monkey-patch any methods until
# the relevant files are loaded.
ActiveSupport.on_load(:action_controller) do
ActionDispatch::Request.instance_eval do
# Is this a PATCH request?
package main
import (
"bytes"
"fmt"
"github.com/codegangsta/martini"
"github.com/rainycape/magick"
"io/ioutil"
"log"
"net/http"