Skip to content

Instantly share code, notes, and snippets.

View akostadinov's full-sized avatar

Aleksandar N. Kostadinov akostadinov

View GitHub Profile
@akostadinov
akostadinov / xml_builder.rb
Created January 26, 2017 10:37
Building XML under Rails 5.
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 / storj.service
Created January 6, 2018 15:09
StorJ sharing node systemd init service file
# # 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
@akostadinov
akostadinov / _http_continue.txt
Last active March 28, 2018 12:47 — forked from trevorrowe/client.rb
Ruby Net::HTTP Expect-100 continue PUT bug
# 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
@akostadinov
akostadinov / recaptcha.php
Created April 1, 2018 20:17
Joomla 2.5 reCaptcha patch to support 2.0 API
<?php
/**
* @package Joomla.Plugin
* @subpackage Captcha
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @note Sorry for the ugliness, just a quick patch to make this work with the 2.0 API, it also connects through TLS now. Just replace original plugins/captcha/recaptcha/recaptcha.php
*/
@akostadinov
akostadinov / monty.rb
Created January 2, 2019 14:46
Monty Hall empirical proof
require 'test/unit'
# Read about the problem and mathematical proof here:
# http://www.greenteapress.com/thinkbayes/html/thinkbayes002.html#sec15
class MontyHall
include Test::Unit::Assertions
NUM_DOORS = 3
@akostadinov
akostadinov / fahclient.service
Last active March 18, 2020 17:31
fahclient.service
[Unit]
Description=FAHClient cruncher
After=syslog.target network.target
[Service]
Type=simple
User=fahclient
WorkingDirectory=/var/lib/fahclient
EnvironmentFile=-/etc/sysconfig/fahclient
# log will go fahclient home dir
@akostadinov
akostadinov / pipeline_examples.groovy
Last active April 15, 2020 14:11
Jenkins Pipeline code Examples
// clone in sub-directory
checkout([
$class: 'GitSCM',
branches: [[name: 'master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'some/path'
]],
submoduleCfg: [],
@akostadinov
akostadinov / touchpad_toggle.sh
Created April 19, 2020 15:20
Turn on and off a libinput device.
# the above works with synaps driver
DEV="SynPS/2 Synaptics TouchPad"
# DEV="Synaptics TM3053-006"
toggle_touchpad () {
local enabled=`xinput list-props "$DEV" | awk '/Device Enabled/{ print $4 }'`
case "$enabled" in
0) xinput enable "$DEV"
;;
1) xinput disable "$DEV"
;;
@akostadinov
akostadinov / post_string_file.rb
Created January 26, 2017 10:19
ruby rest-client posting String as a file multipart/form-data
# 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 / jenkins-job-param.groovy
Last active October 16, 2020 21:41
Jenkins Job deafault value of parameter of a job
job = Jenkins.getInstance().getItem("Flexy-install")
println job.getProperty(ParametersDefinitionProperty.class)?.getParameterDefinition("REPOSITORIES")?.getDefaultParameterValue()
/*
License: https://en.wikipedia.org/wiki/WTFPL
Some readers:
https://support.cloudbees.com/hc/en-us/articles/226941767-Groovy-to-list-all-jobs
https://medium.com/@mukeshsingal/update-default-values-of-jenkins-job-parameters-416de5ff9f96
https://javadoc.jenkins.io/hudson/model/Job.html