Skip to content

Instantly share code, notes, and snippets.

@padde
padde / export-plot-as-csv.m
Created June 19, 2012 11:56
Mathematica: Export Plot Values as CSV
plot = Plot[Cos[x],{x,0,2\[Pi]}];
mydata = Flatten[Cases[plot, Line[x__] -> x, Infinity], 1];
Export["/Users/padde/Desktop/plot-data.dat", mydata, "CSV"];
@padde
padde / stdin-reopen.rb
Created July 9, 2012 18:49
SO Question 11399584
tty = STDIN.reopen('/dev/tty')
tty.each_line do |line|
break if line == "\n"
puts line
end
tty.close
@padde
padde / data.xml
Created July 10, 2012 08:59
SO question #11409692
<?xml version="1.0" encoding="utf-8"?>
<item name="a">
<item name="d">
<item name="g"></item>
</item>
<item name="e"></item>
<item name="f"></item>
</item>
<item name="b"></item>
<item name="c"></item>
@padde
padde / hack.sh
Created July 14, 2012 16:52 — forked from eins78/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/3112090/hack.sh | sh
#
@padde
padde / NSData+CRC32.h
Created July 27, 2012 11:34
NSData CRC32 Category
@interface NSData (CRC32)
-(NSUInteger) crc32;
@end
@padde
padde / alfred-extension.sh
Last active December 11, 2015 05:48
Template for writing Alfred Extensions in Ruby
TMPFILE=".$(uuidgen).tmp.rb"
cat > $TMPFILE <<RUBYSCRIPT
# TODO: replace this with real code
puts "Running Ruby #{RUBY_VERSION}"
puts "Arguments are #{ARGV.inspect}"
RUBYSCRIPT
/usr/bin/env ruby $TMPFILE "{query}"
rm $TMPFILE
@padde
padde / completion.rb
Created January 26, 2013 17:59
Hacky completion class in Ruby. Useful for automatically abbreviating commands etc.
require 'fuzzy_match'
require 'amatch'
require 'text'
class Completion
attr_accessor :keywords
def initialize( keywords=[] )
self.keywords = keywords.map(&:downcase)
ambiguous = true
@padde
padde / highlight.rb
Created January 27, 2013 16:21
Code highlight from stdin thingy
#!/usr/bin/env ruby
require 'securerandom'
require 'fileutils'
require 'coderay'
require 'coderay_bash'
require 'trollop'
opts = Trollop::options do
opt :language, "The language used to highlight the input", short: '-l', type: :string, default: nil
@padde
padde / template.liquid
Created February 14, 2013 06:35
Basic Locomotive Template
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Test</title>
{% seo %}
{% inline_editor %}
</head>
<body>
<nav id="main_menu">
@padde
padde / array.rb
Last active December 14, 2015 13:59
Monkeypatch for Array with each DSL that shows if current element is first, last, etc.
class Array
class EachDSL
attr_accessor :idx, :max
def initialize arr
self.max = arr.size
end
def pos
idx + 1