Skip to content

Instantly share code, notes, and snippets.

View fidalgo's full-sized avatar
🐧

Paulo Fidalgo fidalgo

🐧
View GitHub Profile
@fidalgo
fidalgo / copy_attachments.rb
Created March 31, 2021 10:25 — forked from airblade/copy_attachments.rb
Copies S3-stored Paperclip attachments from one AR model to another
# lib/paperclip/copy_attachments.rb
# Copies S3-stored Paperclip attachments from one AR model to another.
#
# This module should be mixed into the target AR model.
if Gem::Version.new(::AWS::VERSION) >= Gem::Version.new(2)
raise NotImplementedError, 'coded for aws-sdk v1'
end
@fidalgo
fidalgo / signal.list
Last active March 24, 2020 09:54
Ruby signal.list under Fedora 31
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
ruby -e "puts Signal.list"
{"EXIT"=>0, "HUP"=>1, "INT"=>2, "QUIT"=>3, "ILL"=>4, "TRAP"=>5, "ABRT"=>6, "IOT"=>6, "FPE"=>8, "KILL"=>9, "BUS"=>7, "SEGV"=>11, "SYS"=>31, "PIPE"=>13, "ALRM"=>14, "TERM"=>15, "URG"=>23, "STOP"=>19, "TSTP"=>20, "CONT"=>18, "CHLD"=>17, "CLD"=>17, "TTIN"=>21, "TTOU"=>22, "IO"=>29, "XCPU"=>24, "XFSZ"=>25, "VTALRM"=>26, "PROF"=>27, "WINCH"=>28, "USR1"=>10, "USR2"=>12, "PWR"=>30, "POLL"=>29}
@fidalgo
fidalgo / serialize.rb
Created February 15, 2018 15:01
Rails JSON serialize
include ActiveModel::Serializers::JSON
def attributes
result = {}
object_methods = self.class.instance_methods(false) - self.class.public_methods(false)
object_methods.each do |method|
result[method] = send(method)
end
result
end

Keybase proof

I hereby claim:

  • I am fidalgo on github.
  • I am fidalgo (https://keybase.io/fidalgo) on keybase.
  • I have a public key whose fingerprint is 5C31 2326 48B1 1BB7 95B9 62A0 10C8 4652 9545 964A

To claim this, I am signing this object:

# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
@fidalgo
fidalgo / msrplibsession.py
Created August 30, 2011 17:40
_write method from msrplib session.py to send a file in chunks.
def _write_file(self):
outgoing_file = self.outgoing_files.items[0][0]
number_of_chunks = 0
while outgoing_file.position < outgoing_file.size:
try:
piece = outgoing_file.fileobj.read(self.FILE_PIECE_SIZE)
except Exception:
self.logger.err('error while reading file %r\n%s' % (outgoing_file, traceback.format_exc()))
return
self.logger.debug('_write_file: read %s bytes from %s' % (len(piece), outgoing_file))