Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Excelsior!

Sameer Kolhar kolharsam

🚀
Excelsior!
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am kolharsam on github.
  • I am kolharsam (https://keybase.io/kolharsam) on keybase.
  • I have a public key ASBjGCBJ9oW5F-QhszNQwHvt1N11lgF6DkXXQCBj0SX5PAo

To claim this, I am signing this object:

@kolharsam
kolharsam / string-conversions.hs
Created May 29, 2021 — forked from dino-/string-conversions.hs
A handy illustration of converting between String, Text and ByteString in Haskell
View string-conversions.hs
#! /usr/bin/env stack
-- stack --resolver lts-12.14 script
{-# LANGUAGE OverloadedStrings #-}
{-
This is a handy illustration of converting between five of the commonly-used
string types in Haskell (String, ByteString, lazy ByteString, Text and lazy
Text).
@kolharsam
kolharsam / handler.clj
Last active Mar 3, 2021
REST API in Clojure - Example for Hasura Actions
View handler.clj
;; This app was made using the template provided via leiningen.
;; use lein new compojure <project-name> to create a similar project
;; This content's of this file can directly go into `handler.clj`
;; All necessary documentation can be found in these sources:
;; https://github.com/weavejester/compojure/wiki
;; https://github.com/ring-clojure/ring/wiki
(ns rest-hasura-api.handler
(:require [compojure.core :refer :all]
@kolharsam
kolharsam / transducers.js
Last active Jan 14, 2021
Dabbling with Transducers in JS
View transducers.js
const list = [1,2,3,4,5,6,7,8,9];
const inc = x => x + 1;
const isOdd = x => x % 2 !== 0;
console.log(list.map(inc));
console.log(list.filter(isOdd))
console.log(list.map(inc).filter(isOdd))
console.log(list.reduce((acc, val) => {
if (isOdd(inc(val))) {
@kolharsam
kolharsam / move_zeroes.go
Last active Aug 17, 2020
Cassidy's Interview Question - 17/08/20
View move_zeroes.go
package main
import "fmt"
func moveZeros(numList []int) []int {
j := len(numList) - 1
// immutability ftw!
resList := make([]int, len(numList))
copy(resList, numList)
@kolharsam
kolharsam / poweroftwo.clj
Created Jun 1, 2020
Cassidy's Interview Question - 31/5/20
View poweroftwo.clj
;; Just wanted to take a different approach to using
;; logarithms or recursively dividing...
;; powers of 2, in binary, have only 1 bit as "1", so I'll look for just that!
(require '[clojure.string :as str])
(defn is-power-of-2?
"Returns true if n is a power of 2"
[n]
@kolharsam
kolharsam / editor.clj
Last active May 27, 2020
Cassidy's Interview Question - 24/5
View editor.clj
(def S (atom ""))
(def undo-stack (atom []))
(def redo-stack (atom []))
;; Helpers
(defn reset-stacks!
"Empties both stacks"
[]
(reset! undo-stack [])
@kolharsam
kolharsam / js_parser.clj
Created May 27, 2020 — forked from borkdude/js_parser.clj
Parse JavaScript in Clojure using the Google Closure Compiler
View js_parser.clj
#!/bin/sh
#_(
"exec" "clojure" "-Sdeps" "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.520\"}}}" "$0" "$@"
)
;; running js_parser.clj "function foo(x) { var y = x + 1; }" will print:
;; [{:type :function, :name "foo", :body [{:variable-statement [{:lvalue "y", :initializer {:type :binary-op, :left "x", :operator "+", :right "1"}}]}], :params ["x"]}]
@kolharsam
kolharsam / css-parser.md
Created May 22, 2020 — forked from kachayev/css-parser.md
Parsing CSS file with monadic parser in Clojure
View css-parser.md
@kolharsam
kolharsam / monads.clj
Created May 17, 2020 — forked from lispyclouds/monads.clj
Monads, simple made easier
View monads.clj
; A simple demo of monadic composition of side effects
; Program to take 3 nubers as input and print their sum.
(defn read-and-add!
[prev]
(print "Enter a number: ")
(+ prev (do (flush)
(Integer/parseInt (read-line)))))
(defn bind