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 / 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
@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")
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled</title>
@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 / 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 / stay.log
Last active August 29, 2015 14:18
vim-fetch issue #7
calling function fetch#visual(1)
line 1: " get text between last visual selection marks
line 2: " adapted from http://stackoverflow.com/a/6271254/990363
line 3: let [l:startline, l:startcol] = getpos("'<")[1:2]
line 4: let [l:endline, l:endcol] = getpos("'>")[1:2]
line 5: let l:endcol = min([l:endcol, col([l:endline, '$'])]) " 'V' col nr. bug
line 6: let l:endcol -= &selection is 'inclusive' ? 0 : 1
line 7: let l:lines = getline(l:startline, l:endline)
line 8: if visualmode() isnot? 'v' " block-wise selection
@sunaku
sunaku / sjsu-course-prereqs.rb
Last active August 29, 2015 14:02
Dumps course prerequisites for the given SJSU (San Jose State University http://www.sjsu.edu/) degree program as a DOT (Graphviz http://www.graphviz.org/) graph. You can play with the resulting graph by pasting it into the Vis.js playground (http://visjs.org/examples/graph/15_dot_language_playground.html) or you can convert it into a PDF with cl…
#!/usr/bin/env ruby
#
# Usage: ruby sjsu-course-prereqs.rb [PROGRAM_INFO_URL]
#
# Dumps course prerequisites for the given SJSU degree program as a DOT graph.
# If no PROGRAM_INFO_URL is given, the M.S. Computer Science program is used:
#
# http://www.sjsu.edu/cs/programs/mscs/program-info/
#
# You can convert the graph into a PDF with clickable course links like this:
#!/bin/sh
ARGS=$( echo "$*" | sed 's/ -url / -host /; s/ -langselen\>//' )
$HOME/.cisco/hostscan/bin/cstub -log error $ARGS
@sunaku
sunaku / chromeos-vpn
Created April 9, 2014 16:03
chromeos-scripts
#!/bin/bash
#
# Connects to the VPN specified by the given vpnc(1) configuration file and
# then waits for you to interrupt or kill this process, at which time it
# disconnects the VPN. See https://github.com/dnschneid/crouton/wiki/VPNC
#
# Usage: chromeos-vpn VPNC_CONFIGURATION_FILE [OPTIONS_FOR_VPNC...]
#
# Setup: apt-get install vpnc wireless-tools
#