Skip to content

Instantly share code, notes, and snippets.

@wvengen
wvengen / README.md
Last active March 25, 2024 07:53
Ruby memory analysis over time

Finding a Ruby memory leak using a time analysis

When developing a program in Ruby, you may sometimes encounter a memory leak. For a while now, Ruby has a facility to gather information about what objects are laying around: ObjectSpace.

There are several approaches one can take to debug a leak. This discusses a time-based approach, where a full memory dump is generated every, say, 5 minutes, during a time that the memory leak is showing up. Afterwards, one can look at all the objects, and find out which ones are staying around, causing the

@RadhikaG
RadhikaG / heapClass.py
Last active December 13, 2017 04:04
A class to demonstrate the different operations on heaps.
def parent(i):
return i/2
def left(i):
return 2*i
def right(i):
return (2*i + 1)
class Heap:
@RadhikaG
RadhikaG / heap.py
Last active December 13, 2016 13:57
A short script to demonstrate the different operations on heaps.
global heap
global currSize
def parent(i): #returns parent index of ith index
return i/2
def left(i): #returns left child of ith index
return 2*i
def right(i): #returns right child of ith index
@ChuckJHardy
ChuckJHardy / example_activejob.rb
Last active May 10, 2024 20:10
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
@pixeltrix
pixeltrix / time_vs_datatime.md
Last active February 18, 2024 19:20
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
@janko
janko / 01-activerecord.rb
Created May 27, 2015 22:50
PostgreSQL JSON querying in Sequel (my presentation from our local Ruby meetup)
require "active_record"
ActiveRecord::Base.establish_connection('postgres:///testing')
ActiveRecord::Migration.verbose = false
ActiveRecord::Migration.class_eval do
create_table :played_quizzes, force: true do |t|
t.integer :player_ids, array: true
t.json :quiz_snapshot
end
@mr-linch
mr-linch / weblancer.py
Last active November 4, 2023 18:17
Исходный код для урока (https://youtu.be/KPXPr-KS-qk)
#!/usr/bin/env python3
import csv
import urllib.request
from bs4 import BeautifulSoup
BASE_URL = 'http://www.weblancer.net/projects/'
@lolzballs
lolzballs / HelloWorld.java
Created March 22, 2015 00:21
Hello World Enterprise Edition
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
public class HelloWorld{
private static HelloWorld instance;
public static void main(String[] args){
instantiateHelloWorldMainClassAndRun();
@itsthatguy
itsthatguy / foo.coffee
Last active August 29, 2015 14:16
Coffeescript Classes: object.prototype.function and object.function demonstrated
# Run the following command in shell:
# curl -s https://gist.githubusercontent.com/itsthatguy/48d9b47dba05b300c65b/raw/80b1111bb5273697d1db4f5662eb763aa4a80cdc/foo.coffee | coffee --stdio
class Foo
name: 'abott'
@myFunction: ->
console.log "\n# start"
console.log "\nFoo"
console.log "this.name:", this.name
myOtherFunction: ->
console.log "\nfoo (instance of Foo)"
@solnic
solnic / require_measure.rb
Last active August 29, 2015 14:14
A hack to measure how long it takes to require bundled gems in a rails app
REQUIRE_DATA = {}
BUNDLED_GEMS = `bundle show | grep "*" | awk '{print $2}'`.split("\n").sort
require 'bigdecimal'
def require(name)
start = Time.now
ret = super
stop = Time.now
total = BigDecimal(stop-start, 6)
REQUIRE_DATA[name] = total if BUNDLED_GEMS.include?(name)