Skip to content

Instantly share code, notes, and snippets.

View pigoz's full-sized avatar
:octocat:

Stefano Pigozzi pigoz

:octocat:
View GitHub Profile
@pigoz
pigoz / server.rb
Created October 17, 2016 15:29
AWS S3 Presigned Post upload in JavaScript with FormData
post = Aws::S3:Bucket.new('XXXXX').presigned_post(
key: "uploads/tmp/#{SecureRandom.uuid}/${filename}",
success_action_status: '201',
acl: 'public-read')
{ url: post.url.to_s, fields: post.fields }.to_json
import { pipe } from '@fp-ts/core/Function';
import * as A from '@fp-ts/core/ReadonlyArray';
import * as HashMap from '@effect/data/HashMap';
import { dual } from '@fp-ts/core/Function';
const compare = {
number: (a: number, b: number) => a - b,
string: (a: string, b: string) =>
a.localeCompare(b, 'en', { sensitivity: 'base' }),
Date: (a: Date, b: Date) => a.getTime() - b.getTime(),
@pigoz
pigoz / Page.tsx
Last active January 10, 2023 10:12
impport * as Z from '@effect/io/Effect';
export { loader } from '~/runtime';
export const zloader: Z.Effect<..., ..., ...> = currentUserOrRedirect($path('/login'));
There was an error running the data loader for route routes/dashboard.posts
Error: Service not found
at /Users/pigoz/dev/superagent/node_modules/src/internal/Context.ts:130:13
at Object.successK (/Users/pigoz/dev/superagent/node_modules/@effect/io/src/internal/core.ts:915:60)
at Object.4 (/Users/pigoz/dev/superagent/node_modules/@effect/io/src/internal/fiberRuntime.ts:96:17)
at FiberRuntime.6 (/Users/pigoz/dev/superagent/node_modules/@effect/io/src/internal/fiberRuntime.ts:980:36)
at FiberRuntime.runLoop (/Users/pigoz/dev/superagent/node_modules/@effect/io/src/internal/fiberRuntime.ts:1173:47)
at FiberRuntime.evaluateEffect (/Users/pigoz/dev/superagent/node_modules/@effect/io/src/internal/fiberRuntime.ts:785:29)
at FiberRuntime.start (/Users/pigoz/dev/superagent/node_modules/@effect/io/src/internal/fiberRuntime.ts:840:14)
at RuntimeImpl.unsafeRunWith (/Users/pigoz/dev/superagent/node_modules/@effect/io/src/internal/runtime.ts:98:18)
export const pool = (name: string, self: DbTest) => {
return it(name, async () => {
return await zdb.serializable(pgpool, async conn => {
await self(conn);
await zdb.sql`ROLLBACK`.run(conn);
});
});
};
import * as E from '@fp-ts/data/Either';
import * as Z from '@effect/io/Effect';
import * as Context from '@fp-ts/data/Context';
import { pipe } from '@fp-ts/data/Function';
import {
DataFunctionArgs as DataFunctionArgs_,
// LoaderFunction,
// TypedResponse,
// AppLoadContext,
json,
@pigoz
pigoz / http.ts
Created November 27, 2022 10:53
playing around with Effect/io
import { pipe } from '@fp-ts/data/Function';
import * as E from '@fp-ts/data/Either';
import * as Effect from '@effect/io/Effect';
// import * as Layer from '@effect/io/Layer';
// import * as Context from '@fp-ts/data/Context';
import { z } from 'zod';
import debug_ from 'debug';
export function decode<T>(schema: z.ZodSchema<T>) {
return (input: unknown): E.Either<z.ZodError<T>, T> => {
@pigoz
pigoz / gist:5594454
Last active April 23, 2021 03:57
mach_wait_until()
#include <stdio.h>
#include <mach/clock.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/select.h>
void clock_gettime(struct mach_timespec *mts) {
@pigoz
pigoz / ruby_sql_to_csv.rb
Created May 31, 2011 13:04
Ruby SQL to CSV exporter
require "rubygems"
begin
require 'sequel'
rescue LoadError
puts "Please run gem install sequel"
exit!
end
DB = Sequel.connect(:adapter => 'mysql2',
:host => '127.0.0.1',
@pigoz
pigoz / config_development.rb
Last active July 26, 2020 16:24
puma cluster mode + sidekiq
threads 1, 4
workers 2
preload_app!
environment 'development'
bind 'tcp://0.0.0.0:3000'
ssl_bind '127.0.0.1', '5002', {
key: 'doc/certs/server.key',
cert: 'doc/certs/server.crt'
}