Skip to content

Instantly share code, notes, and snippets.

Avatar

Sam Goldman samwgoldman

View GitHub Profile
View a.diff
index 3ef907960..5de2e0e85 100644
--- a/runtime/compare.c
+++ b/runtime/compare.c
@@ -133,7 +133,8 @@ static intnat do_compare_val(struct compare_stack* stk,
return Long_val(v1) - Long_val(v2);
/* Subtraction above cannot overflow and cannot result in UNORDERED */
#ifndef NO_NAKED_POINTERS
- if (Is_in_value_area(v2)) {
+ if (!Is_in_value_area(v2))
+ return LESS;
@samwgoldman
samwgoldman / jsverify.js
Created Nov 14, 2015
First pass at Flow interface file for jsverify
View jsverify.js
declare module "jsverify" {
// Either
declare interface Either<A,B> {
either<T>(l: (a: A) => T, r: (b: B) => T): T;
isEqual(other: Either<A,B>): boolean;
bimap<C,D>(f: (a: A) => C, g: (b: B) => D): Either<C,D>;
first<C>(f: (a: A) => C): Either<C,B>;
second<D>(g: (b: B) => D): Either<A,D>;
View maybe.js
/* @flow */
type Maybe2<T,U> = (pattern: {
some: (x: T) => U,
none: () => U
}) => U;
type Maybe<T> = Maybe2<T, *>;
// Constructors
View cyclic.js
var foo = {}
Object.defineProperty(foo, "bar", {
enumerable: true,
get: function() {
return bar;
}
})
var bar = { foo: foo }
foo.bar.foo === foo // true
@samwgoldman
samwgoldman / example.js
Last active Mar 14, 2019
Pure, stateless, type-checked React components with Immutable.js and Flow
View example.js
/* @flow */
var React = require("react")
var Immutable = require("immutable")
// In order to use any type as props, including Immutable objects, we
// wrap our prop type as the sole "data" key passed as props.
type Component<P> = ReactClass<{},{ data: P },{}>
type Element = ReactElement<any, any, any>
@samwgoldman
samwgoldman / result.rb
Last active Aug 29, 2015
success/failure result object
View result.rb
module Result
class << self
def success(value)
Success.new(value)
end
def failure(error)
Failure.new(error)
end
end
View gist:1fcceea36206e1544414
/* @flow */
type Maybe<T,U> = (pattern: {
some(x: T): U;
none(): U;
}) => U;
function map<A,B,C>(maybe: Maybe<A,C>, f: (a: A) => B): Maybe<B,C> {
return function(pattern) {
return maybe({
@samwgoldman
samwgoldman / main.rb
Last active Aug 29, 2015
TorqueBox testing issue
View main.rb
require "capybara"
require "capybara/poltergeist"
require "torquebox-web"
require "torquebox-messaging"
page = DATA.read
app = proc do
headers = {
"Content-Type" => "text/html",
"Content-Length" => page.length.to_s
View result.rb
module Result
class << self
def not_nil(value)
if value.nil?
None
else
Some.new(value)
end
end
View gist:9610193
access_key_id = ENV.fetch("APP_S3_ACCESS_KEY_ID")
secret_access_key = ENV.fetch("APP_S3_SECRET_ACCESS_KEY")
bucket_name = ENV.fetch("APP_S3_BUCKET")
s3 = AWS::S3.new(access_key_id: access_key_id, secret_access_key: secret_access_key)
bucket = s3.buckets[bucket_name]
object = bucket.objects["whatever/you/want"]
presign = AWS::S3::PresignV4.new(object)
presign.presign(:put, expires: 15.minutes.from_now.to_i)
# => #<URI::HTTP:0x007fcfcd97e1a0 URL:***stuff***>
You can’t perform that action at this time.