Skip to content

Instantly share code, notes, and snippets.

View arpitchauhan's full-sized avatar

Arpit Chauhan arpitchauhan

  • Solaris Digital Assets
  • Berlin
View GitHub Profile
@arpitchauhan
arpitchauhan / monad.md
Last active July 2, 2019 19:02
Using Monads

Monads

Understanding Monads

A concise definition from Wikipedia:

In functional programming, a monad is a design pattern that defines how functions, operations, inputs, and outputs can be used together to build generic types, with the following organization:

a. Define a data type, and how values of that data type are combined. b. Create functions that use the data type, and compose them together into operations, following the rules defined in the first step.

@arpitchauhan
arpitchauhan / config.ru
Created September 11, 2018 20:10
sinatra-app-to-host-files > config.ru
require './server'
run Sinatra::Application
# To flush output immediately
$stdout.sync = true
@arpitchauhan
arpitchauhan / server.rb
Last active September 11, 2018 20:12
sinatra-app-to-host-files > server.rb (Version 2)
require 'sinatra'
require_relative 'basic_auth'
BasicAuth.enable_if_possible
@arpitchauhan
arpitchauhan / basic_auth.rb
Last active September 11, 2018 19:56
sinatra-app-to-host-files > basic_auth.rb
class BasicAuth
class << self
def enable_if_possible
return unless on?
Sinatra::Application.use(Rack::Auth::Basic) do |username, password|
valid_credentials?(username, password)
end
end
@arpitchauhan
arpitchauhan / server.rb
Created September 11, 2018 19:46
sinatra-app-to-host-files > server.rb (Version 1)
# server.rb
require 'sinatra'
@arpitchauhan
arpitchauhan / Gemfile
Created September 11, 2018 19:41
sinatra-app-to-host-files > Gemfile
source "https://rubygems.org"
ruby '2.5.1'
gem 'sinatra', '~> 2.0'
@arpitchauhan
arpitchauhan / Gemfile
Created September 11, 2018 11:52
Creating a Minimal Sinatra App For Hosting Test Files
source "https://rubygems.org"
ruby '2.5.1'
gem 'sinatra', '~> 2.0'

Keybase proof

I hereby claim:

  • I am arpitchauhan on github.
  • I am arpitchauhan (https://keybase.io/arpitchauhan) on keybase.
  • I have a public key whose fingerprint is 9ED4 1E1F FA8F 750C 11EE 6B15 A359 EE80 337B 31E3

To claim this, I am signing this object:

@arpitchauhan
arpitchauhan / error
Created October 21, 2012 00:33
SQLException near ","
@movies = Movie.where("rating IN :ratings;" , {:ratings => params.has_key?(:ratings) ? params[:ratings].keys : @all_ratings})
The error page:
ActiveRecord::StatementInvalid in Movies#index
SQLite3::SQLException: near ",": syntax error: SELECT "movies".* FROM "movies" WHERE (rating IN 'G','PG','PG-13','R','NC-17')
Full Trace:
sqlite3 (1.3.5) lib/sqlite3/database.rb:91:in `initialize'
sqlite3 (1.3.5) lib/sqlite3/database.rb:91:in `new'