Skip to content

Instantly share code, notes, and snippets.

View ivan's full-sized avatar
🕸️

Ivan Kozik ivan

🕸️
View GitHub Profile
@ivan
ivan / depmapper.exs
Last active September 26, 2016 17:08
Hacking mix to globally map Hex dependencies to audited git repositories
# ~/.mix/depmapper.exs
defmodule Mix.DepMapper do
@repos_path "/ejail/code/erlang"
# The branch to check out. My workflow is to mark audited known-good
# commits with both a branch and timestamped tag using
# https://github.com/ludios/tagmyrebase
@default_branch "bien"
def mapdep(dep) do
@ivan
ivan / fonts.conf.xml
Created September 29, 2016 06:06
~/.config/fontconfig/fonts.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- Don't use embedded bitmap in Cambria and other fonts: https://bugzilla.mozilla.org/show_bug.cgi?id=722356#c6 -->
<match target="font">
<edit name="embeddedbitmap" mode="assign">
<bool>false</bool>
</edit>
</match>
<alias>
@ivan
ivan / quoting.ex
Created September 30, 2016 16:24
quoting.ex
iex(9)> quote do {1} end
{:{}, [], [1]}
iex(10)> quote do {1, 2} end
{1, 2}
iex(11)> quote do {1, 2, 3} end
{:{}, [], [1, 2, 3]}
@ivan
ivan / append_if.ex
Last active October 22, 2016 18:27
defmodule LangUtil do
@doc ~S"""
For use in a pipeline like so:
s
|> append_if(c.section, "Section: #{c.section}\n")
|> append_if(true, "Description: #{c.short_description}\n")
|> append_if(c.long_description, prefix_every_line(c.long_description, " ") <> "\n")
`expression` is not evaluated unless evaluation of `clause` is truthy. This avoids
defmodule LangUtil do
@doc ~S"""
For use in a pipeline like so:
{s, &Kernel.<>/2}
|> oper_if(c.section, "Section: #{c.section}\n")
|> oper_if(true, "Description: #{c.short_description}\n")
|> oper_if(c.long_description, prefix_every_line(c.long_description, " ") <> "\n")
|> elem(0)
@ivan
ivan / allow-usb-devices
Last active November 22, 2016 05:25
How to lock and sleep a linux workstation
#!/bin/sh
for f in /sys/bus/usb/devices/usb*/authorized_default; do
echo 1 > $f
done
defmodule LangUtil do
@doc ~S"""
For use in a pipeline like so:
{s, &Kernel.<>/2}
|> oper_if(c.section, "Section: #{c.section}\n")
|> oper_if(true, "Description: #{c.short_description}\n")
|> oper_if(c.long_description, prefix_every_line(c.long_description, " ") <> "\n")
|> elem(0)
@ivan
ivan / demo.ex
Created December 9, 2016 21:20
defmodule Demo do
def demo do
s = ""
if true do
s = s <> "hello"
end
if true do
s = s <> "world"
end
IO.write(s)
# apt-get source systemd
Reading package lists... Done
NOTICE: 'systemd' packaging is maintained in the 'Git' version control system at:
git://anonscm.debian.org/pkg-systemd/systemd.git
Please use:
git clone git://anonscm.debian.org/pkg-systemd/systemd.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 4,558 kB of source archives.
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main systemd 229-4ubuntu12 (dsc) [4,409 B]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main systemd 229-4ubuntu12 (tar) [4,319 kB]
@ivan
ivan / count-occurences
Created December 15, 2016 20:24
triple splitter and counter
#!/usr/bin/env python
"""
Count the number of times each line occurs. This program avoids
the need to `sort | uniq -c`, which is much slower.
"""
from __future__ import print_function
import sys