Skip to content

Instantly share code, notes, and snippets.

View thebugcatcher's full-sized avatar
Turbo mode!

Adi Iyengar thebugcatcher

Turbo mode!
View GitHub Profile
@thebugcatcher
thebugcatcher / n_primes.ex
Last active February 1, 2021 09:48
Find if a number is prime in elixir and get a list of primes.
# Given an input, this program returns a list of all primes numbers less than the input.
defmodule NPrimes do
def get_primes(n) when n < 2, do: []
def get_primes(n), do: Enum.filter(2..n, &is_prime?(&1))
defp is_prime?(n) when n in [2, 3], do: true
defp is_prime?(x) do
start_lim = div(x, 2)
Enum.reduce(2..start_lim, {true, start_lim}, fn(fac, {is_prime, upper_limit}) ->
@thebugcatcher
thebugcatcher / num_unique_perms.ex
Created January 10, 2017 14:49
Number of unique permutations of a string.
# Given a string, string, you have to find out the number of unique strings
# (including string itself) that can be produced by re-arranging the letters
# of the string.
# Example:
#
# string = "ABC"
#
# uniqcount(string) = 6 #=> ["ABC", "ACB", "BAC", "BCA", "CAB", "CBA"]
#
# Notes: Find the number of UNIQUE strings!
# In mathematics, this is called a fixpoint. We pass an argument to a function and the result is that argument.
# Here the argument is the factorial function. It could just be a number; for example, zero and
# one are fixpoints of x = x ^2 (x squared). In lambda calculus speak, when H is applied to factorial
# the result is factorial. Or, calling H with argument factorial returns factorial. factorial is a fixpoint of H.
# H.call(factorial_with_H).call(5)
# ------------------------------------------------------------------------
# FizzBuzz
# ------------------------------------------------------------------------
@thebugcatcher
thebugcatcher / rummage_example_router_1.ex
Last active March 7, 2017 20:57
Rummage Introduction
defmodule RummageExample.Router do
use RummageExample.Web, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
defmodule RummageExample.Product do
use RummageExample.Web, :model
use Rummage.Ecto, repo: RummageExample.Repo, per_page: 2 # <-- Add this
schema "products" do
field :name, :string
field :category, :string
field :quantity, :integer
timestamps()
@thebugcatcher
thebugcatcher / index.html.eex
Last active March 7, 2017 21:15
Add category_name to products index
<h2>Listing products</h2>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Category</th>
<th></th>
@thebugcatcher
thebugcatcher / .block
Created April 16, 2019 16:56
test donut
license: mit
@thebugcatcher
thebugcatcher / keybase.md
Last active June 21, 2020 21:13
For keybase verification

Keybase proof

I hereby claim:

  • I am aditya7iyengar on github.
  • I am aditya7iyengar (https://keybase.io/aditya7iyengar) on keybase.
  • I have a public key whose fingerprint is F956 2A78 29A7 D4C5 2FCE 7ED5 B2BC 1EDB 6C09 4020

To claim this, I am signing this object:

@thebugcatcher
thebugcatcher / gen_test_utils_module.ex
Last active March 16, 2022 19:58
Elixir helper module to test whether a function is delegated to another module.
defmodule GenTestUtils.Module do
@moduledoc """
Helper functions to test parts of an Elixir module
"""
require ExUnit.Assertions
@doc """
Tests whether a module delegates a given MFA to another given MFA
# Usage
@thebugcatcher
thebugcatcher / paperform_splits.html
Last active April 6, 2022 16:22
Code to enable splits in Paperform + Bulma.css
<!-- Add Bulma for Columns (best way is to add this to the theme, but adding it here
so it can be easily re-used) -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.3/css/bulma.min.css" integrity="sha512-IgmDkwzs96t4SrChW29No3NXBIBv8baW490zk5aXvhCD8vuZM3yUSkbyTBcXohkySecyzIrUwiF/qV0cuPcL3Q==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script>
// assign elements
const editorRoot = document.getElementsByClassName("DraftEditor-root")[0]
const editorContainer = document.getElementsByClassName("DraftEditor-editorContainer")[0]
var splitImageColumn = document.getElementById('splitImageColumn')