Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View sunaku's full-sized avatar

Suraj N. Kurapati sunaku

View GitHub Profile
@sunaku
sunaku / README.md
Last active December 12, 2023 16:00
Sunaku's Symbol Layer adapted to Dygma Defy keyboard
@sunaku
sunaku / set-option
Created October 31, 2013 04:19
Listing of all tmux 1.8 options vs. window options.
set-option [-agoqsuw] [-t target-session | target-window] option value
buffer-limit number
escape-time time
exit-unattached [on | off]
quiet [on | off]
set-clipboard [on | off]
Available session options are:
assume-paste-time milliseconds
base-index index
bell-action [any | none | current]
@sunaku
sunaku / shed
Last active July 30, 2020 02:16
POSIX shell script equivalent of https://github.com/mplewis/shed
#!/bin/sh -e
#
# POSIX shell script equivalent of:
# <https://github.com/mplewis/shed>
#
# Usage: shed [SHELL_ARGUMENTS...]
#
# Executes stdin after you edit it.
# If $EDITOR is unset, uses $PAGER.
# If $PAGER is unset, uses cat(1).
@sunaku
sunaku / fizzbuzz.exs
Last active July 14, 2020 18:10
A functional FizzBuzz (without any integer modulus or division) in Elixir. See https://pragprog.com/magazines/2012-08/thinking-functionally-with-haskell
# A functional FizzBuzz (without any integer modulus or division) in Elixir
# https://pragprog.com/magazines/2012-08/thinking-functionally-with-haskell
nums = Stream.iterate(1, &(&1 + 1))
fizz = Stream.cycle ["", "", "Fizz"]
buzz = Stream.cycle ["", "", "", "", "Buzz"]
fizzbuzz = Stream.zip(fizz, buzz) |> Stream.zip(nums) |> Stream.map(fn
{{"", "" }, number} -> number
{{fizzword, buzzword}, _number} -> fizzword <> buzzword
end)
fizzbuzz |> Stream.take(100) |> Enum.each(&IO.puts/1)
@sunaku
sunaku / STDOUT
Last active May 25, 2018 20:48 — forked from courtenay/STDOUT
Further refinement of @jcemer's modifications at <https://gist.github.com/courtenay/5454972#comment-912976> Strictly speaking, we're generating [URI fragments](http://en.wikipedia.org/wiki/Fragment_identifier), not permalinks.
$ irb
## ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
>> require './github_style_titles.rb'
true
>> gh = Redcarpet::Render::GithubStyleTitles.new
#<Redcarpet::Render::GithubStyleTitles:0x00000001cc3a48>
>> puts Redcarpet::Markdown.new(gh).render "test\n\n# test 1\n\n# test 2\n\n# test 1\n\n# test 1"
<a name="test-1" href="#test-1" class="anchor"><span class="anchor-icon"></span></a><h1 id="test-1">test 1</h1>
@sunaku
sunaku / interleave.exs
Created September 15, 2015 23:54
Persistent zipping (interleaving) in Elixir.
defmodule Interleave do
def interleave(a, b, result \\ [])
def interleave([], [], result), do: result |> Enum.reverse
def interleave([], b, result), do: interleave(b, [], result)
def interleave([h|t], b, result), do: interleave(b, t, [h | result])
end
iex(1)> split = Regex.split(~r/x/, "fooxbar")
["foo", "bar"]
iex(2)> scan = Regex.scan(~r/x/, "fooxbar")
@sunaku
sunaku / section8.rb
Last active December 29, 2015 11:19
Example of the functional approach to problem decomposition in Ruby. https://class.coursera.org/proglang-002/forum/thread?thread_id=1962
BadResult = Class.new Exception
Int = Struct.new :i
Negate = Struct.new :e1
Add = Struct.new :e1, :e2
def eval e
case e
when Int then e
when Negate then case v1 = (eval e.e1)
@sunaku
sunaku / racket-tester
Last active December 26, 2015 16:09
Event-driven test runners for Coursera Programming Languages class - https://class.coursera.org/proglang-002
#!/bin/sh
# When *.rkt files in the current directory are modified, this script runs
# their corresponding *test.rkt files and prints any errors or test fails.
inotifywait -qme close_write --format '%w%f' . | while read file; do
# only process *.rkt files - ignore all other files
test "${file%.rkt}" = "$file" && continue
# map the *.rkt file to its corresponding *test.rkt
# file, unless it already _is_ that *test.rkt file!
@sunaku
sunaku / gist:6a043d726b46a9bfaeb3
Created October 21, 2015 22:41
Elixir's Logger to stderr
$ mix new foo
* creating README.md
* creating .gitignore
* creating mix.exs
* creating config
* creating config/config.exs
* creating lib
* creating lib/foo.ex
* creating test
* creating test/test_helper.exs
def self.valid_time?(time)
(0 .. 2359).include? Integer(time)
rescue ArgumentError # invalid integer
false
end