Skip to content

Instantly share code, notes, and snippets.

View Bajena's full-sized avatar
🎩
Working on stuff

Jan Bajena Bajena

🎩
Working on stuff
View GitHub Profile
@Bajena
Bajena / Fix for carrierwave with imagevoodoo throwing JavaxImageIO IIOexception
Created July 10, 2015 07:26
Fix for carrierwave with imagevoodoo throwing JavaxImageIO IIOexception
# This module overrides mount_uploader method and assign methods
# in order to handle Java ImageIO exception which occurs for
# some png files and is unhandled by CarrierWave gem.
# If the file is invalid, it removes newly created
# files, assigns old file back and returns validation error.
module CarrierWavePngFix
extend ActiveSupport::Concern
module ClassMethods
def mount_uploader(column, uploader=nil, options={}, &block)
@Bajena
Bajena / paper_trail.rb
Last active June 24, 2016 12:48
Monkey patch for storing file changes in paper_trail version object
module PaperTrail
module Model
module InstanceMethods
private
def changes_for_paper_trail
notable_changes = changes.delete_if { |k, _v| !notably_changed.include?(k) }
AttributeSerializers::ObjectChangesAttribute.
new(self.class).
serialize(notable_changes)
@Bajena
Bajena / paper_trail.rb
Created June 24, 2016 14:00
Patch for paper_trail initializer that fixes attributes enumerized with enumerize gem
module PaperTrail
module AttributeSerializers
class CastAttributeSerializer
alias_method :old_serialize, :serialize
alias_method :old_deserialize, :deserialize
def serialize(attr, val)
# Special case for enumerize gem
return defined_enumerize_enums[attr].find_value(val).to_s if defined_enumerize_enums[attr]
@Bajena
Bajena / args_to_hash.rb
Last active July 27, 2016 09:08
get a hash of keyword arguments method in ruby
module ArgsToHash
# allows returning a hash of arguments
# Example:
# def method(a:, b:)
# puts eval(ArgsToHash::ARGS_TO_HASH)
# end
#
# method(a: 1, b: 2)
# => {:a=>1, :b=>2}
ARGS_TO_HASH = "method(__method__).parameters.map { |arg| arg[1].to_s }."\
@Bajena
Bajena / test.js
Last active May 30, 2017 20:05
Test blog snippet
{
property1: 1,
property2: "xxx",
function f(x, y) {
return x + y;
},
g() {
return "x";
@Bajena
Bajena / index.html
Last active June 13, 2017 19:26
Prosty przykład użycia event listenerów
<html>
<head>
<meta charset="utf-8">
<title>Event handlers demo</title>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
</head>
<body>
<div class="wrapper" style="width:300px;height:300px;background:red;">
<button>Click me</button>
</div>
@Bajena
Bajena / breakpoints.html
Last active July 4, 2017 17:53
Materiał do 4. posta na bloga - breakpoints
<html>
<head>
<meta charset="utf-8">
<title>Breakpoints demo</title>
<script src="http://code.jquery.com/jquery-latest.js"
type="text/javascript"></script>
</head>
<body>
<div id="numbers" />
<script>
@Bajena
Bajena / breakpoints_interval.js
Created July 4, 2017 19:23
DOM breakpoints demo
setInterval(function() {
var x = getRandomInt(0, 100);
$('#numbers').append(x).append("<br/>");
}, 1000);
setInterval(function() {
var x = getRandomInt(101, 200);
$('#numbers').prepend("<br/>").prepend(x);
}, 2000);
@Bajena
Bajena / xhr_breakpoints.js
Created July 4, 2017 20:02
XHR breakpoints demo
setInterval(function() {
var x = getRandomInt(0, 100);
$('#numbers').append(x).append("<br/>");
}, 1000);
setInterval(function() {
fetch('https://www.random.org/integers/?num=1&min=0&max=100&col=1&base=10&format=plain&rnd=new').then(function(response){
return response.text();
}).then(function(number) {
$('#numbers').prepend("<br/>").prepend(number);
@Bajena
Bajena / function_breakpoints.js
Last active July 4, 2017 21:02
Function breakpoints - example
function myFunction() {
console.log('my func');
}
setInterval(function() {
var x = getRandomInt(0, 1);
if (x == 0) {
myFunction();
}