Skip to content

Instantly share code, notes, and snippets.

const SegfaultHandler = require('segfault-handler');
SegfaultHandler.registerHandler('crash.log');
const { PrismaClient } = require('@prisma/client');
async function main() {
const prisma = new PrismaClient();
const { id } = await prisma.notification.create({ data: { to: "test@example.com" } });
console.log(id)
}
# threads dying on fork examples. run with:
# ruby main.rb
# or
# ruby main.rb fork
#
require 'thread'
class Worker
def initialize
@thread = Thread.new { work }
@felipeelias
felipeelias / genetic.rb
Created March 30, 2018 14:50
Genetic algorithm
class Chromosome
SIZE = 10
attr_reader :value
def initialize(value)
@value = value
end
def fitness
require "ecr"
class Greeting
# def wrap(tag)
# String.build do |str|
# str << "<#{tag}>"
# str << yield
# str << "</#{tag}>"
# end
# end
@felipeelias
felipeelias / reference.md
Last active April 14, 2017 11:39
References of various topics

Keybase proof

I hereby claim:

  • I am felipeelias on github.
  • I am felipeelias (https://keybase.io/felipeelias) on keybase.
  • I have a public key ASCXvgXFgRDO3gzYvfR9Q2V2K9pra4RL5kv-r8M3EoKmfQo

To claim this, I am signing this object:

@felipeelias
felipeelias / pubsub.ex
Last active March 24, 2016 20:34
PubSub server
defmodule Pubsub do
use Application
def start(_type, _options) do
import Supervisor.Spec
IO.puts("Initializing Pubsub app on #{inspect self}")
children = [
worker(Pubsub.Server, [], [name: :server_supervisor])
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
var wg sync.WaitGroup
LaundryMachine washer = getLaundryMachine();
washer.open();
List<Unerdwear> pileOfUnerdwear = gatherUnerdwear();
for (Unerdwear underwear : pileOfUnerdwear) {
if (underwear.isDirty() OR underwear.isSticky()) {
washer.load(underwear);
} else {
putOn(underwear);
while (undewear.isntDirty()) {
@felipeelias
felipeelias / spec_helper.rb
Last active December 10, 2015 17:48
Simple 'database cleaner' approach using `config.around`. Was able to cut down some seconds out of the suite. Thanks to @brandonhilkert
RSpec.configure do |config|
config.around do |example|
# For examples using capybara-webkit for example.
# Remove this if you don't use it or anything similar
if example.metadata[:js]
example.run
ActiveRecord::Base.connection.execute("TRUNCATE #{ActiveRecord::Base.connection.tables.join(',')} RESTART IDENTITY")
else
ActiveRecord::Base.transaction do