Skip to content

Instantly share code, notes, and snippets.

Aleksandar Kostadinov akostadinov

Block or report user

Report or block akostadinov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@akostadinov
akostadinov / rails_test.rb
Last active Nov 9, 2016
Rails Active Record simple test
View rails_test.rb
# run by `ruby rails_test.rb`
# credits to https://github.com/rails/rails/issues/13744#issuecomment-32670636
gem 'activerecord', '5.0.0.1'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
@akostadinov
akostadinov / quine.rb
Created Jan 26, 2017
my first suboptimal ruby quine
View quine.rb
pr = %q{puts %{pr = %q{#{pr}}}, pr}
puts %{pr = %q{#{pr}}}, pr
@akostadinov
akostadinov / post_string_file.rb
Created Jan 26, 2017
ruby rest-client posting String as a file multipart/form-data
View post_string_file.rb
# rest-client recognizes files in multipart/form-data by checking
# the object type passed as the field content. We need to craft
# our string to appear as a file IO. `#stringfile` does that.
# An alternative approach is to just write string to a file and
# pass file IO to rest-client but this would be suboptimal
# provided we already have the content as a String.
def stringfile(string,
filename="file_#{rand 100000}",
type=MIME::Types.type_for("xml").first.content_type)
@akostadinov
akostadinov / xml_builder.rb
Created Jan 26, 2017
Building XML under Rails 5.
View xml_builder.rb
require 'builder'
# See more about syntax on
# http://api.rubyonrails.org/classes/ActionView/Base.html
# https://github.com/jimweirich/builder
# http://builder.rubyforge.org/
xml = +""
builder = Builder::XmlMarkup.new(target: xml, indent: 2)
builder.rootelementname { |x|
@akostadinov
akostadinov / pipeline_examples.groovy
Last active Jan 23, 2019
Jenkins Pipeline code Examples
View pipeline_examples.groovy
// clone in sub-directory
checkout([
$class: 'GitSCM',
branches: [[name: 'master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'some/path'
]],
submoduleCfg: [],
@akostadinov
akostadinov / timebench.groovy
Last active Nov 26, 2019
Benchmark Java Thread-Safe Time Formatter Implementations
View timebench.groovy
@Grapes([
@Grab(group='org.gperfutils', module='gbench', version='[0.4,)'),
@Grab(group='org.apache.commons', module='commons-lang3', version='[3.7,)'),
@Grab(group='joda-time', module='joda-time', version='[2.9.9,)')
])
/**
* Java 8 DateTimeFormatter
*/
import java.util.Date;
@akostadinov
akostadinov / xmr-stak.service
Last active Mar 18, 2020
Example xmr-stak systemd service unit file.
View xmr-stak.service
[Unit]
Description=xmr-stak miner
After=syslog.target network.target
[Service]
Type=simple
# interesting info about starting as regular user: https://bbs.archlinux.org/viewtopic.php?id=162297
User=username
LimitMEMLOCK=256M
EnvironmentFile=-/etc/sysconfig/xmr-stak
@akostadinov
akostadinov / storj.service
Created Jan 6, 2018
StorJ sharing node systemd init service file
View storj.service
# # useradd storj
# $ install storj node as user as described in
# https://docs.storj.io/v1.1/docs/setting-up-storj-share-on-a-raspberry-pi
# * use chrony instead of ntpd (non mandatory but it is better)
# * use instructions up to start-farming.sh
# $ write this file as ~/.config/systemd/user/storj.service
# # loginctl enable-linger myuser
# # reboot
# # su - myuser
# XDG needed for https://bugzilla.redhat.com/show_bug.cgi?id=1531890
View Low_Level_Format_Disk.md

A Low Level Format (LLF) means redefining physical disk layout. This is not doable by user on today's HDDs and SSDs. One usually want's to perform LLF to securely erase all data, reallocate bad sectors and/or remove malware.


[ATA Secure Erase][1]

Allows you to erase data on disk even on reallocated sectors. See:

@akostadinov
akostadinov / _http_continue.txt
Last active Mar 28, 2018 — forked from trevorrowe/client.rb
Ruby Net::HTTP Expect-100 continue PUT bug
View _http_continue.txt
# Start the sample server. This server alternates between responding with 100-continue and
# resopnding with a 403 Forbidden. The client **should** be able to handle both responses.
$ ruby server.rb
# In another terminal window, run the client code twice. The first invocation will succeed.
# The second invocation will fail the client with an error.
$ ruby client.rb
$ ruby client.rb
You can’t perform that action at this time.