Skip to content

Instantly share code, notes, and snippets.

View tadast's full-sized avatar

Tadas Tamošauskas tadast

View GitHub Profile
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
container:
image: ruby:2.6.5

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@brianhempel
brianhempel / bench_rails_memory_usage.rb
Last active October 6, 2022 12:47
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
@Flafla2
Flafla2 / Perlin_Tiled.cs
Last active February 19, 2024 16:29
A slightly modified implementation of Ken Perlin's improved noise that allows for tiling the noise arbitrarily.
public class Perlin {
public int repeat;
public Perlin(int repeat = -1) {
this.repeat = repeat;
}
public double OctavePerlin(double x, double y, double z, int octaves, double persistence) {
double total = 0;
@aseemk
aseemk / coffeescript-updates.md
Last active December 2, 2017 20:22
CoffeeScript upcoming changes.

CoffeeScript 1.7 is shaping up to be a pretty kick-ass release with significant improvements. Here are the ones I'm most excited about, in order of my own excitement.

Parentheses-free chaining

jashkenas/coffeescript#3263

Years of being wished for, finally granted!

@peterc
peterc / methods_returning.rb
Last active October 29, 2023 03:10
Object#methods_returning - to work out which method on an object returns what we want
require 'stringio'
require 'timeout'
class Object
def methods_returning(expected, *args, &blk)
old_stdout = $>
$> = StringIO.new
methods.select do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false
Ruby 2.1.0 in Production: known bugs and patches
Last week, we upgraded the github.com rails app to ruby 2.1.0 in production.
While testing the new build for rollout, we ran into a number of bugs. Most of
these have been fixed on trunk already, but I've documented them below to help
anyone else who might be testing ruby 2.1 in production.
@naruse I think we should backport these patches to the ruby_2_1 branch and
release 2.1.1 sooner rather than later, as some of the bugs are quite critical.
I'm happy to offer any assistance I can to expedite this process.
@sepastian
sepastian / multi_cartesian_product.rb
Last active January 11, 2023 09:26
Build the cartesian product of multiple arrays in Ruby.
# Given an array of arrays s = [ [1,2,3], [4,5,6], ... ]
# compute the Cartesian product among the elements of s.
require 'pp'
s = [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
pp s[1..-1].inject(s[0]){ |m,v| m = m.product(v).map(&:flatten) }
[[1, 3, 6],
[1, 3, 7],
[1, 3, 8],
$ = jQuery
$.fn.lineHeight or= ->
if height = @data('lineHeight')
return height
# Create a hidden div with the same font
# properties, then measure its height
$shadow = $('<span />')
$shadow.css({
@willurd
willurd / web-servers.md
Last active April 26, 2024 18:00
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000