Skip to content

Instantly share code, notes, and snippets.

View michaelfranzl's full-sized avatar
🖥️
Developing software

Michael Franzl michaelfranzl

🖥️
Developing software
View GitHub Profile
@ascendbruce
ascendbruce / gist:7070911
Created October 20, 2013 15:13
Ruby get current file full path (absolute path)
File.expand_path(File.dirname(__FILE__))
# If you want to require some files in different directory, in ruby 1.9, you may want to use:
require_relative "../xxxlib"
@nruth
nruth / tests_spec.rb
Created July 30, 2010 20:48
how not to loop/nest rspec example groups (where you want to iterate diferent let/before variable values)
class Tests
SUBTESTS = %w(Abstract Decision Quantitative Verbal)
end
describe Tests do
describe "before assigning @ - " do
describe "this doesn't work because the loops are all at the same describe level (the befores override one another)" do
Tests::SUBTESTS.each do |test|
before(:each) do
@whatthewhat
whatthewhat / gist:cb6a62532a8a0984adbe
Created July 21, 2014 09:03
Find scheduled sidekiq job by id
require 'sidekiq/api'
Sidekiq::ScheduledSet.new.find_job("61374d5d51db323507376158")
@tmm1
tmm1 / gist:61762
Created February 11, 2009 01:55
FAQ about MRI internals
> - In ruby 1.8.x, what is the functional difference between rb_thread_schedule and rb_thread_select?
rb_thread_schedule() is the guts of the thread scheduler, it traverses
over the linked list of threads (several times) to find the next one
to switch into. The function is long (250 lines) and messy, and covers
all the combinations of thread status (RUNNABLE, TO_KILL, STOPPED,
KILLED) and wait state (FD, SELECT, TIME, JOIN, PID).
If there are no threads doing i/o or waiting on a timeout,
rb_thread_schedule() picks another thread from the list (considering
@Integralist
Integralist / asyncio.wait.py
Last active May 25, 2022 11:55
[Wait for multiple Python futures to finish using asyncio.wait()] #asyncio #wait #concurrency #multiple #requests #httpclient
import time
import asyncio
import requests
domain = 'http://integralist.co.uk'
a = '{}/foo?run={}'.format(domain, time.time())
b = '{}/bar?run={}'.format(domain, time.time())
async def get(url):
print('start: ', url)
@AntonTyutin
AntonTyutin / sendmail.sh
Last active June 9, 2022 11:37
A stub of "sendmail" command. Appends mail to file instead of send it to mail server. Depends on Perl and its "MIME::QuotedPrint" module.
#!/bin/bash
MAIL_LOG=${LOG_DIR:-/var/log}/mails.log
echo '== [' $(date +%Y-%m-%d_%H-%M-%S) '] ==' >> $MAIL_LOG
perl -MMIME::QuotedPrint -pe '$_=MIME::QuotedPrint::decode($_);' | tee -a $MAIL_LOG > /dev/null
@stympy
stympy / skcluster.rb
Created February 8, 2017 20:53
Sidekiq cluster control script and systemd service
#!/usr/bin/env ruby
require 'sidekiq'
require 'sidekiq/cli'
# Default to running one process per core
def process_count
return ENV['SK_PROCESS_COUNT'].to_i unless ENV['SK_PROCESS_COUNT'].to_i == 0
case RbConfig::CONFIG['host_os']
cpanm -l local https://github.com/<user_name>/<repo_name>/tarball/<branch_name>
e.g.
cpanm -l local https://github.com/issm/p5-Amon2-Plugin-Model/tarball/master
@mperham
mperham / frag.rb
Last active April 26, 2023 18:22
memory fragmentation on ruby 2.5.1
=begin
This script attempts to reproduce poor glibc allocator behavior within Ruby, leading
to extreme memory fragmentation and process RSS bloat.
glibc allocates memory using per-thread "arenas". These blocks can easily fragment when
some objects are free'd and others are long-lived.
Our script runs multiple threads, all allocating randomly sized "large" Strings between 4,000
and 40,000 bytes in size. This simulates Rails views with ERB creating large chunks of HTML
to output to the browser. Some of these strings are kept around and some are discarded.
@sj26
sj26 / sidekiq.service
Last active July 4, 2023 19:20 — forked from dsadaka/\lib\systemd\system\sidekiq-static.service
systemd unit files for multiple sidekiq workers
[Unit]
Description=Sidekiq workers
# start as many workers as you want here
Wants=sidekiq@1.service
Wants=sidekiq@2.service
# ...
[Service]
Type=oneshot
ExecStart=/bin/true