Skip to content

Instantly share code, notes, and snippets.

defmodule Codepoints do
defstruct str: ""
def new(str) when is_list(str) do
new(to_string(str))
end
def new(str) when is_binary(str) do
%__MODULE__{str: str}
end
@padde
padde / lpmap.exs
Last active April 10, 2016 16:48
Limited parallel map in Elixir
defmodule Parallel do
def run(funs, max) do
tasks = for fun <- funs, do: {make_ref, fun}
results = do_run(tasks, max, 0, %{})
for {ref, _} <- tasks, do: results[ref]
end
defp do_run([], _max, 0, results) do
results
end
@padde
padde / shellscript.sh
Created March 18, 2016 09:03
Shell Script Template
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
@padde
padde / stars.rb
Last active January 29, 2016 20:03
Colored stars (dabbling with ANSI escape codes)
lines = `tput lines`.to_i
cols = `tput cols`.to_i
# hide cursor
print "\e[?25l"
# clear screen
print "\e[2J"
at_exit do
# MathN using Ruby 2.0 refinements instead of plain monkey patches
# Patrick OSCITY 2013
#
# Based on original mathn implementation by Keiju ISHITSUKA from Ruby 1.8.7-p72
# http://www.opensource.apple.com/source/ruby/ruby-75/ruby/lib/mathn.rb
#
# Distributes under the same terms as Ruby.
require "complex"
require "rational"
@padde
padde / zsh.rb
Created December 14, 2013 18:46
require 'formula'
class Zsh < Formula
homepage 'http://www.zsh.org/'
url 'http://www.zsh.org/pub/zsh-5.0.2.tar.bz2'
mirror 'http://downloads.sourceforge.net/project/zsh/zsh/5.0.2/zsh-5.0.2.tar.bz2'
sha1 '9f55ecaaae7cdc1495f91237ba2ec087777a4ad9'
depends_on 'gdbm'
depends_on 'pcre'
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index 17b78ce..f136178 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -1576,7 +1576,7 @@ zrefresh(void)
else
put_rpmpt = rprompth == 1 && rpromptbuf[0] &&
!strchr(rpromptbuf, '\t') &&
- (int)ZR_strlen(nbuf[0]) + rpromptw < winw - 1;
+ (int)ZR_strlen(nbuf[0]) + rpromptw < winw;
@padde
padde / quine.rb
Last active December 20, 2015 07:49
A little Quine
puts a=[<<-X*2,?X]
puts a=[<<-X*2,?X]
X
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="Magento" targetNamespace="urn:Magento">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
<complexType name="FixedArray">
<complexContent>
<restriction base="soapenc:Array">
<wsdl:definitions xmlns:ns2="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" name="Magento" targetNamespace="urn:Magento">
<wsdl:types>
<xs:schema targetNamespace="urn:Magento">
<xs:attribute name="root">
<xs:annotation>
<xs:documentation>
'root' can be used to distinguish serialization roots from other
elements that are present in a serialization but are not roots of
a serialized value graph
</xs:documentation>