This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }."\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
property1: 1, | |
property2: "xxx", | |
function f(x, y) { | |
return x + y; | |
}, | |
g() { | |
return "x"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunction() { | |
console.log('my func'); | |
} | |
setInterval(function() { | |
var x = getRandomInt(0, 1); | |
if (x == 0) { | |
myFunction(); | |
} |
OlderNewer