Skip to content

Instantly share code, notes, and snippets.

View vitaly-pushkar's full-sized avatar

Vitaly Pushkar vitaly-pushkar

View GitHub Profile
require 'benchmark'
def fibonacci(n)
def fib(current, nxt, n)
return current if n == 0
fib(nxt, current + nxt, n - 1)
end
fib(0, 1, n)
# app/classes/examples/example.rb
module Examples
class Example
'blabla'.constantize #NoMethodError: undefined method `constantize' for Examples::Example
end
end
(defvar clojure-packages
'(
clojure-mode
cider
))
(defun clojure/init-cider ()
(use-package cider
:init
:mode ("\\.clj\\'" "\\.cljs\\'" . clojure-mode)
;; src/clj/me/front-office/handlers.clj
(ns me.front-office.handlers)
(defn me [] ...)
(defn login [] ...)
(defn logout [] ...)
import Html exposing (..)
import Html.App as Html
import Html.Events exposing (..)
import Html.Attributes exposing (src)
import Random
main =
Html.program

Keybase proof

I hereby claim:

  • I am vitaly-pushkar on github.
  • I am pshk4r (https://keybase.io/pshk4r) on keybase.
  • I have a public key whose fingerprint is 3E2C 6703 DA33 3DD6 F718 4FF4 22E5 2E81 5D58 FC86

To claim this, I am signing this object:

@vitaly-pushkar
vitaly-pushkar / test.scala
Last active January 4, 2017 07:14
Excercise 2.2
// implement isSorted, which checks whether an Array[A] is sorted according to a given comparison function:
// def isSorted[A] (as: Array[A], ordered: (A, A) => Boolean): Boolean
object Test {
def isSorted[A](as: Array[A], ordered: (A, A) => Boolean): Boolean = {
def loop(n: Int): Boolean =
if (n+1 >= as.length) true
else if (!ordered(as(n), as(n+1))) false
else loop(n+1)

Keybase proof

I hereby claim:

  • I am vitaly-pushkar on github.
  • I am pshk4r (https://keybase.io/pshk4r) on keybase.
  • I have a public key ASA2hL6yQsXIZKVTrWaRn1Htv26UwrFThgrbrZIrwkkzdgo

To claim this, I am signing this object:

@vitaly-pushkar
vitaly-pushkar / ChangingMoney.scala
Last active January 11, 2018 09:29
Changing money problem solved recursively in Scala with a greedy approach
import scala.annotation.tailrec
object ChangingMoney extends App {
val money = scala.io.StdIn.readInt()
// canonical coin system; this algorithm will not work optimally for arbitrary coin systems
val coins = List(10, 5, 1)
println(changeMoney(money))
@vitaly-pushkar
vitaly-pushkar / db_setup.rb
Created January 23, 2020 20:04
From the blog post "Error Handling with Either Monads in Ruby"
ActiveRecord::Base.establish_connection( adapter: 'sqlite3', database: ":memory:" )
ActiveRecord::Schema.define(version: 1) { create_table(:users) { |t| t.string :name; t.string :email } }
class User < ActiveRecord::Base; end
User.create(name: 'Vitaly', email: 'vitaly.pushkar@gmail.com')