mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Compare commits
164 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a00967ddc4 | ||
|
|
599e1e2a51 | ||
|
|
44638e1c6b | ||
|
|
cabd4fb4c5 | ||
|
|
086845f189 | ||
|
|
413c881af8 | ||
|
|
80321272b1 | ||
|
|
02500d3830 | ||
|
|
5232a45d1f | ||
|
|
c7933537b1 | ||
|
|
e194d7238e | ||
|
|
33d777a6ff | ||
|
|
8465961e72 | ||
|
|
f5cb6e035d | ||
|
|
7946de7116 | ||
|
|
9e65eb35e7 | ||
|
|
76a1369932 | ||
|
|
12e92f127b | ||
|
|
50f3b2e398 | ||
|
|
a716151c83 | ||
|
|
3c70fffb67 | ||
|
|
a0a879a3a3 | ||
|
|
5d35d18634 | ||
|
|
a3a6c2f8b3 | ||
|
|
8eef1c33b8 | ||
|
|
a9db25cc5b | ||
|
|
f06167eaca | ||
|
|
687e82307e | ||
|
|
b3fbd42786 | ||
|
|
590ed26f7b | ||
|
|
12093ee1f0 | ||
|
|
ee840321d1 | ||
|
|
0cbc44677c | ||
|
|
a9b944ac36 | ||
|
|
759860d866 | ||
|
|
c4b21f51e4 | ||
|
|
fdccffddfc | ||
|
|
e610789d38 | ||
|
|
3bd8ed45e4 | ||
|
|
42311e1bf3 | ||
|
|
9e9aae1d83 | ||
|
|
229ab3a268 | ||
|
|
85840aadc2 | ||
|
|
32b7b3e1b1 | ||
|
|
5e7eeae98e | ||
|
|
de8c4daa45 | ||
|
|
64990a00b8 | ||
|
|
33434f08f4 | ||
|
|
d5730f6fd1 | ||
|
|
2305496f94 | ||
|
|
d031392507 | ||
|
|
6ec22a1674 | ||
|
|
694f51d09e | ||
|
|
79040d00c7 | ||
|
|
7dfc1644ce | ||
|
|
c4a90bbbcd | ||
|
|
ac0920a11b | ||
|
|
a4bdca6d6b | ||
|
|
f9bfcceba9 | ||
|
|
e0ceccc0c6 | ||
|
|
cd3e88fe8b | ||
|
|
254b6de1d3 | ||
|
|
a93e9493e2 | ||
|
|
53b356deee | ||
|
|
9dca6fa9cc | ||
|
|
7226aa18de | ||
|
|
ce97865bd2 | ||
|
|
424fa0f56b | ||
|
|
007fc9ebd0 | ||
|
|
e0104c8d12 | ||
|
|
1a98a1f938 | ||
|
|
e005893d4c | ||
|
|
6c74d854ec | ||
|
|
06b185f725 | ||
|
|
e6f38cbf45 | ||
|
|
1764674a13 | ||
|
|
4741a47d21 | ||
|
|
432bffe3ec | ||
|
|
7b2fec88d1 | ||
|
|
76128ccb37 | ||
|
|
f5ede0d0f9 | ||
|
|
70d1649b45 | ||
|
|
de706a2eb9 | ||
|
|
33ebee0f6a | ||
|
|
51a989d5f1 | ||
|
|
3fc208b4ce | ||
|
|
0fa54a85d8 | ||
|
|
96e8a5d2cc | ||
|
|
838fbc5626 | ||
|
|
80780ab042 | ||
|
|
bd19f6ed17 | ||
|
|
2ae76842a0 | ||
|
|
750804876e | ||
|
|
1d8da964e2 | ||
|
|
d21d0f281a | ||
|
|
a8e337e0eb | ||
|
|
37429d91a0 | ||
|
|
4b9c6fdf62 | ||
|
|
4130825a43 | ||
|
|
6d95590861 | ||
|
|
dbc36a5e63 | ||
|
|
32a106cedd | ||
|
|
78ed103f90 | ||
|
|
3e26b2a0a7 | ||
|
|
4fb910533f | ||
|
|
b71cab6add | ||
|
|
5a9d35917f | ||
|
|
772a9a582c | ||
|
|
e633d565a9 | ||
|
|
7d6ee108c4 | ||
|
|
dd64c3b545 | ||
|
|
b462e29e1d | ||
|
|
43f4f5bd32 | ||
|
|
904e86d901 | ||
|
|
374164a299 | ||
|
|
f73f309595 | ||
|
|
f23110a98d | ||
|
|
3193fc90f9 | ||
|
|
cc04519520 | ||
|
|
f51c5e3159 | ||
|
|
c439ca5f97 | ||
|
|
4d45f13783 | ||
|
|
2a56719378 | ||
|
|
7d594b55e4 | ||
|
|
5268a93fa4 | ||
|
|
ae44530a66 | ||
|
|
285216a258 | ||
|
|
4d3720745e | ||
|
|
a681a252d4 | ||
|
|
22de40f5f6 | ||
|
|
7fbfe0a4b4 | ||
|
|
29f5ea591f | ||
|
|
438c0a4ec1 | ||
|
|
887933c86a | ||
|
|
53340ddd4c | ||
|
|
72b70a11bc | ||
|
|
d853864edb | ||
|
|
62ad763933 | ||
|
|
6a15ae47ee | ||
|
|
1bebb50482 | ||
|
|
fdc81d8818 | ||
|
|
68dfff60b5 | ||
|
|
479871f019 | ||
|
|
10ec56e667 | ||
|
|
1e958a18f8 | ||
|
|
9fa0f6cd6f | ||
|
|
4e339db911 | ||
|
|
c1469b25a1 | ||
|
|
ef6abed81a | ||
|
|
96473849e0 | ||
|
|
b14e09af6b | ||
|
|
42050c4d12 | ||
|
|
f2b80a239f | ||
|
|
c6d38ab647 | ||
|
|
420594874a | ||
|
|
407c40f7d3 | ||
|
|
ec786b73bc | ||
|
|
fc8d2f641c | ||
|
|
9a5f9a5e9b | ||
|
|
806369ce7f | ||
|
|
4398cda9a5 | ||
|
|
0479f72a93 | ||
|
|
0f006af583 | ||
|
|
2bbf92d5f8 |
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2011 GitHub, Inc.
|
||||
Copyright (c) 2011-2013 GitHub, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
||||
@@ -84,7 +84,7 @@ To run the tests:
|
||||
|
||||
The majority of patches won't need to touch any Ruby code at all. The [master language list](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) is just a configuration file.
|
||||
|
||||
We try to only add languages once they have a some usage on GitHub, so please note in-the-wild usage examples in your pull request.
|
||||
We try to only add languages once they have some usage on GitHub, so please note in-the-wild usage examples in your pull request.
|
||||
|
||||
Almost all bug fixes or new language additions should come with some additional code samples. Just drop them under [`samples/`](https://github.com/github/linguist/tree/master/samples) in the correct subdirectory and our test suite will automatically test them. In most cases you shouldn't need to add any new assertions.
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# linguist — detect language type for a file, or, given a directory, determine language breakdown
|
||||
#
|
||||
# usage: linguist <path>
|
||||
|
||||
require 'linguist/file_blob'
|
||||
require 'linguist/repository'
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'github-linguist'
|
||||
s.version = '2.7.0'
|
||||
s.version = '2.9.5'
|
||||
s.summary = "GitHub Language detection"
|
||||
|
||||
s.authors = "GitHub"
|
||||
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
||||
s.add_dependency 'charlock_holmes', '~> 0.6.6'
|
||||
s.add_dependency 'escape_utils', '~> 0.3.1'
|
||||
s.add_dependency 'mime-types', '~> 1.19'
|
||||
s.add_dependency 'pygments.rb', '~> 0.4.2'
|
||||
s.add_dependency 'pygments.rb', '~> 0.5.2'
|
||||
s.add_development_dependency 'mocha'
|
||||
s.add_development_dependency 'json'
|
||||
s.add_development_dependency 'rake'
|
||||
|
||||
@@ -189,11 +189,10 @@ module Linguist
|
||||
|
||||
# Public: Is the blob safe to colorize?
|
||||
#
|
||||
# We use Pygments.rb for syntax highlighting blobs, which
|
||||
# has some quirks and also is essentially 'un-killable' via
|
||||
# normal timeout. To workaround this we try to
|
||||
# carefully handling Pygments.rb anything it can't handle.
|
||||
#
|
||||
# We use Pygments for syntax highlighting blobs. Pygments
|
||||
# can be too slow for very large blobs or for certain
|
||||
# corner-case blobs.
|
||||
#
|
||||
# Return true or false
|
||||
def safe_to_colorize?
|
||||
!large? && text? && !high_ratio_of_long_lines?
|
||||
|
||||
@@ -147,16 +147,20 @@ module Linguist
|
||||
# indicate the least-likely language (and zero points) for each token.
|
||||
def dump_all_tokens(tokens, languages)
|
||||
maxlen = tokens.map { |tok| tok.size }.max
|
||||
|
||||
printf "%#{maxlen}s", ""
|
||||
puts " #" + languages.map { |lang| sprintf("%10s", lang) }.join
|
||||
|
||||
tokmap = Hash.new(0)
|
||||
tokens.each { |tok| tokmap[tok] += 1 }
|
||||
|
||||
tokmap.sort.each { |tok, count|
|
||||
arr = languages.map { |lang| [lang, token_probability(tok, lang)] }
|
||||
min = arr.map { |a,b| b }.min
|
||||
minlog = Math.log(min)
|
||||
if !arr.inject(true) { |result, n| result && n[1] == arr[0][1] }
|
||||
printf "%#{maxlen}s%5d", tok, count
|
||||
|
||||
puts arr.map { |ent|
|
||||
ent[1] == min ? " -" : sprintf("%10.3f", count * (Math.log(ent[1]) - minlog))
|
||||
}.join
|
||||
|
||||
@@ -52,11 +52,12 @@ module Linguist
|
||||
# Return true or false
|
||||
def generated?
|
||||
name == 'Gemfile.lock' ||
|
||||
minified_javascript? ||
|
||||
minified_files? ||
|
||||
compiled_coffeescript? ||
|
||||
xcode_project_file? ||
|
||||
generated_net_docfile? ||
|
||||
generated_parser? ||
|
||||
generated_net_docfile? ||
|
||||
generated_net_designer_file? ||
|
||||
generated_protocol_buffer?
|
||||
end
|
||||
|
||||
@@ -70,16 +71,16 @@ module Linguist
|
||||
['.xib', '.nib', '.storyboard', '.pbxproj', '.xcworkspacedata', '.xcuserstate'].include?(extname)
|
||||
end
|
||||
|
||||
# Internal: Is the blob minified JS?
|
||||
# Internal: Is the blob minified files?
|
||||
#
|
||||
# Consider JS minified if the average line length is
|
||||
# greater then 100c.
|
||||
# Consider a file minified if it contains more than 5% spaces.
|
||||
# Currently, only JS and CSS files are detected by this method.
|
||||
#
|
||||
# Returns true or false.
|
||||
def minified_javascript?
|
||||
return unless extname == '.js'
|
||||
if lines.any?
|
||||
(lines.inject(0) { |n, l| n += l.length } / lines.length) > 100
|
||||
def minified_files?
|
||||
return unless ['.js', '.css'].include? extname
|
||||
if data && data.length > 200
|
||||
(data.each_char.count{ |c| c <= ' ' } / data.length.to_f) < 0.05
|
||||
else
|
||||
false
|
||||
end
|
||||
@@ -143,6 +144,16 @@ module Linguist
|
||||
lines[-2].include?("</doc>")
|
||||
end
|
||||
|
||||
# Internal: Is this a codegen file for a .NET project?
|
||||
#
|
||||
# Visual Studio often uses code generation to generate partial classes, and
|
||||
# these files can be quite unwieldy. Let's hide them.
|
||||
#
|
||||
# Returns true or false
|
||||
def generated_net_designer_file?
|
||||
name.downcase =~ /\.designer\.cs$/
|
||||
end
|
||||
|
||||
# Internal: Is the blob of JS a parser generated by PEG.js?
|
||||
#
|
||||
# PEG.js-generated parsers are not meant to be consumed by humans.
|
||||
|
||||
@@ -15,12 +15,21 @@ module Linguist
|
||||
@index = {}
|
||||
@name_index = {}
|
||||
@alias_index = {}
|
||||
@extension_index = Hash.new { |h,k| h[k] = [] }
|
||||
@filename_index = Hash.new { |h,k| h[k] = [] }
|
||||
|
||||
@extension_index = Hash.new { |h,k| h[k] = [] }
|
||||
@filename_index = Hash.new { |h,k| h[k] = [] }
|
||||
@primary_extension_index = {}
|
||||
|
||||
# Valid Languages types
|
||||
TYPES = [:data, :markup, :programming]
|
||||
|
||||
# Names of non-programming languages that we will still detect
|
||||
#
|
||||
# Returns an array
|
||||
def self.detectable_markup
|
||||
["AsciiDoc", "CSS", "Creole", "Less", "Markdown", "MediaWiki", "Org", "RDoc", "Sass", "Textile", "reStructuredText"]
|
||||
end
|
||||
|
||||
# Internal: Create a new Language object
|
||||
#
|
||||
# attributes - A hash of attributes
|
||||
@@ -56,6 +65,12 @@ module Linguist
|
||||
@extension_index[extension] << language
|
||||
end
|
||||
|
||||
if @primary_extension_index.key?(language.primary_extension)
|
||||
raise ArgumentError, "Duplicate primary extension: #{language.primary_extension}"
|
||||
end
|
||||
|
||||
@primary_extension_index[language.primary_extension] = language
|
||||
|
||||
language.filenames.each do |filename|
|
||||
@filename_index[filename] << language
|
||||
end
|
||||
@@ -141,7 +156,10 @@ module Linguist
|
||||
# Returns all matching Languages or [] if none were found.
|
||||
def self.find_by_filename(filename)
|
||||
basename, extname = File.basename(filename), File.extname(filename)
|
||||
@filename_index[basename] + @extension_index[extname]
|
||||
langs = [@primary_extension_index[extname]] +
|
||||
@filename_index[basename] +
|
||||
@extension_index[extname]
|
||||
langs.compact.uniq
|
||||
end
|
||||
|
||||
# Public: Look up Language by its name or lexer.
|
||||
@@ -445,8 +463,6 @@ module Linguist
|
||||
extnames.each do |extname|
|
||||
if !options['extensions'].include?(extname)
|
||||
options['extensions'] << extname
|
||||
else
|
||||
warn "#{name} #{extname.inspect} is already defined in samples/. Remove from languages.yml."
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -455,8 +471,6 @@ module Linguist
|
||||
fns.each do |filename|
|
||||
if !options['filenames'].include?(filename)
|
||||
options['filenames'] << filename
|
||||
else
|
||||
warn "#{name} #{filename.inspect} is already defined in samples/. Remove from languages.yml."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
# Any additions or modifications (even trivial) should have corresponding
|
||||
# test change in `test/test_blob.rb`.
|
||||
#
|
||||
# Please keep this list alphabetized.
|
||||
# Please keep this list alphabetized. Capitalization comes before lower case.
|
||||
|
||||
ABAP:
|
||||
type: programming
|
||||
@@ -91,6 +91,16 @@ Arduino:
|
||||
lexer: C++
|
||||
primary_extension: .ino
|
||||
|
||||
AsciiDoc:
|
||||
type: markup
|
||||
lexer: Text only
|
||||
ace_mode: asciidoc
|
||||
wrap: true
|
||||
primary_extension: .asciidoc
|
||||
extensions:
|
||||
- .adoc
|
||||
- .asc
|
||||
|
||||
Assembly:
|
||||
type: programming
|
||||
lexer: NASM
|
||||
@@ -212,8 +222,18 @@ CMake:
|
||||
filenames:
|
||||
- CMakeLists.txt
|
||||
|
||||
COBOL:
|
||||
type: programming
|
||||
primary_extension: .cob
|
||||
extensions:
|
||||
- .cbl
|
||||
- .ccp
|
||||
- .cobol
|
||||
- .cpy
|
||||
|
||||
CSS:
|
||||
ace_mode: css
|
||||
color: "#1f085e"
|
||||
primary_extension: .css
|
||||
|
||||
Ceylon:
|
||||
@@ -232,6 +252,7 @@ Clojure:
|
||||
primary_extension: .clj
|
||||
extensions:
|
||||
- .cljs
|
||||
- .cljx
|
||||
filenames:
|
||||
- riemann.config
|
||||
|
||||
@@ -272,6 +293,7 @@ Common Lisp:
|
||||
- .asd
|
||||
- .lsp
|
||||
- .ny
|
||||
- .podsl
|
||||
|
||||
Coq:
|
||||
type: programming
|
||||
@@ -285,6 +307,12 @@ Cpp-ObjDump:
|
||||
- .c++objdump
|
||||
- .cxx-objdump
|
||||
|
||||
Creole:
|
||||
type: markup
|
||||
lexer: Text only
|
||||
wrap: true
|
||||
primary_extension: .creole
|
||||
|
||||
Cucumber:
|
||||
lexer: Gherkin
|
||||
primary_extension: .feature
|
||||
@@ -328,14 +356,6 @@ Dart:
|
||||
type: programming
|
||||
primary_extension: .dart
|
||||
|
||||
Delphi:
|
||||
type: programming
|
||||
color: "#b0ce4e"
|
||||
primary_extension: .pas
|
||||
extensions:
|
||||
- .dfm
|
||||
- .lpr
|
||||
|
||||
DCPU-16 ASM:
|
||||
type: programming
|
||||
lexer: dasm16
|
||||
@@ -399,7 +419,7 @@ Emacs Lisp:
|
||||
|
||||
Erlang:
|
||||
type: programming
|
||||
color: "#949e0e"
|
||||
color: "#0faf8d"
|
||||
primary_extension: .erl
|
||||
extensions:
|
||||
- .hrl
|
||||
@@ -408,7 +428,9 @@ F#:
|
||||
type: programming
|
||||
lexer: FSharp
|
||||
color: "#b845fc"
|
||||
search_term: ocaml
|
||||
search_term: fsharp
|
||||
aliases:
|
||||
- fsharp
|
||||
primary_extension: .fs
|
||||
extensions:
|
||||
- .fsi
|
||||
@@ -473,6 +495,18 @@ GAS:
|
||||
extensions:
|
||||
- .S
|
||||
|
||||
GLSL:
|
||||
group: C
|
||||
type: programming
|
||||
primary_extension: .glsl
|
||||
extensions:
|
||||
- .fp
|
||||
- .frag
|
||||
- .geom
|
||||
- .glslv
|
||||
- .shader
|
||||
- .vert
|
||||
|
||||
Genshi:
|
||||
primary_extension: .kid
|
||||
|
||||
@@ -497,7 +531,7 @@ Gettext Catalog:
|
||||
|
||||
Go:
|
||||
type: programming
|
||||
color: "#8d04eb"
|
||||
color: "#a89b4d"
|
||||
primary_extension: .go
|
||||
|
||||
Gosu:
|
||||
@@ -601,7 +635,6 @@ Haxe:
|
||||
INI:
|
||||
type: data
|
||||
extensions:
|
||||
- .cfg
|
||||
- .ini
|
||||
- .prefs
|
||||
- .properties
|
||||
@@ -626,6 +659,11 @@ Ioke:
|
||||
color: "#078193"
|
||||
primary_extension: .ik
|
||||
|
||||
J:
|
||||
type: programming
|
||||
lexer: Text only
|
||||
primary_extension: .ijs
|
||||
|
||||
JSON:
|
||||
type: data
|
||||
group: JavaScript
|
||||
@@ -680,6 +718,13 @@ Kotlin:
|
||||
- .ktm
|
||||
- .kts
|
||||
|
||||
LFE:
|
||||
type: programming
|
||||
primary_extension: .lfe
|
||||
color: "#004200"
|
||||
lexer: Common Lisp
|
||||
group: Erlang
|
||||
|
||||
LLVM:
|
||||
primary_extension: .ll
|
||||
|
||||
@@ -745,6 +790,8 @@ Logos:
|
||||
Logtalk:
|
||||
type: programming
|
||||
primary_extension: .lgt
|
||||
extensions:
|
||||
- .logtalk
|
||||
|
||||
Lua:
|
||||
type: programming
|
||||
@@ -753,13 +800,16 @@ Lua:
|
||||
primary_extension: .lua
|
||||
extensions:
|
||||
- .nse
|
||||
- .rbxs
|
||||
|
||||
M:
|
||||
type: programming
|
||||
lexer: Common Lisp
|
||||
aliases:
|
||||
- mumps
|
||||
primary_extension: .m
|
||||
primary_extension: .mumps
|
||||
extensions:
|
||||
- .m
|
||||
|
||||
Makefile:
|
||||
aliases:
|
||||
@@ -808,6 +858,12 @@ Max:
|
||||
- .maxhelp
|
||||
- .maxpat
|
||||
|
||||
MediaWiki:
|
||||
type: markup
|
||||
lexer: Text only
|
||||
wrap: true
|
||||
primary_extension: .mediawiki
|
||||
|
||||
MiniD: # Legacy
|
||||
searchable: false
|
||||
primary_extension: .minid # Dummy extension
|
||||
@@ -937,6 +993,12 @@ OpenEdge ABL:
|
||||
- abl
|
||||
primary_extension: .p
|
||||
|
||||
Org:
|
||||
type: markup
|
||||
lexer: Text only
|
||||
wrap: true
|
||||
primary_extension: .org
|
||||
|
||||
PHP:
|
||||
type: programming
|
||||
ace_mode: php
|
||||
@@ -974,6 +1036,15 @@ Parrot Assembly:
|
||||
- pasm
|
||||
primary_extension: .pasm
|
||||
|
||||
Pascal:
|
||||
type: programming
|
||||
lexer: Delphi
|
||||
color: "#b0ce4e"
|
||||
primary_extension: .pas
|
||||
extensions:
|
||||
- .dfm
|
||||
- .lpr
|
||||
|
||||
Perl:
|
||||
type: programming
|
||||
ace_mode: perl
|
||||
@@ -981,6 +1052,7 @@ Perl:
|
||||
primary_extension: .pl
|
||||
extensions:
|
||||
- .PL
|
||||
- .nqp
|
||||
- .perl
|
||||
- .ph
|
||||
- .plx
|
||||
@@ -1044,6 +1116,7 @@ Python:
|
||||
primary_extension: .py
|
||||
extensions:
|
||||
- .gyp
|
||||
- .pyt
|
||||
- .pyw
|
||||
- .wsgi
|
||||
- .xpy
|
||||
@@ -1062,6 +1135,15 @@ R:
|
||||
color: "#198ce7"
|
||||
lexer: S
|
||||
primary_extension: .r
|
||||
filenames:
|
||||
- .Rprofile
|
||||
|
||||
RDoc:
|
||||
type: markup
|
||||
lexer: Text only
|
||||
ace_mode: rdoc
|
||||
wrap: true
|
||||
primary_extension: .rdoc
|
||||
|
||||
RHTML:
|
||||
type: markup
|
||||
@@ -1132,6 +1214,7 @@ Ruby:
|
||||
- .thor
|
||||
- .watchr
|
||||
filenames:
|
||||
- Berksfile
|
||||
- Gemfile
|
||||
- Guardfile
|
||||
- Podfile
|
||||
@@ -1202,6 +1285,13 @@ Shell:
|
||||
primary_extension: .sh
|
||||
extensions:
|
||||
- .tmux
|
||||
filenames:
|
||||
- Dockerfile
|
||||
|
||||
Slash:
|
||||
type: programming
|
||||
color: "#007eff"
|
||||
primary_extension: .sl
|
||||
|
||||
Smalltalk:
|
||||
type: programming
|
||||
@@ -1211,6 +1301,11 @@ Smalltalk:
|
||||
Smarty:
|
||||
primary_extension: .tpl
|
||||
|
||||
Squirrel:
|
||||
type: programming
|
||||
lexer: C++
|
||||
primary_extension: .nut
|
||||
|
||||
Standard ML:
|
||||
type: programming
|
||||
color: "#dc566d"
|
||||
@@ -1287,7 +1382,6 @@ Twig:
|
||||
TypeScript:
|
||||
type: programming
|
||||
color: "#31859c"
|
||||
lexer: Text only
|
||||
aliases:
|
||||
- ts
|
||||
primary_extension: .ts
|
||||
@@ -1298,8 +1392,8 @@ Unified Parallel C:
|
||||
lexer: C
|
||||
ace_mode: c_cpp
|
||||
color: "#755223"
|
||||
primary_extension: .upc
|
||||
|
||||
primary_extension: .upc
|
||||
|
||||
VHDL:
|
||||
type: programming
|
||||
lexer: vhdl
|
||||
@@ -1345,6 +1439,17 @@ Visual Basic:
|
||||
- .vba
|
||||
- .vbs
|
||||
|
||||
Volt:
|
||||
type: programming
|
||||
lexer: D
|
||||
color: "#0098db"
|
||||
primary_extension: .volt
|
||||
|
||||
XC:
|
||||
type: programming
|
||||
lexer: C
|
||||
primary_extension: .xc
|
||||
|
||||
XML:
|
||||
type: markup
|
||||
ace_mode: xml
|
||||
@@ -1373,6 +1478,7 @@ XML:
|
||||
- .tmLanguage
|
||||
- .tmPreferences
|
||||
- .tmSnippet
|
||||
- .tmTheme
|
||||
- .tml
|
||||
- .ui
|
||||
- .vxml
|
||||
@@ -1380,9 +1486,11 @@ XML:
|
||||
- .wxi
|
||||
- .wxl
|
||||
- .wxs
|
||||
- .x3d
|
||||
- .xaml
|
||||
- .xlf
|
||||
- .xliff
|
||||
- .xmi
|
||||
- .xsd
|
||||
- .xul
|
||||
- .zcml
|
||||
@@ -1422,7 +1530,7 @@ Xtend:
|
||||
primary_extension: .xtend
|
||||
|
||||
YAML:
|
||||
type: markup
|
||||
type: data
|
||||
aliases:
|
||||
- yml
|
||||
primary_extension: .yml
|
||||
|
||||
@@ -73,8 +73,8 @@ module Linguist
|
||||
# Skip vendored or generated blobs
|
||||
next if blob.vendored? || blob.generated? || blob.language.nil?
|
||||
|
||||
# Only include programming languages
|
||||
if blob.language.type == :programming
|
||||
# Only include programming languages and acceptable markup languages
|
||||
if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name)
|
||||
@sizes[blob.language.group] += blob.size
|
||||
end
|
||||
end
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,9 @@
|
||||
# Node dependencies
|
||||
- node_modules/
|
||||
|
||||
# Erlang bundles
|
||||
- ^rebar$
|
||||
|
||||
# Vendored dependencies
|
||||
- vendor/
|
||||
|
||||
@@ -34,7 +37,11 @@
|
||||
|
||||
# jQuery
|
||||
- (^|/)jquery([^.]*)(\.min)?\.js$
|
||||
- (^|/)jquery\-\d\.\d(\.\d)?(\.min)?\.js$
|
||||
- (^|/)jquery\-\d\.\d+(\.\d+)?(\.min)?\.js$
|
||||
|
||||
# jQuery UI
|
||||
- (^|/)jquery\-ui(\-\d\.\d+(\.\d+)?)?(\.\w+)?(\.min)?\.(js|css)$
|
||||
- (^|/)jquery\.(ui|effects)\.([^.]*)(\.min)?\.(js|css)$
|
||||
|
||||
# Prototype
|
||||
- (^|/)prototype(.*)\.js$
|
||||
@@ -55,10 +62,6 @@
|
||||
- (^|/)yahoo-([^.]*)\.js$
|
||||
- (^|/)yui([^.]*)\.js$
|
||||
|
||||
# LESS css
|
||||
- (^|/)less([^.]*)(\.min)?\.js$
|
||||
- (^|/)less\-\d+\.\d+\.\d+(\.min)?\.js$
|
||||
|
||||
# WYS editors
|
||||
- (^|/)ckeditor\.js$
|
||||
- (^|/)tiny_mce([^.]*)\.js$
|
||||
@@ -95,7 +98,8 @@
|
||||
- -vsdoc\.js$
|
||||
|
||||
# jQuery validation plugin (MS bundles this with asp.net mvc)
|
||||
- (^|/)jquery([^.]*)\.validate(\.min)?\.js$
|
||||
- (^|/)jquery([^.]*)\.validate(\.unobtrusive)?(\.min)?\.js$
|
||||
- (^|/)jquery([^.]*)\.unobtrusive\-ajax(\.min)?\.js$
|
||||
|
||||
# Microsoft Ajax
|
||||
- (^|/)[Mm]icrosoft([Mm]vc)?([Aa]jax|[Vv]alidation)(\.debug)?\.js$
|
||||
@@ -109,5 +113,17 @@
|
||||
# Samples folders
|
||||
- ^[Ss]amples/
|
||||
|
||||
# LICENSE, README, git config files
|
||||
- ^COPYING$
|
||||
- ^LICENSE$
|
||||
- gitattributes$
|
||||
- gitignore$
|
||||
- gitmodules$
|
||||
- ^README$
|
||||
- ^readme$
|
||||
|
||||
# Test fixtures
|
||||
- ^[Tt]est/fixtures/
|
||||
|
||||
# .DS_Store's
|
||||
- .[Dd][Ss]_[Ss]tore$
|
||||
|
||||
13
samples/AsciiDoc/encoding.asciidoc
Normal file
13
samples/AsciiDoc/encoding.asciidoc
Normal file
@@ -0,0 +1,13 @@
|
||||
Gregory Romé has written an AsciiDoc plugin for the Redmine project management application.
|
||||
|
||||
https://github.com/foo-users/foo
|
||||
へと `vicmd` キーマップを足してみている試み、
|
||||
アニメーションgifです。
|
||||
|
||||
tag::romé[]
|
||||
Gregory Romé has written an AsciiDoc plugin for the Redmine project management application.
|
||||
end::romé[]
|
||||
|
||||
== Überschrift
|
||||
|
||||
* Codierungen sind verrückt auf älteren Versionen von Ruby
|
||||
10
samples/AsciiDoc/list.asc
Normal file
10
samples/AsciiDoc/list.asc
Normal file
@@ -0,0 +1,10 @@
|
||||
AsciiDoc Home Page
|
||||
==================
|
||||
|
||||
Example Articles
|
||||
~~~~~~~~~~~~~~~~
|
||||
- Item 1
|
||||
|
||||
- Item 2
|
||||
|
||||
- Item 3
|
||||
25
samples/AsciiDoc/sample.adoc
Normal file
25
samples/AsciiDoc/sample.adoc
Normal file
@@ -0,0 +1,25 @@
|
||||
Document Title
|
||||
==============
|
||||
Doc Writer <thedoc@asciidoctor.org>
|
||||
:idprefix: id_
|
||||
|
||||
Preamble paragraph.
|
||||
|
||||
NOTE: This is test, only a test.
|
||||
|
||||
== Section A
|
||||
|
||||
*Section A* paragraph.
|
||||
|
||||
=== Section A Subsection
|
||||
|
||||
*Section A* 'subsection' paragraph.
|
||||
|
||||
== Section B
|
||||
|
||||
*Section B* paragraph.
|
||||
|
||||
.Section B list
|
||||
* Item 1
|
||||
* Item 2
|
||||
* Item 3
|
||||
5
samples/COBOL/hello_world.cbl
Normal file
5
samples/COBOL/hello_world.cbl
Normal file
@@ -0,0 +1,5 @@
|
||||
program-id. hello.
|
||||
procedure division.
|
||||
display "Hello, World!".
|
||||
stop run.
|
||||
|
||||
6
samples/COBOL/hello_world.ccp
Normal file
6
samples/COBOL/hello_world.ccp
Normal file
@@ -0,0 +1,6 @@
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. hello.
|
||||
PROCEDURE DIVISION.
|
||||
DISPLAY "Hello World, yet again.".
|
||||
STOP RUN.
|
||||
|
||||
6
samples/COBOL/hello_world.cob
Normal file
6
samples/COBOL/hello_world.cob
Normal file
@@ -0,0 +1,6 @@
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. hello.
|
||||
PROCEDURE DIVISION.
|
||||
DISPLAY "Hello World!".
|
||||
STOP RUN.
|
||||
|
||||
7
samples/COBOL/simple.cpy
Normal file
7
samples/COBOL/simple.cpy
Normal file
@@ -0,0 +1,7 @@
|
||||
01 COBOL-TEST-RECORD.
|
||||
05 COBOL-TEST-USAGES.
|
||||
10 COBOL-4-COMP PIC S9(4) COMP.
|
||||
10 COBOL-8-COMP PIC S9(8) COMP.
|
||||
10 COBOL-9-COMP PIC S9(9) COMP.
|
||||
10 COBOL-4-COMP2 PIC S9(4) COMP-2.
|
||||
10 COBOL-7-COMP2 PIC 9(7) COMP-2.
|
||||
6307
samples/CSS/bootstrap.css
vendored
Normal file
6307
samples/CSS/bootstrap.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
873
samples/CSS/bootstrap.min.css
vendored
Normal file
873
samples/CSS/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
47
samples/Creole/creole.creole
Normal file
47
samples/Creole/creole.creole
Normal file
@@ -0,0 +1,47 @@
|
||||
= Creole
|
||||
|
||||
Creole is a Creole-to-HTML converter for Creole, the lightweight markup
|
||||
language (http://wikicreole.org/). Github uses this converter to render *.creole files.
|
||||
|
||||
Project page on github:
|
||||
|
||||
* http://github.com/minad/creole
|
||||
|
||||
Travis-CI:
|
||||
|
||||
* https://travis-ci.org/minad/creole
|
||||
|
||||
RDOC:
|
||||
|
||||
* http://rdoc.info/projects/minad/creole
|
||||
|
||||
== INSTALLATION
|
||||
|
||||
{{{
|
||||
gem install creole
|
||||
}}}
|
||||
|
||||
== SYNOPSIS
|
||||
|
||||
{{{
|
||||
require 'creole'
|
||||
html = Creole.creolize('== Creole text')
|
||||
}}}
|
||||
|
||||
== BUGS
|
||||
|
||||
If you found a bug, please report it at the Creole project's tracker
|
||||
on GitHub:
|
||||
|
||||
http://github.com/minad/creole/issues
|
||||
|
||||
== AUTHORS
|
||||
|
||||
* Lars Christensen (larsch)
|
||||
* Daniel Mendler (minad)
|
||||
|
||||
== LICENSE
|
||||
|
||||
Creole is Copyright (c) 2008 - 2013 Lars Christensen, Daniel Mendler. It is free software, and
|
||||
may be redistributed under the terms specified in the README file of
|
||||
the Ruby distribution.
|
||||
122
samples/Erlang/release.script!
Normal file
122
samples/Erlang/release.script!
Normal file
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env escript
|
||||
%%!
|
||||
%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*-
|
||||
% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et:
|
||||
%%%
|
||||
%%%------------------------------------------------------------------------
|
||||
%%% BSD LICENSE
|
||||
%%%
|
||||
%%% Copyright (c) 2013, Michael Truog <mjtruog at gmail dot com>
|
||||
%%% All rights reserved.
|
||||
%%%
|
||||
%%% Redistribution and use in source and binary forms, with or without
|
||||
%%% modification, are permitted provided that the following conditions are met:
|
||||
%%%
|
||||
%%% * Redistributions of source code must retain the above copyright
|
||||
%%% notice, this list of conditions and the following disclaimer.
|
||||
%%% * Redistributions in binary form must reproduce the above copyright
|
||||
%%% notice, this list of conditions and the following disclaimer in
|
||||
%%% the documentation and/or other materials provided with the
|
||||
%%% distribution.
|
||||
%%% * All advertising materials mentioning features or use of this
|
||||
%%% software must display the following acknowledgment:
|
||||
%%% This product includes software developed by Michael Truog
|
||||
%%% * The name of the author may not be used to endorse or promote
|
||||
%%% products derived from this software without specific prior
|
||||
%%% written permission
|
||||
%%%
|
||||
%%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
%%% CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
%%% INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
%%% OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
%%% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
%%% CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
%%% SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
%%% BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
%%% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
%%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
%%% WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
%%% NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
%%% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
%%% DAMAGE.
|
||||
%%%------------------------------------------------------------------------
|
||||
|
||||
-author('mjtruog [at] gmail (dot) com').
|
||||
|
||||
-mode(compile).
|
||||
|
||||
main(_) ->
|
||||
{ok,
|
||||
[{sys, _} = RelToolConfig,
|
||||
{target_dir, TargetDir},
|
||||
{overlay, OverlayConfig}]} = file:consult("reltool.config"),
|
||||
{ok, Spec} = reltool:get_target_spec([RelToolConfig]),
|
||||
case file:make_dir(TargetDir) of
|
||||
ok ->
|
||||
ok;
|
||||
{error, eexist} ->
|
||||
io:format("release already exists? (~p)~n", [TargetDir]),
|
||||
exit_code(1)
|
||||
end,
|
||||
ok = reltool:eval_target_spec(Spec, code:root_dir(), TargetDir),
|
||||
ok = process_overlay(RelToolConfig, TargetDir, OverlayConfig),
|
||||
exit_code(0).
|
||||
|
||||
shell(Command, Arguments) ->
|
||||
CommandSuffix = " && echo 0 || echo 1",
|
||||
case lists:reverse(os:cmd(lists:flatten(
|
||||
io_lib:format(Command ++ CommandSuffix, Arguments)))) of
|
||||
[_, $0 | _] ->
|
||||
ok;
|
||||
[_, $1 | _] ->
|
||||
io:format("\"~s\" failed!~n", [io_lib:format(Command, Arguments)]),
|
||||
error
|
||||
end.
|
||||
|
||||
boot_rel_vsn({sys, Config} = _RelToolConfig) ->
|
||||
{rel, _Name, Ver, _} = proplists:lookup(rel, Config),
|
||||
Ver.
|
||||
|
||||
%% minimal parsing for handling mustache syntax
|
||||
mustache(Body, Context) ->
|
||||
mustache(Body, "", Context).
|
||||
mustache([], Result, _Context) ->
|
||||
lists:reverse(Result);
|
||||
mustache([${, ${ | KeyStr], Result, Context) ->
|
||||
mustache_key(KeyStr, "", Result, Context);
|
||||
mustache([C | Rest], Result, Context) ->
|
||||
mustache(Rest, [C | Result], Context).
|
||||
mustache_key([$}, $} | Rest], KeyStr, Result, Context) ->
|
||||
Key = erlang:list_to_existing_atom(lists:reverse(KeyStr)),
|
||||
{ok, Value} = dict:find(Key, Context),
|
||||
mustache(Rest, lists:reverse(Value) ++ Result, Context);
|
||||
mustache_key([C | Rest], KeyStr, Result, Context) ->
|
||||
mustache_key(Rest, [C | KeyStr], Result, Context).
|
||||
|
||||
%% support minimal overlay based on rebar overlays
|
||||
process_overlay(RelToolConfig, TargetDir, OverlayConfig) ->
|
||||
BootRelVsn = boot_rel_vsn(RelToolConfig),
|
||||
OverlayVars =
|
||||
dict:from_list([{erts_vsn, "erts-" ++ erlang:system_info(version)},
|
||||
{rel_vsn, BootRelVsn},
|
||||
{target_dir, TargetDir},
|
||||
{hostname, net_adm:localhost()}]),
|
||||
{ok, BaseDir} = file:get_cwd(),
|
||||
execute_overlay(OverlayConfig, OverlayVars, BaseDir, TargetDir).
|
||||
|
||||
execute_overlay([], _Vars, _BaseDir, _TargetDir) ->
|
||||
ok;
|
||||
execute_overlay([{mkdir, Out} | Rest], Vars, BaseDir, TargetDir) ->
|
||||
OutDir = mustache(filename:join(TargetDir, Out), Vars),
|
||||
ok = shell("mkdir -p ~s", [OutDir]),
|
||||
execute_overlay(Rest, Vars, BaseDir, TargetDir);
|
||||
execute_overlay([{copy, In, Out} | Rest], Vars, BaseDir, TargetDir) ->
|
||||
InFile = mustache(filename:join(BaseDir, In), Vars),
|
||||
OutFile = mustache(filename:join(TargetDir, Out), Vars),
|
||||
true = filelib:is_file(InFile),
|
||||
ok = shell("cp -R ~s ~s", [InFile, OutFile]),
|
||||
execute_overlay(Rest, Vars, BaseDir, TargetDir).
|
||||
|
||||
exit_code(ExitCode) ->
|
||||
erlang:halt(ExitCode, [{flush, true}]).
|
||||
|
||||
161
samples/GLSL/SyLens.glsl
Normal file
161
samples/GLSL/SyLens.glsl
Normal file
@@ -0,0 +1,161 @@
|
||||
#version 120
|
||||
|
||||
/*
|
||||
Original Lens Distortion Algorithm from SSontech (Syntheyes)
|
||||
http://www.ssontech.com/content/lensalg.htm
|
||||
|
||||
r2 is radius squared.
|
||||
|
||||
r2 = image_aspect*image_aspect*u*u + v*v
|
||||
f = 1 + r2*(k + kcube*sqrt(r2))
|
||||
u' = f*u
|
||||
v' = f*v
|
||||
|
||||
*/
|
||||
|
||||
// Controls
|
||||
uniform float kCoeff, kCube, uShift, vShift;
|
||||
uniform float chroma_red, chroma_green, chroma_blue;
|
||||
uniform bool apply_disto;
|
||||
|
||||
// Uniform inputs
|
||||
uniform sampler2D input1;
|
||||
uniform float adsk_input1_w, adsk_input1_h, adsk_input1_aspect, adsk_input1_frameratio;
|
||||
uniform float adsk_result_w, adsk_result_h;
|
||||
|
||||
float distortion_f(float r) {
|
||||
float f = 1 + (r*r)*(kCoeff + kCube * r);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
float inverse_f(float r)
|
||||
{
|
||||
|
||||
// Build a lookup table on the radius, as a fixed-size table.
|
||||
// We will use a vec3 since we will store the multipled number in the Z coordinate.
|
||||
// So to recap: x will be the radius, y will be the f(x) distortion, and Z will be x * y;
|
||||
vec3[48] lut;
|
||||
|
||||
// Since out LUT is shader-global check if it's been computed alrite
|
||||
// Flame has no overflow bbox so we can safely max out at the image edge, plus some cushion
|
||||
float max_r = sqrt((adsk_input1_frameratio * adsk_input1_frameratio) + 1) + 0.1;
|
||||
float incr = max_r / 48;
|
||||
float lut_r = 0;
|
||||
float f;
|
||||
for(int i=0; i < 48; i++) {
|
||||
f = distortion_f(lut_r);
|
||||
lut[i] = vec3(lut_r, f, lut_r * f);
|
||||
lut_r += incr;
|
||||
}
|
||||
|
||||
float t;
|
||||
// Now find the nehgbouring elements
|
||||
// only iterate to 46 since we will need
|
||||
// 47 as i+1
|
||||
for(int i=0; i < 47; i++) {
|
||||
if(lut[i].z < r && lut[i+1].z > r) {
|
||||
// BAM! our value is between these two segments
|
||||
// get the T interpolant and mix
|
||||
t = (r - lut[i].z) / (lut[i+1].z - lut[i]).z;
|
||||
return mix(lut[i].y, lut[i+1].y, t );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float aberrate(float f, float chroma)
|
||||
{
|
||||
return f + (f * chroma);
|
||||
}
|
||||
|
||||
vec3 chromaticize_and_invert(float f)
|
||||
{
|
||||
vec3 rgb_f = vec3(aberrate(f, chroma_red), aberrate(f, chroma_green), aberrate(f, chroma_blue));
|
||||
// We need to DIVIDE by F when we redistort, and x / y == x * (1 / y)
|
||||
if(apply_disto) {
|
||||
rgb_f = 1 / rgb_f;
|
||||
}
|
||||
return rgb_f;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec2 px, uv;
|
||||
float f = 1;
|
||||
float r = 1;
|
||||
|
||||
px = gl_FragCoord.xy;
|
||||
|
||||
// Make sure we are still centered
|
||||
px.x -= (adsk_result_w - adsk_input1_w) / 2;
|
||||
px.y -= (adsk_result_h - adsk_input1_h) / 2;
|
||||
|
||||
// Push the destination coordinates into the [0..1] range
|
||||
uv.x = px.x / adsk_input1_w;
|
||||
uv.y = px.y / adsk_input1_h;
|
||||
|
||||
|
||||
// And to Syntheyes UV which are [1..-1] on both X and Y
|
||||
uv.x = (uv.x *2 ) - 1;
|
||||
uv.y = (uv.y *2 ) - 1;
|
||||
|
||||
// Add UV shifts
|
||||
uv.x += uShift;
|
||||
uv.y += vShift;
|
||||
|
||||
// Make the X value the aspect value, so that the X coordinates go to [-aspect..aspect]
|
||||
uv.x = uv.x * adsk_input1_frameratio;
|
||||
|
||||
// Compute the radius
|
||||
r = sqrt(uv.x*uv.x + uv.y*uv.y);
|
||||
|
||||
// If we are redistorting, account for the oversize plate in the input, assume that
|
||||
// the input aspect is the same
|
||||
if(apply_disto) {
|
||||
r = r / (float(adsk_input1_w) / float(adsk_result_w));
|
||||
}
|
||||
|
||||
// Apply or remove disto, per channel honoring chromatic aberration
|
||||
if(apply_disto) {
|
||||
f = inverse_f(r);
|
||||
} else {
|
||||
f = distortion_f(r);
|
||||
}
|
||||
|
||||
vec2[3] rgb_uvs = vec2[](uv, uv, uv);
|
||||
|
||||
// Compute distortions per component
|
||||
vec3 rgb_f = chromaticize_and_invert(f);
|
||||
|
||||
// Apply the disto coefficients, per component
|
||||
rgb_uvs[0] = rgb_uvs[0] * rgb_f.rr;
|
||||
rgb_uvs[1] = rgb_uvs[1] * rgb_f.gg;
|
||||
rgb_uvs[2] = rgb_uvs[2] * rgb_f.bb;
|
||||
|
||||
// Convert all the UVs back to the texture space, per color component
|
||||
for(int i=0; i < 3; i++) {
|
||||
uv = rgb_uvs[i];
|
||||
|
||||
// Back from [-aspect..aspect] to [-1..1]
|
||||
uv.x = uv.x / adsk_input1_frameratio;
|
||||
|
||||
// Remove UV shifts
|
||||
uv.x -= uShift;
|
||||
uv.y -= vShift;
|
||||
|
||||
// Back to OGL UV
|
||||
uv.x = (uv.x + 1) / 2;
|
||||
uv.y = (uv.y + 1) / 2;
|
||||
|
||||
rgb_uvs[i] = uv;
|
||||
}
|
||||
|
||||
// Sample the input plate, per component
|
||||
vec4 sampled;
|
||||
sampled.r = texture2D(input1, rgb_uvs[0]).r;
|
||||
sampled.g = texture2D(input1, rgb_uvs[1]).g;
|
||||
sampled.b = texture2D(input1, rgb_uvs[2]).b;
|
||||
|
||||
// and assign to the output
|
||||
gl_FragColor.rgba = vec4(sampled.rgb, 1.0 );
|
||||
}
|
||||
630
samples/GLSL/islandScene.glsl
Normal file
630
samples/GLSL/islandScene.glsl
Normal file
@@ -0,0 +1,630 @@
|
||||
//// High quality (Some browsers may freeze or crash)
|
||||
//#define HIGHQUALITY
|
||||
|
||||
//// Medium quality (Should be fine on all systems, works on Intel HD2000 on Win7 but quite slow)
|
||||
//#define MEDIUMQUALITY
|
||||
|
||||
//// Defaults
|
||||
//#define REFLECTIONS
|
||||
#define SHADOWS
|
||||
//#define GRASS
|
||||
//#define SMALL_WAVES
|
||||
#define RAGGED_LEAVES
|
||||
//#define DETAILED_NOISE
|
||||
//#define LIGHT_AA // 2 sample SSAA
|
||||
//#define HEAVY_AA // 2x2 RG SSAA
|
||||
//#define TONEMAP
|
||||
|
||||
//// Configurations
|
||||
#ifdef MEDIUMQUALITY
|
||||
#define SHADOWS
|
||||
#define SMALL_WAVES
|
||||
#define RAGGED_LEAVES
|
||||
#define TONEMAP
|
||||
#endif
|
||||
|
||||
#ifdef HIGHQUALITY
|
||||
#define REFLECTIONS
|
||||
#define SHADOWS
|
||||
//#define GRASS
|
||||
#define SMALL_WAVES
|
||||
#define RAGGED_LEAVES
|
||||
#define DETAILED_NOISE
|
||||
#define LIGHT_AA
|
||||
#define TONEMAP
|
||||
#endif
|
||||
|
||||
// Constants
|
||||
const float eps = 1e-5;
|
||||
const float PI = 3.14159265359;
|
||||
|
||||
const vec3 sunDir = vec3(0.79057,-0.47434, 0.0);
|
||||
const vec3 skyCol = vec3(0.3, 0.5, 0.8);
|
||||
const vec3 sandCol = vec3(0.9, 0.8, 0.5);
|
||||
const vec3 treeCol = vec3(0.8, 0.65, 0.3);
|
||||
const vec3 grassCol = vec3(0.4, 0.5, 0.18);
|
||||
const vec3 leavesCol = vec3(0.3, 0.6, 0.2);
|
||||
const vec3 leavesPos = vec3(-5.1,13.4, 0.0);
|
||||
|
||||
#ifdef TONEMAP
|
||||
const vec3 sunCol = vec3(1.8, 1.7, 1.6);
|
||||
#else
|
||||
const vec3 sunCol = vec3(0.9, 0.85, 0.8);
|
||||
#endif
|
||||
|
||||
const float exposure = 1.1; // Only used when tonemapping
|
||||
|
||||
// Description : Array and textureless GLSL 2D/3D/4D simplex
|
||||
// noise functions.
|
||||
// Author : Ian McEwan, Ashima Arts.
|
||||
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
|
||||
// Distributed under the MIT License. See LICENSE file.
|
||||
// https://github.com/ashima/webgl-noise
|
||||
vec3 mod289(vec3 x) {
|
||||
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
||||
}
|
||||
|
||||
vec4 mod289(vec4 x) {
|
||||
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
||||
}
|
||||
|
||||
vec4 permute(vec4 x) {
|
||||
return mod289(((x*34.0)+1.0)*x);
|
||||
}
|
||||
|
||||
vec4 taylorInvSqrt(vec4 r) {
|
||||
return 1.79284291400159 - 0.85373472095314 * r;
|
||||
}
|
||||
|
||||
float snoise(vec3 v) {
|
||||
const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
|
||||
const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
|
||||
|
||||
// First corner
|
||||
vec3 i = floor(v + dot(v, C.yyy) );
|
||||
vec3 x0 = v - i + dot(i, C.xxx) ;
|
||||
|
||||
// Other corners
|
||||
vec3 g = step(x0.yzx, x0.xyz);
|
||||
vec3 l = 1.0 - g;
|
||||
vec3 i1 = min( g.xyz, l.zxy );
|
||||
vec3 i2 = max( g.xyz, l.zxy );
|
||||
|
||||
// x0 = x0 - 0.0 + 0.0 * C.xxx;
|
||||
// x1 = x0 - i1 + 1.0 * C.xxx;
|
||||
// x2 = x0 - i2 + 2.0 * C.xxx;
|
||||
// x3 = x0 - 1.0 + 3.0 * C.xxx;
|
||||
vec3 x1 = x0 - i1 + C.xxx;
|
||||
vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
|
||||
vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
|
||||
|
||||
// Permutations
|
||||
i = mod289(i);
|
||||
vec4 p = permute( permute( permute(
|
||||
i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
|
||||
+ i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
|
||||
+ i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
|
||||
|
||||
// Gradients: 7x7 points over a square, mapped onto an octahedron.
|
||||
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
|
||||
float n_ = 0.142857142857; // 1.0/7.0
|
||||
vec3 ns = n_ * D.wyz - D.xzx;
|
||||
|
||||
vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
|
||||
|
||||
vec4 x_ = floor(j * ns.z);
|
||||
vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
|
||||
|
||||
vec4 x = x_ *ns.x + ns.yyyy;
|
||||
vec4 y = y_ *ns.x + ns.yyyy;
|
||||
vec4 h = 1.0 - abs(x) - abs(y);
|
||||
|
||||
vec4 b0 = vec4( x.xy, y.xy );
|
||||
vec4 b1 = vec4( x.zw, y.zw );
|
||||
|
||||
//vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
|
||||
//vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
|
||||
vec4 s0 = floor(b0)*2.0 + 1.0;
|
||||
vec4 s1 = floor(b1)*2.0 + 1.0;
|
||||
vec4 sh = -step(h, vec4(0.0));
|
||||
|
||||
vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
|
||||
vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
|
||||
|
||||
vec3 p0 = vec3(a0.xy,h.x);
|
||||
vec3 p1 = vec3(a0.zw,h.y);
|
||||
vec3 p2 = vec3(a1.xy,h.z);
|
||||
vec3 p3 = vec3(a1.zw,h.w);
|
||||
|
||||
//Normalise gradients
|
||||
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
|
||||
p0 *= norm.x;
|
||||
p1 *= norm.y;
|
||||
p2 *= norm.z;
|
||||
p3 *= norm.w;
|
||||
|
||||
// Mix final noise value
|
||||
vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
|
||||
m = m * m;
|
||||
return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
|
||||
dot(p2,x2), dot(p3,x3) ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Main
|
||||
float fbm(vec3 p)
|
||||
{
|
||||
float final = snoise(p);
|
||||
p *= 1.94; final += snoise(p) * 0.5;
|
||||
#ifdef DETAILED_NOISE
|
||||
p *= 3.75; final += snoise(p) * 0.25;
|
||||
return final / 1.75;
|
||||
#else
|
||||
return final / 1.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
float waterHeight(vec3 p)
|
||||
{
|
||||
float d = length(p.xz);
|
||||
float h = sin(d * 1.5 + iGlobalTime * 3.0) * 12.0 / d; // Island waves
|
||||
#ifdef SMALL_WAVES
|
||||
h += fbm(p*0.5); // Other waves
|
||||
#endif
|
||||
return h;
|
||||
}
|
||||
|
||||
vec3 bump(vec3 pos, vec3 rayDir)
|
||||
{
|
||||
float s = 2.0;
|
||||
|
||||
// Fade out waves to reduce aliasing
|
||||
float dist = dot(pos, rayDir);
|
||||
s *= dist < 2.0 ? 1.0 : 1.4142 / sqrt(dist);
|
||||
|
||||
// Calculate normal from heightmap
|
||||
vec2 e = vec2(1e-2, 0.0);
|
||||
vec3 p = vec3(pos.x, iGlobalTime*0.5, pos.z)*0.7;
|
||||
float m = waterHeight(p)*s;
|
||||
return normalize(vec3(
|
||||
waterHeight(p+e.xyy)*s-m,
|
||||
1.0,
|
||||
waterHeight(p+e.yxy)*s-m
|
||||
));
|
||||
}
|
||||
|
||||
// Ray intersections
|
||||
vec4 intersectSphere(vec3 rpos, vec3 rdir, vec3 pos, float rad)
|
||||
{
|
||||
vec3 op = pos - rpos;
|
||||
float b = dot(op, rdir);
|
||||
float det = b*b - dot(op, op) + rad*rad;
|
||||
|
||||
if (det > 0.0)
|
||||
{
|
||||
det = sqrt(det);
|
||||
float t = b - det;
|
||||
if (t > eps)
|
||||
return vec4(-normalize(rpos+rdir*t-pos), t);
|
||||
}
|
||||
|
||||
return vec4(0.0);
|
||||
}
|
||||
|
||||
vec4 intersectCylinder(vec3 rpos, vec3 rdir, vec3 pos, float rad)
|
||||
{
|
||||
vec3 op = pos - rpos;
|
||||
vec2 rdir2 = normalize(rdir.yz);
|
||||
float b = dot(op.yz, rdir2);
|
||||
float det = b*b - dot(op.yz, op.yz) + rad*rad;
|
||||
|
||||
if (det > 0.0)
|
||||
{
|
||||
det = sqrt(det);
|
||||
float t = b - det;
|
||||
if (t > eps)
|
||||
return vec4(-normalize(rpos.yz+rdir2*t-pos.yz), 0.0, t);
|
||||
t = b + det;
|
||||
if (t > eps)
|
||||
return vec4(-normalize(rpos.yz+rdir2*t-pos.yz), 0.0, t);
|
||||
}
|
||||
|
||||
return vec4(0.0);
|
||||
}
|
||||
|
||||
vec4 intersectPlane(vec3 rayPos, vec3 rayDir, vec3 n, float d)
|
||||
{
|
||||
float t = -(dot(rayPos, n) + d) / dot(rayDir, n);
|
||||
return vec4(n * sign(dot(rayDir, n)), t);
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
vec3 rotate(vec3 p, float theta)
|
||||
{
|
||||
float c = cos(theta), s = sin(theta);
|
||||
return vec3(p.x * c + p.z * s, p.y,
|
||||
p.z * c - p.x * s);
|
||||
}
|
||||
|
||||
float impulse(float k, float x) // by iq
|
||||
{
|
||||
float h = k*x;
|
||||
return h * exp(1.0 - h);
|
||||
}
|
||||
|
||||
// Raymarched parts of scene
|
||||
float grass(vec3 pos)
|
||||
{
|
||||
float h = length(pos - vec3(0.0, -7.0, 0.0)) - 8.0;
|
||||
|
||||
if (h > 2.0) return h; // Optimization (Avoid noise if too far away)
|
||||
|
||||
return h + snoise(pos * 3.0) * 0.1 + pos.y * 0.9;
|
||||
}
|
||||
|
||||
float tree(vec3 pos)
|
||||
{
|
||||
pos.y -= 0.5;
|
||||
float s = sin(pos.y*0.03);
|
||||
float c = cos(pos.y*0.03);
|
||||
mat2 m = mat2(c, -s, s, c);
|
||||
vec3 p = vec3(m*pos.xy, pos.z);
|
||||
|
||||
float width = 1.0 - pos.y * 0.02 - clamp(sin(pos.y * 8.0) * 0.1, 0.05, 0.1);
|
||||
|
||||
return max(length(p.xz) - width, pos.y - 12.5);
|
||||
}
|
||||
|
||||
vec2 scene(vec3 pos)
|
||||
{
|
||||
float vtree = tree(pos);
|
||||
#ifdef GRASS
|
||||
float vgrass = grass(pos);
|
||||
float v = min(vtree, vgrass);
|
||||
#else
|
||||
float v = vtree;
|
||||
#endif
|
||||
return vec2(v, v == vtree ? 2.0 : 1.0);
|
||||
}
|
||||
|
||||
vec3 normal(vec3 pos)
|
||||
{
|
||||
vec2 eps = vec2(1e-3, 0.0);
|
||||
float h = scene(pos).x;
|
||||
return normalize(vec3(
|
||||
scene(pos-eps.xyy).x-h,
|
||||
scene(pos-eps.yxy).x-h,
|
||||
scene(pos-eps.yyx).x-h
|
||||
));
|
||||
}
|
||||
|
||||
float plantsShadow(vec3 rayPos, vec3 rayDir)
|
||||
{
|
||||
// Soft shadow taken from iq
|
||||
float k = 6.0;
|
||||
float t = 0.0;
|
||||
float s = 1.0;
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
vec3 pos = rayPos+rayDir*t;
|
||||
vec2 res = scene(pos);
|
||||
if (res.x < 0.001) return 0.0;
|
||||
s = min(s, k*res.x/t);
|
||||
t += max(res.x, 0.01);
|
||||
}
|
||||
|
||||
return s*s*(3.0 - 2.0*s);
|
||||
}
|
||||
|
||||
// Ray-traced parts of scene
|
||||
vec4 intersectWater(vec3 rayPos, vec3 rayDir)
|
||||
{
|
||||
float h = sin(20.5 + iGlobalTime * 2.0) * 0.03;
|
||||
float t = -(rayPos.y + 2.5 + h) / rayDir.y;
|
||||
return vec4(0.0, 1.0, 0.0, t);
|
||||
}
|
||||
|
||||
vec4 intersectSand(vec3 rayPos, vec3 rayDir)
|
||||
{
|
||||
return intersectSphere(rayPos, rayDir, vec3(0.0,-24.1,0.0), 24.1);
|
||||
}
|
||||
|
||||
vec4 intersectTreasure(vec3 rayPos, vec3 rayDir)
|
||||
{
|
||||
return vec4(0.0);
|
||||
}
|
||||
|
||||
vec4 intersectLeaf(vec3 rayPos, vec3 rayDir, float openAmount)
|
||||
{
|
||||
vec3 dir = normalize(vec3(0.0, 1.0, openAmount));
|
||||
float offset = 0.0;
|
||||
|
||||
vec4 res = intersectPlane(rayPos, rayDir, dir, 0.0);
|
||||
vec3 pos = rayPos+rayDir*res.w;
|
||||
#ifdef RAGGED_LEAVES
|
||||
offset = snoise(pos*0.8) * 0.3;
|
||||
#endif
|
||||
if (pos.y > 0.0 || length(pos * vec3(0.9, 2.0, 1.0)) > 4.0 - offset) res.w = 0.0;
|
||||
|
||||
vec4 res2 = intersectPlane(rayPos, rayDir, vec3(dir.xy, -dir.z), 0.0);
|
||||
pos = rayPos+rayDir*res2.w;
|
||||
#ifdef RAGGED_LEAVES
|
||||
offset = snoise(pos*0.8) * 0.3;
|
||||
#endif
|
||||
if (pos.y > 0.0 || length(pos * vec3(0.9, 2.0, 1.0)) > 4.0 - offset) res2.w = 0.0;
|
||||
|
||||
if (res2.w > 0.0 && res2.w < res.w || res.w <= 0.0)
|
||||
res = res2;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
vec4 leaves(vec3 rayPos, vec3 rayDir)
|
||||
{
|
||||
float t = 1e20;
|
||||
vec3 n = vec3(0.0);
|
||||
|
||||
rayPos -= leavesPos;
|
||||
|
||||
float sway = impulse(15.0, fract(iGlobalTime / PI * 0.125));
|
||||
float upDownSway = sway * -sin(iGlobalTime) * 0.06;
|
||||
float openAmount = sway * max(-cos(iGlobalTime) * 0.4, 0.0);
|
||||
|
||||
float angleOffset = -0.1;
|
||||
for (float k = 0.0; k < 6.2; k += 0.75)
|
||||
{
|
||||
// Left-right
|
||||
float alpha = k + (k - PI) * sway * 0.015;
|
||||
vec3 p = rotate(rayPos, alpha);
|
||||
vec3 d = rotate(rayDir, alpha);
|
||||
|
||||
// Up-down
|
||||
angleOffset *= -1.0;
|
||||
float theta = -0.4 +
|
||||
angleOffset +
|
||||
cos(k) * 0.35 +
|
||||
upDownSway +
|
||||
sin(iGlobalTime+k*10.0) * 0.03 * (sway + 0.2);
|
||||
|
||||
p = rotate(p.xzy, theta).xzy;
|
||||
d = rotate(d.xzy, theta).xzy;
|
||||
|
||||
// Shift
|
||||
p -= vec3(5.4, 0.0, 0.0);
|
||||
|
||||
// Intersect individual leaf
|
||||
vec4 res = intersectLeaf(p, d, 1.0+openAmount);
|
||||
if (res.w > 0.0 && res.w < t)
|
||||
{
|
||||
t = res.w;
|
||||
n = res.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
return vec4(n, t);
|
||||
}
|
||||
|
||||
// Lighting
|
||||
float shadow(vec3 rayPos, vec3 rayDir)
|
||||
{
|
||||
float s = 1.0;
|
||||
|
||||
// Intersect sand
|
||||
//vec4 resSand = intersectSand(rayPos, rayDir);
|
||||
//if (resSand.w > 0.0) return 0.0;
|
||||
|
||||
// Intersect plants
|
||||
s = min(s, plantsShadow(rayPos, rayDir));
|
||||
if (s < 0.0001) return 0.0;
|
||||
|
||||
// Intersect leaves
|
||||
vec4 resLeaves = leaves(rayPos, rayDir);
|
||||
if (resLeaves.w > 0.0 && resLeaves.w < 1e7) return 0.0;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
vec3 light(vec3 p, vec3 n)
|
||||
{
|
||||
float s = 1.0;
|
||||
|
||||
#ifdef SHADOWS
|
||||
s = shadow(p-sunDir*0.01, -sunDir);
|
||||
#endif
|
||||
|
||||
vec3 col = sunCol * min(max(dot(n, sunDir), 0.0), s);
|
||||
col += skyCol * (-n.y * 0.5 + 0.5) * 0.3;
|
||||
return col;
|
||||
}
|
||||
|
||||
vec3 lightLeaves(vec3 p, vec3 n)
|
||||
{
|
||||
float s = 1.0;
|
||||
|
||||
#ifdef SHADOWS
|
||||
s = shadow(p-sunDir*0.01, -sunDir);
|
||||
#endif
|
||||
|
||||
float ao = min(length(p - leavesPos) * 0.1, 1.0);
|
||||
|
||||
float ns = dot(n, sunDir);
|
||||
float d = sqrt(max(ns, 0.0));
|
||||
vec3 col = sunCol * min(d, s);
|
||||
col += sunCol * max(-ns, 0.0) * vec3(0.3, 0.3, 0.1) * ao;
|
||||
col += skyCol * (-n.y * 0.5 + 0.5) * 0.3 * ao;
|
||||
return col;
|
||||
}
|
||||
|
||||
vec3 sky(vec3 n)
|
||||
{
|
||||
return skyCol * (1.0 - n.y * 0.8);
|
||||
}
|
||||
|
||||
// Ray-marching
|
||||
vec4 plants(vec3 rayPos, vec3 rayDir)
|
||||
{
|
||||
float t = 0.0;
|
||||
|
||||
for (int i = 0; i < 40; i++)
|
||||
{
|
||||
vec3 pos = rayPos+rayDir*t;
|
||||
vec2 res = scene(pos);
|
||||
float h = res.x;
|
||||
|
||||
if (h < 0.001)
|
||||
{
|
||||
vec3 col = res.y == 2.0 ? treeCol : grassCol;
|
||||
float uvFact = res.y == 2.0 ? 1.0 : 10.0;
|
||||
|
||||
vec3 n = normal(pos);
|
||||
vec2 uv = vec2(n.x, pos.y * 0.5) * 0.2 * uvFact;
|
||||
vec3 tex = texture2D(iChannel0, uv).rgb * 0.6 + 0.4;
|
||||
float ao = min(length(pos - leavesPos) * 0.1, 1.0);
|
||||
return vec4(col * light(pos, n) * ao * tex, t);
|
||||
}
|
||||
|
||||
t += h;
|
||||
}
|
||||
|
||||
return vec4(sky(rayDir), 1e8);
|
||||
}
|
||||
|
||||
// Final combination
|
||||
vec3 traceReflection(vec3 rayPos, vec3 rayDir)
|
||||
{
|
||||
vec3 col = vec3(0.0);
|
||||
float t = 1e20;
|
||||
|
||||
// Intersect plants
|
||||
vec4 resPlants = plants(rayPos, rayDir);
|
||||
if (resPlants.w > 0.0 && resPlants.w < t)
|
||||
{
|
||||
t = resPlants.w;
|
||||
col = resPlants.xyz;
|
||||
}
|
||||
|
||||
// Intersect leaves
|
||||
vec4 resLeaves = leaves(rayPos, rayDir);
|
||||
if (resLeaves.w > 0.0 && resLeaves.w < t)
|
||||
{
|
||||
vec3 pos = rayPos + rayDir * resLeaves.w;
|
||||
vec2 uv = (pos.xz - leavesPos.xz) * 0.3;
|
||||
float tex = texture2D(iChannel0, uv).r * 0.6 + 0.5;
|
||||
|
||||
t = resLeaves.w;
|
||||
col = leavesCol * lightLeaves(pos, resLeaves.xyz) * tex;
|
||||
}
|
||||
|
||||
if (t > 1e7) return sky(rayDir);
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
vec3 trace(vec3 rayPos, vec3 rayDir)
|
||||
{
|
||||
vec3 col = vec3(0.0);
|
||||
float t = 1e20;
|
||||
|
||||
// Intersect sand
|
||||
vec4 resSand = intersectSand(rayPos, rayDir);
|
||||
if (resSand.w > 0.0)
|
||||
{
|
||||
vec3 pos = rayPos + rayDir * resSand.w;
|
||||
t = resSand.w;
|
||||
|
||||
col = sandCol * light(pos, resSand.xyz);
|
||||
}
|
||||
|
||||
// Intersect treasure chest
|
||||
vec4 resTreasure = intersectTreasure(rayPos, rayDir);
|
||||
if (resTreasure.w > 0.0 && resTreasure.w < t)
|
||||
{
|
||||
vec3 pos = rayPos + rayDir * resTreasure.w;
|
||||
t = resTreasure.w;
|
||||
col = leavesCol * light(pos, resTreasure.xyz);
|
||||
}
|
||||
|
||||
// Intersect leaves
|
||||
vec4 resLeaves = leaves(rayPos, rayDir);
|
||||
if (resLeaves.w > 0.0 && resLeaves.w < t)
|
||||
{
|
||||
vec3 pos = rayPos + rayDir * resLeaves.w;
|
||||
vec2 uv = (pos.xz - leavesPos.xz) * 0.3;
|
||||
float tex = texture2D(iChannel0, uv).r * 0.6 + 0.5;
|
||||
|
||||
t = resLeaves.w;
|
||||
col = leavesCol * lightLeaves(pos, resLeaves.xyz) * tex;
|
||||
}
|
||||
|
||||
// Intersect plants
|
||||
vec4 resPlants = plants(rayPos, rayDir);
|
||||
if (resPlants.w > 0.0 && resPlants.w < t)
|
||||
{
|
||||
t = resPlants.w;
|
||||
col = resPlants.xyz;
|
||||
}
|
||||
|
||||
// Intersect water
|
||||
vec4 resWater = intersectWater(rayPos, rayDir);
|
||||
if (resWater.w > 0.0 && resWater.w < t)
|
||||
{
|
||||
vec3 pos = rayPos + rayDir * resWater.w;
|
||||
float dist = t - resWater.w;
|
||||
vec3 n = bump(pos, rayDir);
|
||||
|
||||
float ct = -min(dot(n,rayDir), 0.0);
|
||||
float fresnel = 0.9 - 0.9 * pow(1.0 - ct, 5.0);
|
||||
|
||||
vec3 trans = col * exp(-dist * vec3(1.0, 0.7, 0.4) * 3.0);
|
||||
vec3 reflDir = normalize(reflect(rayDir, n));
|
||||
vec3 refl = sky(reflDir);
|
||||
|
||||
#ifdef REFLECTIONS
|
||||
if (dot(pos, rayDir) < -2.0)
|
||||
refl = traceReflection(pos, reflDir).rgb;
|
||||
#endif
|
||||
|
||||
t = resWater.t;
|
||||
col = mix(refl, trans, fresnel);
|
||||
}
|
||||
|
||||
if (t > 1e7) return sky(rayDir);
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
// Ray-generation
|
||||
vec3 camera(vec2 px)
|
||||
{
|
||||
vec2 rd = (px / iResolution.yy - vec2(iResolution.x/iResolution.y*0.5-0.5, 0.0)) * 2.0 - 1.0;
|
||||
float t = sin(iGlobalTime * 0.1) * 0.2;
|
||||
vec3 rayDir = normalize(vec3(rd.x, rd.y, 1.0));
|
||||
vec3 rayPos = vec3(0.0, 3.0, -18.0);
|
||||
return trace(rayPos, rayDir);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
#ifdef HEAVY_AA
|
||||
vec3 col = camera(gl_FragCoord.xy+vec2(0.0,0.5))*0.25;
|
||||
col += camera(gl_FragCoord.xy+vec2(0.25,0.0))*0.25;
|
||||
col += camera(gl_FragCoord.xy+vec2(0.5,0.75))*0.25;
|
||||
col += camera(gl_FragCoord.xy+vec2(0.75,0.25))*0.25;
|
||||
#else
|
||||
vec3 col = camera(gl_FragCoord.xy);
|
||||
#ifdef LIGHT_AA
|
||||
col = col * 0.5 + camera(gl_FragCoord.xy+vec2(0.5,0.5))*0.5;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TONEMAP
|
||||
// Optimized Haarm-Peter Duiker’s curve
|
||||
vec3 x = max(vec3(0.0),col*exposure-0.004);
|
||||
col = (x*(6.2*x+.5))/(x*(6.2*x+1.7)+0.06);
|
||||
#else
|
||||
col = pow(col, vec3(0.4545));
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4(col, 1.0);
|
||||
}
|
||||
68
samples/GLSL/shader.fp
Normal file
68
samples/GLSL/shader.fp
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Josh A. Beam
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
const int NUM_LIGHTS = 3;
|
||||
const vec3 AMBIENT = vec3(0.1, 0.1, 0.1);
|
||||
const float MAX_DIST = 2.5;
|
||||
const float MAX_DIST_SQUARED = MAX_DIST * MAX_DIST;
|
||||
|
||||
uniform vec3 lightColor[NUM_LIGHTS];
|
||||
|
||||
varying vec3 fragmentNormal;
|
||||
varying vec3 cameraVector;
|
||||
varying vec3 lightVector[NUM_LIGHTS];
|
||||
|
||||
void
|
||||
main()
|
||||
{
|
||||
// initialize diffuse/specular lighting
|
||||
vec3 diffuse = vec3(0.0, 0.0, 0.0);
|
||||
vec3 specular = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
// normalize the fragment normal and camera direction
|
||||
vec3 normal = normalize(fragmentNormal);
|
||||
vec3 cameraDir = normalize(cameraVector);
|
||||
|
||||
// loop through each light
|
||||
for(int i = 0; i < NUM_LIGHTS; ++i) {
|
||||
// calculate distance between 0.0 and 1.0
|
||||
float dist = min(dot(lightVector[i], lightVector[i]), MAX_DIST_SQUARED) / MAX_DIST_SQUARED;
|
||||
float distFactor = 1.0 - dist;
|
||||
|
||||
// diffuse
|
||||
vec3 lightDir = normalize(lightVector[i]);
|
||||
float diffuseDot = dot(normal, lightDir);
|
||||
diffuse += lightColor[i] * clamp(diffuseDot, 0.0, 1.0) * distFactor;
|
||||
|
||||
// specular
|
||||
vec3 halfAngle = normalize(cameraDir + lightDir);
|
||||
vec3 specularColor = min(lightColor[i] + 0.5, 1.0);
|
||||
float specularDot = dot(normal, halfAngle);
|
||||
specular += specularColor * pow(clamp(specularDot, 0.0, 1.0), 16.0) * distFactor;
|
||||
}
|
||||
|
||||
vec4 sample = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
gl_FragColor = vec4(clamp(sample.rgb * (diffuse + AMBIENT) + specular, 0.0, 1.0), sample.a);
|
||||
}
|
||||
111
samples/LFE/church.lfe
Normal file
111
samples/LFE/church.lfe
Normal file
@@ -0,0 +1,111 @@
|
||||
;; Copyright (c) 2013 Duncan McGreggor <oubiwann@cogitat.io>
|
||||
;;
|
||||
;; Licensed under the Apache License, Version 2.0 (the "License");
|
||||
;; you may not use this file except in compliance with the License.
|
||||
;; You may obtain a copy of the License at
|
||||
;;
|
||||
;; http://www.apache.org/licenses/LICENSE-2.0
|
||||
;;
|
||||
;; Unless required by applicable law or agreed to in writing, software
|
||||
;; distributed under the License is distributed on an "AS IS" BASIS,
|
||||
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
;; See the License for the specific language governing permissions and
|
||||
;; limitations under the License.
|
||||
|
||||
;; File : church.lfe
|
||||
;; Author : Duncan McGreggor
|
||||
;; Purpose : Demonstrating church numerals from the lambda calculus
|
||||
|
||||
;; The code below was used to create the section of the user guide here:
|
||||
;; http://lfe.github.io/user-guide/recursion/5.html
|
||||
;;
|
||||
;; Here is some example usage:
|
||||
;;
|
||||
;; > (slurp '"church.lfe")
|
||||
;; #(ok church)
|
||||
;; > (zero)
|
||||
;; #Fun<lfe_eval.10.53503600>
|
||||
;; > (church->int1 (zero))
|
||||
;; 0
|
||||
;; > (church->int1 (three))
|
||||
;; 3
|
||||
;; > (church->int1 (five))
|
||||
;; 5
|
||||
;; > (church->int2 #'five/0)
|
||||
;; 5
|
||||
;; > (church->int2 (lambda () (get-church 25)))
|
||||
;; 25
|
||||
|
||||
(defmodule church
|
||||
(export all))
|
||||
|
||||
(defun zero ()
|
||||
(lambda (s)
|
||||
(lambda (x) x)))
|
||||
|
||||
(defun one ()
|
||||
(lambda (s)
|
||||
(lambda (x)
|
||||
(funcall s x))))
|
||||
|
||||
(defun two ()
|
||||
(lambda (s)
|
||||
(lambda (x)
|
||||
(funcall s
|
||||
(funcall s x)))))
|
||||
|
||||
(defun three ()
|
||||
(lambda (s)
|
||||
(lambda (x)
|
||||
(funcall s
|
||||
(funcall s
|
||||
(funcall s x))))))
|
||||
|
||||
(defun four ()
|
||||
(lambda (s)
|
||||
(lambda (x)
|
||||
(funcall s
|
||||
(funcall s
|
||||
(funcall s
|
||||
(funcall s x)))))))
|
||||
|
||||
(defun five ()
|
||||
(get-church 5))
|
||||
|
||||
(defun int-successor (n)
|
||||
(+ n 1))
|
||||
|
||||
(defun church->int1 (church-numeral)
|
||||
"
|
||||
Converts a called church numeral to an integer, e.g.:
|
||||
> (church->int1 (five))
|
||||
"
|
||||
(funcall
|
||||
(funcall church-numeral #'int-successor/1) 0))
|
||||
|
||||
(defun church->int2 (church-numeral)
|
||||
"
|
||||
Converts a non-called church numeral to an integer, e.g.:
|
||||
> (church->int2 #'five/0)
|
||||
"
|
||||
(funcall
|
||||
(funcall
|
||||
(funcall church-numeral) #'int-successor/1) 0))
|
||||
|
||||
(defun church-successor (church-numeral)
|
||||
(lambda (s)
|
||||
(lambda (x)
|
||||
(funcall s
|
||||
(funcall
|
||||
(funcall church-numeral s) x)))))
|
||||
|
||||
(defun get-church (church-numeral count limit)
|
||||
(cond ((== count limit) church-numeral)
|
||||
((/= count limit)
|
||||
(get-church
|
||||
(church-successor church-numeral)
|
||||
(+ 1 count)
|
||||
limit))))
|
||||
|
||||
(defun get-church (integer)
|
||||
(get-church (zero) 0 integer))
|
||||
104
samples/LFE/gps1.lfe
Normal file
104
samples/LFE/gps1.lfe
Normal file
@@ -0,0 +1,104 @@
|
||||
;;; -*- Mode: LFE; -*-
|
||||
;;; Code from Paradigms of Artificial Intelligence Programming
|
||||
;;; Copyright (c) 1991 Peter Norvig
|
||||
|
||||
;;;; File gps1.lisp: First version of GPS (General Problem Solver)
|
||||
|
||||
;;;; Converted to LFE by Robert Virding
|
||||
|
||||
;; Define macros for global variable access. This is a hack and very naughty!
|
||||
(defsyntax defvar
|
||||
([name val] (let ((v val)) (put 'name v) v)))
|
||||
|
||||
(defsyntax setvar
|
||||
([name val] (let ((v val)) (put 'name v) v)))
|
||||
|
||||
(defsyntax getvar
|
||||
([name] (get 'name)))
|
||||
|
||||
;; Module definition.
|
||||
|
||||
(defmodule gps1
|
||||
(export (gps 2) (gps 3) (school-ops 0))
|
||||
(import (from lists (member 2) (all 2) (any 2))
|
||||
;; Rename lists functions to be more CL like.
|
||||
(rename lists ((all 2) every) ((any 2) some) ((filter 2) find-all))))
|
||||
|
||||
;; An operation.
|
||||
(defrecord op
|
||||
action preconds add-list del-list)
|
||||
|
||||
;; General Problem Solver: achieve all goals using *ops*.
|
||||
(defun gps (state goals ops)
|
||||
;; Set global variables
|
||||
(defvar *state* state) ;The current state: a list of conditions.
|
||||
(defvar *ops* ops) ;A list of available operators.
|
||||
(if (every (fun achieve 1) goals) 'solved))
|
||||
|
||||
(defun gps (state goals)
|
||||
;; Set global variables, but use existing *ops*
|
||||
(defvar *state* state) ;The current state: a list of conditions.
|
||||
(if (every (fun achieve 1) goals) 'solved))
|
||||
|
||||
;; A goal is achieved if it already holds or if there is an
|
||||
;; appropriate op for it that is applicable."
|
||||
(defun achieve (goal)
|
||||
(orelse (member goal (getvar *state*))
|
||||
(some (fun apply-op 1)
|
||||
(find-all (lambda (op) (appropriate-p goal op))
|
||||
(getvar *ops*)))))
|
||||
|
||||
;; An op is appropriate to a goal if it is in its add list.
|
||||
(defun appropriate-p (goal op)
|
||||
(member goal (op-add-list op)))
|
||||
|
||||
;; Print a message and update *state* if op is applicable.
|
||||
(defun apply-op (op)
|
||||
(if (every (fun achieve 1) (op-preconds op))
|
||||
(progn
|
||||
(: io fwrite '"executing ~p\n" (list (op-action op)))
|
||||
(setvar *state* (set-difference (getvar *state*) (op-del-list op)))
|
||||
(setvar *state* (union (getvar *state*) (op-add-list op)))
|
||||
'true)))
|
||||
|
||||
;; Define the set functions to work on list, a listsets module really.
|
||||
(defun set-difference
|
||||
([(cons e es) s2]
|
||||
(if (member e s2)
|
||||
(set-difference es s2)
|
||||
(cons e (set-difference es s2))))
|
||||
([() s2] ()))
|
||||
|
||||
(defun union
|
||||
([(cons e es) s2]
|
||||
(if (member e s2) (union es s2) (cons e (union es s2))))
|
||||
([() s2] ()))
|
||||
|
||||
;;; ==============================
|
||||
|
||||
(defun school-ops ()
|
||||
(list
|
||||
(make-op action 'drive-son-to-school
|
||||
preconds '(son-at-home car-works)
|
||||
add-list '(son-at-school)
|
||||
del-list '(son-at-home))
|
||||
(make-op action 'shop-installs-battery
|
||||
preconds '(car-needs-battery shop-knows-problem shop-has-money)
|
||||
add-list '(car-works)
|
||||
del-list ())
|
||||
(make-op action 'tell-shop-problem
|
||||
preconds '(in-communication-with-shop)
|
||||
add-list '(shop-knows-problem)
|
||||
del-list ())
|
||||
(make-op action 'telephone-shop
|
||||
preconds '(know-phone-number)
|
||||
add-list '(in-communication-with-shop)
|
||||
del-list ())
|
||||
(make-op action 'look-up-number
|
||||
preconds '(have-phone-book)
|
||||
add-list '(know-phone-number)
|
||||
del-list ())
|
||||
(make-op action 'give-shop-money
|
||||
preconds '(have-money)
|
||||
add-list '(shop-has-money)
|
||||
del-list '(have-money))))
|
||||
83
samples/LFE/mnesia_demo.lfe
Normal file
83
samples/LFE/mnesia_demo.lfe
Normal file
@@ -0,0 +1,83 @@
|
||||
;; Copyright (c) 2008-2013 Robert Virding
|
||||
;;
|
||||
;; Licensed under the Apache License, Version 2.0 (the "License");
|
||||
;; you may not use this file except in compliance with the License.
|
||||
;; You may obtain a copy of the License at
|
||||
;;
|
||||
;; http://www.apache.org/licenses/LICENSE-2.0
|
||||
;;
|
||||
;; Unless required by applicable law or agreed to in writing, software
|
||||
;; distributed under the License is distributed on an "AS IS" BASIS,
|
||||
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
;; See the License for the specific language governing permissions and
|
||||
;; limitations under the License.
|
||||
|
||||
;; File : mnesia_demo.lfe
|
||||
;; Author : Robert Virding
|
||||
;; Purpose : A simple Mnesia demo file for LFE.
|
||||
|
||||
;; This file contains a simple demo of using LFE to access Mnesia
|
||||
;; tables. It shows how to use the emp-XXXX macro (ETS match pattern)
|
||||
;; together with mnesia:match_object, match specifications with
|
||||
;; mnesia:select and Query List Comprehensions.
|
||||
|
||||
(defmodule mnesia_demo
|
||||
(export (new 0) (by_place 1) (by_place_ms 1) (by_place_qlc 1)))
|
||||
|
||||
(defrecord person name place job)
|
||||
|
||||
(defun new ()
|
||||
;; Start mnesia and create a table, we will get an in memory only schema.
|
||||
(: mnesia start)
|
||||
(: mnesia create_table 'person '(#(attributes (name place job))))
|
||||
;; Initialise the table.
|
||||
(let ((people '(
|
||||
;; First some people in London.
|
||||
#(fred london waiter)
|
||||
#(bert london waiter)
|
||||
#(john london painter)
|
||||
#(paul london driver)
|
||||
;; Now some in Paris.
|
||||
#(jean paris waiter)
|
||||
#(gerard paris driver)
|
||||
#(claude paris painter)
|
||||
#(yves paris waiter)
|
||||
;; And some in Rome.
|
||||
#(roberto rome waiter)
|
||||
#(guiseppe rome driver)
|
||||
#(paulo rome painter)
|
||||
;; And some in Berlin.
|
||||
#(fritz berlin painter)
|
||||
#(kurt berlin driver)
|
||||
#(hans berlin waiter)
|
||||
#(franz berlin waiter)
|
||||
)))
|
||||
(: lists foreach (match-lambda
|
||||
([(tuple n p j)]
|
||||
(: mnesia transaction
|
||||
(lambda ()
|
||||
(let ((new (make-person name n place p job j)))
|
||||
(: mnesia write new))))))
|
||||
people)))
|
||||
|
||||
;; Match records by place using match_object and the emp-XXXX macro.
|
||||
(defun by_place (place)
|
||||
(: mnesia transaction
|
||||
(lambda () (: mnesia match_object (emp-person place place)))))
|
||||
|
||||
;; Use match specifications to match records
|
||||
(defun by_place_ms (place)
|
||||
(let ((f (lambda () (: mnesia select 'person
|
||||
(match-spec ([(match-person name n place p job j)]
|
||||
(when (=:= p place))
|
||||
(tuple n j)))))))
|
||||
(: mnesia transaction f)))
|
||||
|
||||
;; Use Query List Comprehensions to match records
|
||||
(defun by_place_qlc (place)
|
||||
(let ((f (lambda ()
|
||||
(let ((q (qlc (lc ((<- person (: mnesia table 'person))
|
||||
(=:= (person-place person) place))
|
||||
person))))
|
||||
(: qlc e q)))))
|
||||
(: mnesia transaction f)))
|
||||
169
samples/LFE/object.lfe
Normal file
169
samples/LFE/object.lfe
Normal file
@@ -0,0 +1,169 @@
|
||||
;; Copyright (c) 2013 Duncan McGreggor <oubiwann@cogitat.io>
|
||||
;;
|
||||
;; Licensed under the Apache License, Version 2.0 (the "License");
|
||||
;; you may not use this file except in compliance with the License.
|
||||
;; You may obtain a copy of the License at
|
||||
;;
|
||||
;; http://www.apache.org/licenses/LICENSE-2.0
|
||||
;;
|
||||
;; Unless required by applicable law or agreed to in writing, software
|
||||
;; distributed under the License is distributed on an "AS IS" BASIS,
|
||||
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
;; See the License for the specific language governing permissions and
|
||||
;; limitations under the License.
|
||||
|
||||
;; File : object.lfe
|
||||
;; Author : Duncan McGreggor
|
||||
;; Purpose : Demonstrating simple OOP with closures
|
||||
|
||||
;; The simple object system demonstrated below shows how to do the following:
|
||||
;; * create objects
|
||||
;; * call methods on those objects
|
||||
;; * have methods which can call other methods
|
||||
;; * update the state of an instance variable
|
||||
;;
|
||||
;; Note, however, that his example does not demonstrate inheritance.
|
||||
;;
|
||||
;; To use the code below in LFE, do the following:
|
||||
;;
|
||||
;; $ cd examples
|
||||
;; $ ../bin/lfe -pa ../ebin
|
||||
;;
|
||||
;; Load the file and create a fish-class instance:
|
||||
;;
|
||||
;; > (slurp '"object.lfe")
|
||||
;; #(ok object)
|
||||
;; > (set mommy-fish (fish-class '"Carp"))
|
||||
;; #Fun<lfe_eval.10.91765564>
|
||||
;;
|
||||
;; Execute some of the basic methods:
|
||||
;;
|
||||
;; > (get-species mommy-fish)
|
||||
;; "Carp"
|
||||
;; > (move mommy-fish 17)
|
||||
;; The Carp swam 17 feet!
|
||||
;; ok
|
||||
;; > (get-id mommy-fish)
|
||||
;; "47eebe91a648f042fc3fb278df663de5"
|
||||
;;
|
||||
;; Now let's look at "modifying" state data (e.g., children counts):
|
||||
;;
|
||||
;; > (get-children mommy-fish)
|
||||
;; ()
|
||||
;; > (get-children-count mommy-fish)
|
||||
;; 0
|
||||
;; > (set (mommy-fish baby-fish-1) (reproduce mommy-fish))
|
||||
;; (#Fun<lfe_eval.10.91765564> #Fun<lfe_eval.10.91765564>)
|
||||
;; > (get-id mommy-fish)
|
||||
;; "47eebe91a648f042fc3fb278df663de5"
|
||||
;; > (get-id baby-fish-1)
|
||||
;; "fdcf35983bb496650e558a82e34c9935"
|
||||
;; > (get-children-count mommy-fish)
|
||||
;; 1
|
||||
;; > (set (mommy-fish baby-fish-2) (reproduce mommy-fish))
|
||||
;; (#Fun<lfe_eval.10.91765564> #Fun<lfe_eval.10.91765564>)
|
||||
;; > (get-id mommy-fish)
|
||||
;; "47eebe91a648f042fc3fb278df663de5"
|
||||
;; > (get-id baby-fish-2)
|
||||
;; "3e64e5c20fb742dd88dac1032749c2fd"
|
||||
;; > (get-children-count mommy-fish)
|
||||
;; 2
|
||||
;; > (get-info mommy-fish)
|
||||
;; id: "47eebe91a648f042fc3fb278df663de5"
|
||||
;; species: "Carp"
|
||||
;; children: ["fdcf35983bb496650e558a82e34c9935",
|
||||
;; "3e64e5c20fb742dd88dac1032749c2fd"]
|
||||
;; ok
|
||||
|
||||
(defmodule object
|
||||
(export all))
|
||||
|
||||
(defun fish-class (species)
|
||||
"
|
||||
This is the constructor that will be used most often, only requiring that
|
||||
one pass a 'species' string.
|
||||
|
||||
When the children are not defined, simply use an empty list.
|
||||
"
|
||||
(fish-class species ()))
|
||||
|
||||
(defun fish-class (species children)
|
||||
"
|
||||
This contructor is mostly useful as a way of abstracting out the id
|
||||
generation from the larger constructor. Nothing else uses fish-class/2
|
||||
besides fish-class/1, so it's not strictly necessary.
|
||||
|
||||
When the id isn't know, generate one."
|
||||
(let* (((binary (id (size 128))) (: crypto rand_bytes 16))
|
||||
(formatted-id (car
|
||||
(: io_lib format
|
||||
'"~32.16.0b" (list id)))))
|
||||
(fish-class species children formatted-id)))
|
||||
|
||||
(defun fish-class (species children id)
|
||||
"
|
||||
This is the constructor used internally, once the children and fish id are
|
||||
known.
|
||||
"
|
||||
(let ((move-verb '"swam"))
|
||||
(lambda (method-name)
|
||||
(case method-name
|
||||
('id
|
||||
(lambda (self) id))
|
||||
('species
|
||||
(lambda (self) species))
|
||||
('children
|
||||
(lambda (self) children))
|
||||
('info
|
||||
(lambda (self)
|
||||
(: io format
|
||||
'"id: ~p~nspecies: ~p~nchildren: ~p~n"
|
||||
(list (get-id self)
|
||||
(get-species self)
|
||||
(get-children self)))))
|
||||
('move
|
||||
(lambda (self distance)
|
||||
(: io format
|
||||
'"The ~s ~s ~p feet!~n"
|
||||
(list species move-verb distance))))
|
||||
('reproduce
|
||||
(lambda (self)
|
||||
(let* ((child (fish-class species))
|
||||
(child-id (get-id child))
|
||||
(children-ids (: lists append
|
||||
(list children (list child-id))))
|
||||
(parent-id (get-id self))
|
||||
(parent (fish-class species children-ids parent-id)))
|
||||
(list parent child))))
|
||||
('children-count
|
||||
(lambda (self)
|
||||
(: erlang length children)))))))
|
||||
|
||||
(defun get-method (object method-name)
|
||||
"
|
||||
This is a generic function, used to call into the given object (class
|
||||
instance).
|
||||
"
|
||||
(funcall object method-name))
|
||||
|
||||
; define object methods
|
||||
(defun get-id (object)
|
||||
(funcall (get-method object 'id) object))
|
||||
|
||||
(defun get-species (object)
|
||||
(funcall (get-method object 'species) object))
|
||||
|
||||
(defun get-info (object)
|
||||
(funcall (get-method object 'info) object))
|
||||
|
||||
(defun move (object distance)
|
||||
(funcall (get-method object 'move) object distance))
|
||||
|
||||
(defun reproduce (object)
|
||||
(funcall (get-method object 'reproduce) object))
|
||||
|
||||
(defun get-children (object)
|
||||
(funcall (get-method object 'children) object))
|
||||
|
||||
(defun get-children-count (object)
|
||||
(funcall (get-method object 'children-count) object))
|
||||
16
samples/Makefile/filenames/Makefile
Normal file
16
samples/Makefile/filenames/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
all: hello
|
||||
|
||||
hello: main.o factorial.o hello.o
|
||||
g++ main.o factorial.o hello.o -o hello
|
||||
|
||||
main.o: main.cpp
|
||||
g++ -c main.cpp
|
||||
|
||||
factorial.o: factorial.cpp
|
||||
g++ -c factorial.cpp
|
||||
|
||||
hello.o: hello.cpp
|
||||
g++ -c hello.cpp
|
||||
|
||||
clean:
|
||||
rm -rf *o hello
|
||||
3
samples/Makefile/makefile.script!
Normal file
3
samples/Makefile/makefile.script!
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/make -f
|
||||
%:
|
||||
ls -l
|
||||
90
samples/MediaWiki/mediawiki.mediawiki
Normal file
90
samples/MediaWiki/mediawiki.mediawiki
Normal file
@@ -0,0 +1,90 @@
|
||||
|
||||
= Overview =
|
||||
|
||||
The GDB Tracepoint Analysis feature is an extension to the Tracing and Monitoring Framework that allows the visualization and analysis of C/C++ tracepoint data collected by GDB and stored to a log file.
|
||||
|
||||
= Getting Started =
|
||||
|
||||
The feature can be installed from the Eclipse update site by selecting '''Linux Tools''' > '''GDB Tracepoint Analysis'''.
|
||||
|
||||
The feature requires GDB version 7.2 or later to be installed on the local host. The executable program 'gdb' must be found in the path.
|
||||
|
||||
= GDB Trace Perspective =
|
||||
|
||||
To open the perspective, select '''Window''' > '''Open Perspective''' > '''Other...''' > '''GDB Trace'''.
|
||||
|
||||
The perspective includes the following views by default:
|
||||
|
||||
* '''Project Explorer''': This view shows the projects in the workspace and is used to create and manage Tracing projects.
|
||||
* '''Debug''': This view shows the running C/C++ Postmortem Debugger instances and displays the thread and stack trace associated with a tracepoint.
|
||||
* '''Trace Control''': This view shows the status of the debugger and allows navigation of trace records.
|
||||
* '''Console''': This view displays console output of the C/C++ Postmortem Debugger.
|
||||
|
||||
The editor area contains the '''Events''' and '''C/C++''' editors when a GDB Trace is opened.
|
||||
|
||||
[[Image:images/GDBTracePerspective.png]]
|
||||
|
||||
= Collecting Tracepoint Data =
|
||||
|
||||
Collecting the C/C++ tracepoint data is outside the scope of this feature. It can be done from the GDB command line or by using the CDT debug component within Eclipse. See the CDT FAQ entry in the [[#References | References]] section.
|
||||
|
||||
= Importing Tracepoint Data =
|
||||
|
||||
Some information in this section is redundant with the LTTng User Guide. For further details, see the LTTng User Guide entry in the [[#References | References]] section.
|
||||
|
||||
== Creating a Tracing Project ==
|
||||
|
||||
In the '''Project Explorer''' view, right-click and select '''New''' > '''Project...''' from the context menu. In the '''New Project''' dialog, select '''Tracing''' > '''Tracing Project''', click '''Next''', name your project and click '''Finish'''.
|
||||
|
||||
== Importing a GDB Trace ==
|
||||
|
||||
In your tracing project, right-click on the '''Traces''' folder and select '''Import...'''. Browse to, or enter, a source directory. Select the trace file in the tree. Optionally set the trace type to '''GDB : GDB Trace'''. Click '''Finish'''.
|
||||
|
||||
Alternatively, the trace can be drag & dropped to the '''Traces''' folder from any external file manager.
|
||||
|
||||
== Selecting the GDB Trace Type ==
|
||||
|
||||
Right-click the imported trace in the '''Traces''' folder and choose '''Select Trace Type...''' > '''GDB''' > '''GDB Trace''' from the context menu. This step can be omitted if the trace type was selected at import.
|
||||
|
||||
The trace will be updated with the GDB icon [[Image:images/gdb_icon16.png]].
|
||||
|
||||
== Selecting the Trace Executable ==
|
||||
|
||||
The executable file that created the tracepoint data must be identified so that the C/C++ Postmortem Debugger can be launched properly.
|
||||
|
||||
Right-click the GDB trace in the '''Traces''' folder and choose '''Select Trace Executable...''' from the context menu. Browse to, or enter, the path of the executable file and press '''OK'''.
|
||||
|
||||
The selected file must be recognized by GDB as an executable.
|
||||
|
||||
= Visualizing Tracepoint Data =
|
||||
|
||||
== Opening a GDB Trace ==
|
||||
|
||||
In the '''Traces''' folder, double-click the GDB trace or right-click it and select '''Open''' from the context menu.
|
||||
|
||||
The tracepoint data will be opened in an Events editor, and a C/C++ Postmortem Debugger instance will be launched.
|
||||
|
||||
If available in the workspace, the source code corresponding to the first trace record will also be opened in a C/C++ editor.
|
||||
|
||||
At this point it is recommended to relocate the Events editor outside of the default editor area, so that it is not hidden by the C/C++ editor.
|
||||
|
||||
== Viewing Trace Data ==
|
||||
|
||||
In the Events editor, a table is shown with one row for each trace record. The '''Trace Frame''' column shows the sequential trace record number. The '''Tracepoint''' column shows the number assigned by GDB at collection time for this tracepoint. The '''File''' column shows the file name, line number and method where the tracepoint was set. The '''Content''' column shows the data collected at run-time by the tracepoint.
|
||||
|
||||
Searching and filtering can be done on any column by entering a regular expression in the column header.
|
||||
|
||||
== Navigating the GDB Trace ==
|
||||
|
||||
Trace records can be selected in the Events editor using the keyboard or mouse. The C/C++ Postmortem Debugger in the '''Debug''' view will be updated to show the stack trace of the current trace record.
|
||||
|
||||
The trace can also be navigated from the '''Trace Control''' view by clicking the '''Next Trace Record''' or '''Previous Trace Record''' buttons. The Events editor and '''Debug''' views will be updated.
|
||||
|
||||
= References =
|
||||
|
||||
* [http://wiki.eclipse.org/index.php/Linux_Tools_Project/LTTng2/User_Guide LTTng User Guide]
|
||||
* [http://wiki.eclipse.org/CDT/User/FAQ#How_can_I_trace_my_application_using_C.2FC.2B.2B_Tracepoints.3F CDT FAQ - How can I trace my application using C/C++ Tracepoints?]
|
||||
|
||||
= Updating This Document =
|
||||
|
||||
This document is maintained in a collaborative wiki. If you wish to update or modify this document please visit [http://wiki.eclipse.org/index.php/Linux_Tools_Project/GDB_Tracepoint_Analysis/User_Guide http://wiki.eclipse.org/Linux_Tools_Project/GDB_Tracepoint_Analysis/User_Guide]
|
||||
164
samples/Org/org.org
Normal file
164
samples/Org/org.org
Normal file
@@ -0,0 +1,164 @@
|
||||
#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t TeX:t LaTeX:t skip:nil d:(HIDE) tags:not-in-toc
|
||||
#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate
|
||||
#+SEQ_TODO: TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
|
||||
#+TAGS: Write(w) Update(u) Fix(f) Check(c)
|
||||
#+TITLE: org-ruby
|
||||
#+AUTHOR: Brian Dewey
|
||||
#+EMAIL: bdewey@gmail.com
|
||||
#+LANGUAGE: en
|
||||
#+PRIORITIES: A C B
|
||||
#+CATEGORY: worg
|
||||
|
||||
{Back to Worg's index}
|
||||
|
||||
* Motivation
|
||||
|
||||
The dominant simple plain-text markup languages for the web are
|
||||
Textile and Markdown. A factor for the popularity of those markup
|
||||
formats is the widespread availability of simple, free packages for
|
||||
converting the formats to HTML. For example, the world of
|
||||
Ruby-powered websites has settled on RedCloth for converting Textile
|
||||
to HTML.
|
||||
|
||||
The default way to convert org-mode files to HTML is the powerful
|
||||
publishing functionality provided by =emacs=. However, =emacs= does
|
||||
not easiliy integrate into many existing website frameworks.
|
||||
|
||||
=Org-ruby= tries to make it easier to use org-mode files in both
|
||||
dyanmic and static website generation tools written in
|
||||
Ruby. =Org-ruby= is a simple Ruby gem to convert org-mode files to
|
||||
HTML.
|
||||
|
||||
* Using Org-ruby
|
||||
|
||||
=Org-ruby= follows the same model as other Ruby markup
|
||||
libraries. You install the gem:
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
sudo gem install org-ruby
|
||||
#+END_EXAMPLE
|
||||
|
||||
Then, to convert an org-file to HTML in your Ruby code:
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
require 'rubygems'
|
||||
require 'org-ruby'
|
||||
|
||||
data = IO.read(filename)
|
||||
puts Orgmode::Parser.new(data).to_html
|
||||
#+END_EXAMPLE
|
||||
|
||||
* Walkthrough: Using org-ruby with Webby
|
||||
|
||||
Here is an example of how to integrate =org-ruby= into Webby, a
|
||||
static website generation tool written in Ruby.
|
||||
|
||||
Webby follows a similar pattern to other static site generation
|
||||
tools (like nanoc, Jekyll, and webgen):
|
||||
|
||||
- You author website content in text with simple markup
|
||||
- Each page is fed through one or more /filters/ to produce HTML
|
||||
- The HTML is mixed in with layouts to produce the final pages
|
||||
|
||||
For a Webby site, a the source for a page may look like this:
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
---
|
||||
title: Special Directories
|
||||
created_at: 2009-12-17
|
||||
status: Complete
|
||||
filter:
|
||||
- erb
|
||||
- maruku
|
||||
tags:
|
||||
- powershell
|
||||
---
|
||||
<%= @page.title %>
|
||||
==================
|
||||
|
||||
Special Directories are a set of directories, each of which has a
|
||||
function that will navigate you to the appropriate directory using
|
||||
the push-location cmdlet. For example, the function `home` might
|
||||
navigate to `c:\users\bdewey.`
|
||||
|
||||
Install
|
||||
-------
|
||||
|
||||
Copy the module to somewhere in `ENV:PSModulePath`. Then,
|
||||
|
||||
InstallModule SpecialDirectories
|
||||
#+END_EXAMPLE
|
||||
|
||||
In the above example, the text is written in Markdown. At the top of
|
||||
the file, metadata informs Webby to pass the text through two
|
||||
/filters/ to produce HTML. The first filter, =erb=, handles embedded
|
||||
Ruby. In this case, it will replace ~<%= @page.title %>~ with the
|
||||
page title (=Special Directories=). The second filter uses Maruku to
|
||||
translate Markdown into HTML.
|
||||
|
||||
You can use the exact same pattern to include org-mode files in a
|
||||
Webby site. For this walkthrough, I assume you already have Webby
|
||||
installed, and that you've already created a site.
|
||||
|
||||
1. Make sure you have =org-ruby= installed: =sudo gem install
|
||||
org-ruby=.
|
||||
2. You need to register a new Webby filter to handle org-mode
|
||||
content. Webby makes this easy. In the =lib/= folder of your
|
||||
site, create a file =orgmode.rb=:
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
require 'org-ruby'
|
||||
|
||||
Webby::Filters.register :org do |input|
|
||||
Orgmode::Parser.new(input).to_html
|
||||
end
|
||||
#+END_EXAMPLE
|
||||
|
||||
This code creates a new filter, =org=, that will use the
|
||||
=org-ruby= parser to translate org-mode input into HTML.
|
||||
3. Create your content. For example:
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
---
|
||||
title: Orgmode Parser
|
||||
created_at: 2009-12-21
|
||||
status: Under development
|
||||
filter:
|
||||
- erb
|
||||
- org
|
||||
tags:
|
||||
- orgmode
|
||||
- ruby
|
||||
---
|
||||
<%= @page.title %>
|
||||
|
||||
Status: <%= @page.status %>
|
||||
|
||||
* Description
|
||||
|
||||
Helpful Ruby routines for parsing orgmode files. The most
|
||||
significant thing this library does today is convert orgmode files
|
||||
to textile. Currently, you cannot do much to customize the
|
||||
conversion. The supplied textile conversion is optimized for
|
||||
extracting "content" from the orgfile as opposed to "metadata."
|
||||
|
||||
|
||||
* History
|
||||
|
||||
** 2009-12-29: Version 0.4
|
||||
|
||||
- The first thing output in HTML gets the class "title"
|
||||
- HTML output is now indented
|
||||
- Proper support for multi-paragraph list items.
|
||||
|
||||
See? This paragraph is part of the last bullet.
|
||||
|
||||
- Fixed bugs:
|
||||
- "rake spec" wouldn't work on Linux. Needed "require 'rubygems'".
|
||||
#+END_EXAMPLE
|
||||
|
||||
This file will go through the =erb= and =org= filters; as defined
|
||||
in the previous step, the =org= filter will use =org-ruby= to
|
||||
generate HTML.
|
||||
|
||||
That's all there is to it!
|
||||
22
samples/PHP/php2.script!
Normal file
22
samples/PHP/php2.script!
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Yii console bootstrap file.
|
||||
*
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
||||
|
||||
// fcgi doesn't have STDIN defined by default
|
||||
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
|
||||
|
||||
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
|
||||
require(__DIR__ . '/vendor/autoload.php');
|
||||
|
||||
$config = require(__DIR__ . '/config/console.php');
|
||||
|
||||
$application = new yii\console\Application($config);
|
||||
$application->run();
|
||||
102
samples/Perl/index.fcgi
Executable file
102
samples/Perl/index.fcgi
Executable file
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use CGI::Fast;
|
||||
use XML::Hash::XS;
|
||||
use File::Spec;
|
||||
use FindBin qw($Bin);
|
||||
|
||||
#use lib File::Spec->catdir($Bin, qw(.. lib));
|
||||
|
||||
my $_stop = 0;
|
||||
my $request;
|
||||
$SIG{'PIPE'} = 'IGNORE';
|
||||
|
||||
$SIG{'INT'} = $SIG{'TERM'} = sub {
|
||||
$_stop = 1;
|
||||
|
||||
exit(0) unless defined($request);
|
||||
};
|
||||
|
||||
unless ($ENV{'SERVER_SOFTWARE'}) { # for nginx external fcgi
|
||||
$CGI::Fast::Ext_Request = FCGI::Request(
|
||||
\*STDIN, \*STDOUT, \*STDERR,
|
||||
\%ENV, int($ARGV[0] || 0), 1
|
||||
);
|
||||
}
|
||||
|
||||
my $conv = XML::Hash::XS->new(
|
||||
use_attr => 1,
|
||||
indent => 2,
|
||||
output => \*STDOUT,
|
||||
xml_decl => 1
|
||||
);
|
||||
|
||||
my $tmpl_path = File::Spec->catdir($Bin, qw|.. tmpl|);
|
||||
|
||||
|
||||
my $data = {
|
||||
name => {
|
||||
nick => 'cono'
|
||||
},
|
||||
tree => {
|
||||
example => [
|
||||
{ name => 'Encyclopaedia', parent => 0, id => 1 },
|
||||
{ name => 'Science', parent => 1, id => 2 },
|
||||
{ name => 'Culture', parent => 1, id => 3 },
|
||||
{ name => 'Art', parent => 3, id => 4 },
|
||||
{ name => 'Craft', parent => 3, id => 5 }
|
||||
],
|
||||
},
|
||||
third_party => {
|
||||
results => [
|
||||
{ artist_name => 'Madonna', venue => 'Kitchen', event => 'cooking', date => '2013-04-21' },
|
||||
{ artist_name => 'cono', venue => 'Provectus-IT', event => 'presentation', date => '2013-04-20' },
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
while (1) {
|
||||
eval {
|
||||
$request = CGI::Fast->new();
|
||||
unless ($request) {
|
||||
$_stop = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
my ($tmpl, $output) = ('nick');
|
||||
if ($ENV{'REQUEST_URI'} =~ m|/([a-zA-Z0-9_]+)|) {
|
||||
$tmpl = $1;
|
||||
$output = $data->{$tmpl} if exists $data->{$tmpl};
|
||||
}
|
||||
|
||||
die "Bad request" unless $output;
|
||||
|
||||
if (-e File::Spec->catfile($tmpl_path, "$tmpl.xslt")) {
|
||||
print "X-Xslt-Stylesheet: /$tmpl.xslt\r\n";
|
||||
}
|
||||
|
||||
print qq(Content-type:application/xml;charset=utf-8\r\n\r\n);
|
||||
$conv->hash2xml($output);
|
||||
|
||||
};
|
||||
|
||||
if ($@) {
|
||||
print qq(Content-type:text/html;charset=utf-8\r\n\r\nError: $@);
|
||||
}
|
||||
|
||||
$request = undef;
|
||||
last if $_stop;
|
||||
|
||||
if (-M $0 < 0) {
|
||||
unless ($ENV{'SERVER_SOFTWARE'}) { # for nginx external fcgi
|
||||
system("$0 ". int($ARGV[0] || 0).' &');
|
||||
}
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
47
samples/Python/python2.script!
Normal file
47
samples/Python/python2.script!
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
def main():
|
||||
|
||||
# usage string
|
||||
usage = 'usage: gitall command'
|
||||
|
||||
# command check
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit(usage)
|
||||
|
||||
command = 'git ' + ' '.join(sys.argv[1:])
|
||||
printDelimiter()
|
||||
print 'Running command:', command
|
||||
|
||||
# get a list of git directories in the specified parent
|
||||
gitDirectories = getSubdirectories('.', isGitDirectory)
|
||||
|
||||
for gitDirectory in gitDirectories:
|
||||
os.chdir(gitDirectory)
|
||||
printDelimiter()
|
||||
print 'Current respository location:', os.getcwd()
|
||||
os.system(command)
|
||||
|
||||
printDelimiter()
|
||||
|
||||
def getSubdirectories(directory, filter = None):
|
||||
directory = os.path.abspath(directory)
|
||||
subdirectories = os.walk(directory).next()[1]
|
||||
if filter is None:
|
||||
return [directory + '/' + i for i in subdirectories]
|
||||
else:
|
||||
return [directory + '/' + i for i in subdirectories if filter(directory + '/' + i)]
|
||||
|
||||
def isGitDirectory(directory):
|
||||
return os.path.isdir(directory + '/.git/')
|
||||
|
||||
def printDelimiter():
|
||||
print '\033[91m'
|
||||
print ('#' * 80)
|
||||
print '\033[0m'
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
324
samples/Python/python3.script!
Normal file
324
samples/Python/python3.script!
Normal file
@@ -0,0 +1,324 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright © 2013 Martin Ueding <dev@martin-ueding.de>
|
||||
|
||||
import argparse
|
||||
import matplotlib.pyplot as pl
|
||||
import numpy as np
|
||||
import scipy.optimize as op
|
||||
from prettytable import PrettyTable
|
||||
|
||||
__docformat__ = "restructuredtext en"
|
||||
|
||||
# Sensitivität der Thermosäule
|
||||
S = 30e-6
|
||||
|
||||
def phif(U):
|
||||
return U / S
|
||||
|
||||
def main():
|
||||
options = _parse_args()
|
||||
|
||||
V = 1000
|
||||
|
||||
data = np.genfromtxt("a-leer.csv", delimiter="\t")
|
||||
t = data[:,0]
|
||||
U = data[:,1] / V / 1000
|
||||
U_err = 0.7e-3 / V
|
||||
|
||||
offset = np.mean(U[-3:])
|
||||
|
||||
x = np.linspace(min(t), max(t))
|
||||
y = np.ones(x.size) * offset
|
||||
pl.plot(x, y * 10**6, label="Offset")
|
||||
|
||||
print "Offset: {:.3g} V".format(offset)
|
||||
|
||||
pl.errorbar(t, U * 10**6, yerr=U_err * 10**6, linestyle="none", marker="+",
|
||||
label="Messdaten")
|
||||
pl.grid(True)
|
||||
pl.legend(loc="best")
|
||||
pl.title(u"Bestimmung des Offsets")
|
||||
pl.xlabel(ur"Zeit $t / \mathrm{s}$")
|
||||
pl.ylabel(ur"Thermospannung $U / \mathrm{\mu V}$")
|
||||
pl.savefig("Plot_a-leer.pdf")
|
||||
pl.clf()
|
||||
|
||||
V = 100
|
||||
|
||||
data = np.genfromtxt("a-Lampe.csv", delimiter="\t")
|
||||
t = data[:,0]
|
||||
U = data[:,1] / V / 1000 - offset
|
||||
U_err = 0.7e-3 / V
|
||||
|
||||
x = np.linspace(min(t), max(t))
|
||||
y = np.ones(x.size) * max(U) * 0.9
|
||||
pl.plot(x, y * 10**6, label=ur"$90\%$")
|
||||
|
||||
pl.errorbar(t, U * 10**6, yerr=U_err * 10**6, linestyle="none", marker="+",
|
||||
label="Messdaten")
|
||||
pl.grid(True)
|
||||
pl.legend(loc="best")
|
||||
pl.title(u"Bestimmung der Ansprechzeit")
|
||||
pl.xlabel(ur"Zeit $t / \mathrm{s}$")
|
||||
pl.ylabel(ur"Thermospannung $U / \mathrm{\mu V}$")
|
||||
pl.savefig("Plot_a-Lampe.pdf")
|
||||
pl.clf()
|
||||
|
||||
# Lesliewürfel
|
||||
print """
|
||||
Lesliewürfel
|
||||
============
|
||||
"""
|
||||
|
||||
glanz = np.genfromtxt("b-glanz.csv", delimiter="\t")
|
||||
matt = np.genfromtxt("b-matt.csv", delimiter="\t")
|
||||
schwarz = np.genfromtxt("b-schwarz.csv", delimiter="\t")
|
||||
weiss = np.genfromtxt("b-weiss.csv", delimiter="\t")
|
||||
|
||||
T0 = 19.0 + 273.15
|
||||
T0_err = 1.0
|
||||
|
||||
glanz[:,0] += 273.15
|
||||
matt[:,0] += 273.15
|
||||
schwarz[:,0] += 273.15
|
||||
weiss[:,0] += 273.15
|
||||
|
||||
glanz[:,1] /= 1000 * V
|
||||
matt[:,1] /= 1000 * V
|
||||
schwarz[:,1] /= 1000 * V
|
||||
weiss[:,1] /= 1000 * V
|
||||
|
||||
glanz[:,1] -= offset
|
||||
matt[:,1] -= offset
|
||||
schwarz[:,1] -= offset
|
||||
weiss[:,1] -= offset
|
||||
|
||||
glanz_phi = phif(glanz[:,1])
|
||||
matt_phi = phif(matt[:,1])
|
||||
schwarz_phi = phif(schwarz[:,1])
|
||||
weiss_phi = phif(weiss[:,1])
|
||||
|
||||
T_err = 0.3
|
||||
|
||||
sigma = 5.670373e-8
|
||||
|
||||
def boltzmann(T, epsilon, offset):
|
||||
return epsilon * sigma * T**4 + offset
|
||||
|
||||
glanz_popt, glanz_pconv = op.curve_fit(boltzmann, glanz[:,0], glanz_phi)
|
||||
matt_popt, matt_pconv = op.curve_fit(boltzmann, matt[:,0], matt_phi)
|
||||
schwarz_popt, schwarz_pconv = op.curve_fit(boltzmann, schwarz[:,0], schwarz_phi)
|
||||
weiss_popt, weiss_pconv = op.curve_fit(boltzmann, weiss[:,0], weiss_phi)
|
||||
|
||||
glanz_x = np.linspace(min(glanz[:,0]), max(glanz[:,0]))
|
||||
glanz_y = boltzmann(glanz_x, *glanz_popt)
|
||||
pl.plot(glanz_x, glanz_y, label="Fit glanz", color="gold")
|
||||
|
||||
matt_x = np.linspace(min(matt[:,0]), max(matt[:,0]))
|
||||
matt_y = boltzmann(matt_x, *matt_popt)
|
||||
pl.plot(matt_x, matt_y, label="Fit matt", color="yellow")
|
||||
|
||||
schwarz_x = np.linspace(min(schwarz[:,0]), max(schwarz[:,0]))
|
||||
schwarz_y = boltzmann(schwarz_x, *schwarz_popt)
|
||||
pl.plot(schwarz_x, schwarz_y, label="Fit schwarz", color="black")
|
||||
|
||||
weiss_x = np.linspace(min(weiss[:,0]), max(weiss[:,0]))
|
||||
weiss_y = boltzmann(weiss_x, *weiss_popt)
|
||||
pl.plot(weiss_x, weiss_y, label="Fit weiss", color="gray")
|
||||
|
||||
print "glanz ε = {:.3g} ± {:.3g}".format(glanz_popt[0], np.sqrt(glanz_pconv.diagonal()[0]))
|
||||
print "glanz offset = {:.3g} ± {:.3g}".format(glanz_popt[1], np.sqrt(glanz_pconv.diagonal()[1]))
|
||||
print "matt ε = {:.3g} ± {:.3g}".format(matt_popt[0], np.sqrt(matt_pconv.diagonal()[0]))
|
||||
print "matt offset = {:.3g} ± {:.3g}".format(matt_popt[1], np.sqrt(matt_pconv.diagonal()[1]))
|
||||
print "schwarz ε = {:.3g} ± {:.3g}".format(schwarz_popt[0], np.sqrt(schwarz_pconv.diagonal()[0]))
|
||||
print "schwarz offset = {:.3g} ± {:.3g}".format(schwarz_popt[1], np.sqrt(schwarz_pconv.diagonal()[1]))
|
||||
print "weiss ε = {:.3g} ± {:.3g}".format(weiss_popt[0], np.sqrt(weiss_pconv.diagonal()[0]))
|
||||
print "weiss offset = {:.3g} ± {:.3g}".format(weiss_popt[1], np.sqrt(weiss_pconv.diagonal()[1]))
|
||||
|
||||
pl.errorbar(glanz[:,0], glanz_phi, xerr=T_err, yerr=U_err/S,
|
||||
label="glanz", color="gold", linestyle="none")
|
||||
pl.errorbar(matt[:,0], matt_phi, xerr=T_err, yerr=U_err/S,
|
||||
label="matt", color="yellow", linestyle="none")
|
||||
pl.errorbar(schwarz[:,0], schwarz_phi, xerr=T_err, yerr=U_err/S,
|
||||
label="schwarz", color="black", linestyle="none")
|
||||
pl.errorbar(weiss[:,0], weiss_phi, xerr=T_err, yerr=U_err/S,
|
||||
label="weiss", color="gray", linestyle="none")
|
||||
|
||||
header = ["T / K", "Phi/F in W/m^2", "Fehler T", "Fehler Phi/F"]
|
||||
|
||||
print """
|
||||
Tabellen für den Lesliewürfel-Plot
|
||||
----------------------------------
|
||||
"""
|
||||
|
||||
print "Glanz"
|
||||
glanz_table = PrettyTable(header)
|
||||
for row in zip(glanz[:,0], glanz_phi, np.ones(glanz[:,0].size)*T_err, np.ones(glanz_phi.size)*U_err/S):
|
||||
glanz_table.add_row(row)
|
||||
print glanz_table
|
||||
print
|
||||
|
||||
print "Matt"
|
||||
matt_table = PrettyTable(header)
|
||||
for row in zip(matt[:,0], matt_phi, np.ones(matt[:,0].size)*T_err, np.ones(matt_phi.size)*U_err/S):
|
||||
matt_table.add_row(row)
|
||||
print matt_table
|
||||
print
|
||||
|
||||
print "Schwarz"
|
||||
schwarz_table = PrettyTable(header)
|
||||
for row in zip(schwarz[:,0], schwarz_phi, np.ones(schwarz[:,0].size)*T_err, np.ones(schwarz_phi.size)*U_err/S):
|
||||
schwarz_table.add_row(row)
|
||||
print schwarz_table
|
||||
print
|
||||
|
||||
print "Weiß"
|
||||
weiss_table = PrettyTable(header)
|
||||
for row in zip(weiss[:,0], weiss_phi, np.ones(weiss[:,0].size)*T_err, np.ones(weiss_phi.size)*U_err/S):
|
||||
weiss_table.add_row(row)
|
||||
print weiss_table
|
||||
print
|
||||
|
||||
epsilon = 0.1
|
||||
|
||||
x = np.linspace(min([min(x) for x in [glanz[:,0], matt[:,0], schwarz[:,0],
|
||||
weiss[:,0]]]),
|
||||
max([max(x) for x in [glanz[:,0], matt[:,0], schwarz[:,0],
|
||||
weiss[:,0]]]),
|
||||
100)
|
||||
offset = - epsilon * sigma * T0**4
|
||||
print "ideal offset = {:.3g}".format(offset)
|
||||
y = boltzmann(x, epsilon, offset)
|
||||
pl.plot(x, y, label=ur"$\epsilon = 0.1$")
|
||||
|
||||
|
||||
pl.grid(True)
|
||||
pl.title(u"Lesliewürfel")
|
||||
pl.xlabel(ur"Temperatur $T / \mathrm{K}$")
|
||||
pl.ylabel(ur"Strahlungsfluss $\frac{\Phi}{F} / \mathrm{\frac{W}{m^2}}$")
|
||||
pl.legend(loc="best", prop={"size": 12})
|
||||
pl.savefig("Plot_b.pdf")
|
||||
pl.clf()
|
||||
|
||||
# Aufgabe c
|
||||
print """
|
||||
Aufgabe c
|
||||
=========
|
||||
"""
|
||||
|
||||
data = np.genfromtxt("c-erste.csv", delimiter="\t")
|
||||
d = data[:,0] / 100
|
||||
U = data[:,1] / V
|
||||
phi = phif(U)
|
||||
|
||||
def c(x, a, b):
|
||||
return a*x + b
|
||||
|
||||
|
||||
dx = d**(-2)
|
||||
dy = phi
|
||||
|
||||
dx_err = np.abs(-2 * d**(-3)) * 0.001
|
||||
dy_err = 0.001 / S
|
||||
|
||||
popt, pconv = op.curve_fit(c, dx, dy)
|
||||
x = np.linspace(min(dx), max(dx))
|
||||
y = c(x, *popt)
|
||||
pl.plot(x, y, label="Fit")
|
||||
|
||||
print "Fitparameter"
|
||||
print "a", popt[0], "±", np.sqrt(pconv.diagonal()[0])
|
||||
print "b", popt[1], "±", np.sqrt(pconv.diagonal()[1])
|
||||
|
||||
pl.errorbar(dx, dy, xerr=dx_err, yerr=dy_err, linestyle="none",
|
||||
marker="+", label="Messdaten")
|
||||
pl.grid(True)
|
||||
pl.title(u"Halogenlampe bei verschiedenen Abständen")
|
||||
pl.xlabel(ur"Abstand $d^{-2} / \mathrm{m^{-2}}$")
|
||||
pl.ylabel(ur"Strahlungsfluss $\frac{\Phi}{F} / \mathrm{\frac{W}{m^2}}$")
|
||||
pl.legend(loc="best")
|
||||
pl.savefig("Plot_c-erste.pdf")
|
||||
pl.clf()
|
||||
|
||||
print
|
||||
print "Tabelle für Aufgabe c"
|
||||
fields = ["d^-2 in m^-2", "Phi/F in W/m^2", "Fehler d^-2", "Fehler Phi/F"]
|
||||
table = PrettyTable(fields)
|
||||
table.align = "l"
|
||||
for row in zip(dx, dy, dx_err, np.ones(dy.size)*dy_err):
|
||||
table.add_row(row)
|
||||
print table
|
||||
print
|
||||
|
||||
data = np.genfromtxt("c-zweite.csv", delimiter="\t")
|
||||
U1 = data[:,0]
|
||||
I1 = data[:,1]
|
||||
U2 = data[:,2] / V
|
||||
|
||||
U_err = 0.001
|
||||
I_err = 0.01
|
||||
|
||||
p = U1 * I1
|
||||
R = U1 / I1
|
||||
R_err = np.sqrt(
|
||||
(1/I1 * U_err)**2
|
||||
+ (U1/I1**2 * I_err)**2
|
||||
)
|
||||
|
||||
phi = phif(U2)
|
||||
phi_err = U_err / S
|
||||
|
||||
alpha = 4.82e-3
|
||||
beta = 6.76e-7
|
||||
|
||||
R0 = 0.35
|
||||
R0_err = 0.05
|
||||
|
||||
T = (-alpha*R0 + np.sqrt(R0)*np.sqrt(4*beta*R + alpha**2*R0 - 4*beta*R0) +
|
||||
2*beta*R0*T0)/(2*beta*R0)
|
||||
|
||||
popt, pconv = op.curve_fit(boltzmann, T, phi, sigma=phi_err)
|
||||
x = np.linspace(min(T), max(T))
|
||||
y = boltzmann(x, *popt)
|
||||
pl.plot(x, y, label="Fit")
|
||||
|
||||
epsilon = popt[0]
|
||||
epsilon_err = np.sqrt(pconv.diagonal()[0])
|
||||
|
||||
print "ε = {:.3g} ± {:.3g}".format(epsilon, epsilon_err)
|
||||
|
||||
f1 = (1/(np.sqrt(R0)*np.sqrt(4*beta*R + alpha**2*R0 - 4*beta*R0))) * R_err
|
||||
f2 = T0_err
|
||||
f3 = ((-alpha + ((alpha**2 - 4*beta)*np.sqrt(R0))/( 2*np.sqrt(4*beta*R + alpha**2*R0 - 4*beta*R0)) + np.sqrt( 4*beta*R + alpha**2*R0 - 4*beta*R0)/(2*np.sqrt(R0)) + 2*beta*T0)/( 2*beta*R0) - (-alpha*R0 + np.sqrt(R0)*np.sqrt(4*beta*R + alpha**2*R0 - 4*beta*R0) + 2*beta*R0*T0)/( 2*beta*R0**2)) * R0_err
|
||||
|
||||
T_err = np.sqrt(f1**2 + f2**2 + f3**2)
|
||||
|
||||
pl.errorbar(T, phi, xerr=T_err, yerr=phi_err, label="Messdaten",
|
||||
linestyle="none", marker="+")
|
||||
pl.grid(True)
|
||||
pl.legend(loc="best")
|
||||
pl.title(u"Halogenlampe bei verschiedenen Leistungen")
|
||||
pl.xlabel(u"Temperatur $T / \mathrm{K}$")
|
||||
pl.ylabel(ur"Strahlungsfluss $\frac{\Phi}{F} / \mathrm{\frac{W}{m^2}}$")
|
||||
pl.savefig("Plot_c-zweite.pdf")
|
||||
pl.clf()
|
||||
|
||||
def _parse_args():
|
||||
"""
|
||||
Parses the command line arguments.
|
||||
|
||||
:return: Namespace with arguments.
|
||||
:rtype: Namespace
|
||||
"""
|
||||
parser = argparse.ArgumentParser(description="")
|
||||
#parser.add_argument("args", metavar="N", type=str, nargs="*", help="Positional arguments.")
|
||||
#parser.add_argument("", dest="", type="", default=, help=)
|
||||
#parser.add_argument("--version", action="version", version="<the version>")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
31
samples/R/git-punchcard.script!
Executable file
31
samples/R/git-punchcard.script!
Executable file
@@ -0,0 +1,31 @@
|
||||
#! /usr/bin/env Rscript
|
||||
# vim: filetype=r:
|
||||
|
||||
ParseDates <- function(lines) {
|
||||
dates <- matrix(unlist(strsplit(lines, " +")), ncol=6, byrow=TRUE)
|
||||
days <- dates[,1]
|
||||
times <- dates[,4]
|
||||
hours <- matrix(unlist(strsplit(times, ":")), ncol=3, byrow=TRUE)[,1]
|
||||
all.days <- c("Sun", "Sat", "Fri", "Thu", "Wed", "Tue", "Mon")
|
||||
all.hours <- 0:23
|
||||
data.frame( Day = factor(days , levels=all.days)
|
||||
, Hour = factor(hours, levels=all.hours)
|
||||
)
|
||||
}
|
||||
|
||||
Main <- function() {
|
||||
lines <- system("git log --format=%ad", intern=TRUE)
|
||||
punchcard <- as.data.frame(table(ParseDates(lines)))
|
||||
punchcard <-
|
||||
( ggplot2::ggplot(punchcard, ggplot2::aes(y=Day, x=Hour))
|
||||
+ ggplot2::geom_point(ggplot2::aes(size=Freq))
|
||||
+ ggplot2::scale_size(range=c(0, 15))
|
||||
)
|
||||
ggplot2::ggsave( filename = "punchcard.png"
|
||||
, plot = punchcard
|
||||
, width = 10
|
||||
, height = 5
|
||||
)
|
||||
}
|
||||
|
||||
Main()
|
||||
129
samples/RDoc/rdoc.rdoc
Normal file
129
samples/RDoc/rdoc.rdoc
Normal file
@@ -0,0 +1,129 @@
|
||||
= \RDoc - Ruby Documentation System
|
||||
|
||||
home :: https://github.com/rdoc/rdoc
|
||||
rdoc :: http://docs.seattlerb.org/rdoc
|
||||
bugs :: https://github.com/rdoc/rdoc/issues
|
||||
code quality :: {<img src="https://codeclimate.com/badge.png" alt="code climate">}[https://codeclimate.com/github/rdoc/rdoc]
|
||||
|
||||
== Description
|
||||
|
||||
RDoc produces HTML and command-line documentation for Ruby projects. RDoc
|
||||
includes the +rdoc+ and +ri+ tools for generating and displaying documentation
|
||||
from the command-line.
|
||||
|
||||
== Generating Documentation
|
||||
|
||||
Once installed, you can create documentation using the +rdoc+ command
|
||||
|
||||
$ rdoc [options] [names...]
|
||||
|
||||
For an up-to-date option summary, type
|
||||
|
||||
$ rdoc --help
|
||||
|
||||
A typical use might be to generate documentation for a package of Ruby
|
||||
source (such as RDoc itself).
|
||||
|
||||
$ rdoc
|
||||
|
||||
This command generates documentation for all the Ruby and C source
|
||||
files in and below the current directory. These will be stored in a
|
||||
documentation tree starting in the subdirectory +doc+.
|
||||
|
||||
You can make this slightly more useful for your readers by having the
|
||||
index page contain the documentation for the primary file. In our
|
||||
case, we could type
|
||||
|
||||
% rdoc --main README.rdoc
|
||||
|
||||
You'll find information on the various formatting tricks you can use
|
||||
in comment blocks in the documentation this generates.
|
||||
|
||||
RDoc uses file extensions to determine how to process each file. File names
|
||||
ending +.rb+ and +.rbw+ are assumed to be Ruby source. Files
|
||||
ending +.c+ are parsed as C files. All other files are assumed to
|
||||
contain just Markup-style markup (with or without leading '#' comment
|
||||
markers). If directory names are passed to RDoc, they are scanned
|
||||
recursively for C and Ruby source files only.
|
||||
|
||||
To generate documentation using +rake+ see RDoc::Task.
|
||||
|
||||
To generate documentation programmatically:
|
||||
|
||||
gem 'rdoc'
|
||||
require 'rdoc/rdoc'
|
||||
|
||||
options = RDoc::Options.new
|
||||
# see RDoc::Options
|
||||
|
||||
rdoc = RDoc::RDoc.new
|
||||
rdoc.document options
|
||||
# see RDoc::RDoc
|
||||
|
||||
== Writing Documentation
|
||||
|
||||
To write documentation for RDoc place a comment above the class, module,
|
||||
method, constant, or attribute you want documented:
|
||||
|
||||
##
|
||||
# This class represents an arbitrary shape by a series of points.
|
||||
|
||||
class Shape
|
||||
|
||||
##
|
||||
# Creates a new shape described by a +polyline+.
|
||||
#
|
||||
# If the +polyline+ does not end at the same point it started at the
|
||||
# first pointed is copied and placed at the end of the line.
|
||||
#
|
||||
# An ArgumentError is raised if the line crosses itself, but shapes may
|
||||
# be concave.
|
||||
|
||||
def initialize polyline
|
||||
# ...
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
The default comment markup format is the RDoc::Markup format.
|
||||
TomDoc[rdoc-ref:RDoc::TomDoc], Markdown[rdoc-ref:RDoc::Markdown] and
|
||||
RD[rdoc-ref:RDoc::RD] format comments are also supported. You can set the
|
||||
default comment format for your entire project by creating a
|
||||
<tt>.rdoc_options</tt> file. See RDoc::Options@Saved+Options for instructions
|
||||
on creating one. You can also set the comment format for a single file
|
||||
through the +:markup:+ directive, but this is only recommended if you wish to
|
||||
switch markup formats. See RDoc::Markup@Other+directives.
|
||||
|
||||
Comments can contain directives that tell RDoc information that it cannot
|
||||
otherwise discover through parsing. See RDoc::Markup@Directives to control
|
||||
what is or is not documented, to define method arguments or to break up
|
||||
methods in a class by topic. See RDoc::Parser::Ruby for directives used to
|
||||
teach RDoc about metaprogrammed methods.
|
||||
|
||||
See RDoc::Parser::C for documenting C extensions with RDoc.
|
||||
|
||||
To determine how well your project is documented run <tt>rdoc -C lib</tt> to
|
||||
get a documentation coverage report. <tt>rdoc -C1 lib</tt> includes parameter
|
||||
names in the documentation coverage report.
|
||||
|
||||
== Bugs
|
||||
|
||||
See CONTRIBUTING@Bugs for information on filing a bug report. It's OK to file
|
||||
a bug report for anything you're having a problem with. If you can't figure
|
||||
out how to make RDoc produce the output you like that is probably a
|
||||
documentation bug.
|
||||
|
||||
== License
|
||||
|
||||
RDoc is Copyright (c) 2001-2003 Dave Thomas, The Pragmatic Programmers.
|
||||
Portions (c) 2007-2011 Eric Hodel. Portions copyright others, see individual
|
||||
files and LEGAL.rdoc for details.
|
||||
|
||||
RDoc is free software, and may be redistributed under the terms specified in
|
||||
LICENSE.rdoc.
|
||||
|
||||
== Warranty
|
||||
|
||||
This software is provided "as is" and without any express or implied
|
||||
warranties, including, without limitation, the implied warranties of
|
||||
merchantability and fitness for a particular purpose.
|
||||
12
samples/Sass/demo.scss
Normal file
12
samples/Sass/demo.scss
Normal file
@@ -0,0 +1,12 @@
|
||||
$blue: #3bbfce;
|
||||
$margin: 16px;
|
||||
|
||||
.content_navigation {
|
||||
color: $blue;
|
||||
}
|
||||
|
||||
.border {
|
||||
padding: $margin / 2;
|
||||
margin: $margin / 2;
|
||||
border: 2px $blue solid;
|
||||
}
|
||||
30
samples/Shell/filenames/Dockerfile
Normal file
30
samples/Shell/filenames/Dockerfile
Normal file
@@ -0,0 +1,30 @@
|
||||
# This file describes the standard way to build Docker, using docker
|
||||
docker-version 0.4.2
|
||||
from ubuntu:12.04
|
||||
maintainer Solomon Hykes <solomon@dotcloud.com>
|
||||
# Build dependencies
|
||||
run apt-get install -y -q curl
|
||||
run apt-get install -y -q git
|
||||
# Install Go
|
||||
run curl -s https://go.googlecode.com/files/go1.1.1.linux-amd64.tar.gz | tar -v -C /usr/local -xz
|
||||
env PATH /usr/local/go/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
|
||||
env GOPATH /go
|
||||
env CGO_ENABLED 0
|
||||
run cd /tmp && echo 'package main' > t.go && go test -a -i -v
|
||||
# Download dependencies
|
||||
run PKG=github.com/kr/pty REV=27435c699; git clone http://$PKG /go/src/$PKG && cd /go/src/$PKG && git checkout -f $REV
|
||||
run PKG=github.com/gorilla/context/ REV=708054d61e5; git clone http://$PKG /go/src/$PKG && cd /go/src/$PKG && git checkout -f $REV
|
||||
run PKG=github.com/gorilla/mux/ REV=9b36453141c; git clone http://$PKG /go/src/$PKG && cd /go/src/$PKG && git checkout -f $REV
|
||||
# Run dependencies
|
||||
run apt-get install -y iptables
|
||||
# lxc requires updating ubuntu sources
|
||||
run echo 'deb http://archive.ubuntu.com/ubuntu precise main universe' > /etc/apt/sources.list
|
||||
run apt-get update
|
||||
run apt-get install -y lxc
|
||||
run apt-get install -y aufs-tools
|
||||
# Upload docker source
|
||||
add . /go/src/github.com/dotcloud/docker
|
||||
# Build the binary
|
||||
run cd /go/src/github.com/dotcloud/docker/docker && go install -ldflags "-X main.GITCOMMIT '??' -d -w"
|
||||
env PATH /usr/local/go/bin:/go/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
|
||||
cmd ["docker"]
|
||||
127
samples/Slash/brainfuck.sl
Normal file
127
samples/Slash/brainfuck.sl
Normal file
@@ -0,0 +1,127 @@
|
||||
<%
|
||||
|
||||
class Env {
|
||||
def init {
|
||||
@memory = [];
|
||||
@ptr = 0;
|
||||
}
|
||||
|
||||
def ptr { @ptr }
|
||||
def ptr=(ptr) { @ptr = ptr }
|
||||
|
||||
def current_value { @memory[@ptr] || 0 }
|
||||
def current_value=(value) { @memory[@ptr] = value }
|
||||
}
|
||||
|
||||
class AST {
|
||||
class Next {
|
||||
def eval(env) {
|
||||
env.ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
class Prev {
|
||||
def eval(env) {
|
||||
env.ptr--;
|
||||
}
|
||||
}
|
||||
|
||||
class Inc {
|
||||
def eval(env) {
|
||||
env.current_value++;
|
||||
}
|
||||
}
|
||||
|
||||
class Dec {
|
||||
def eval(env) {
|
||||
env.current_value--;
|
||||
}
|
||||
}
|
||||
|
||||
class Output {
|
||||
def eval(env) {
|
||||
print(env.current_value.char);
|
||||
}
|
||||
}
|
||||
|
||||
class Input {
|
||||
def eval(env) {
|
||||
...
|
||||
}
|
||||
}
|
||||
|
||||
class Sequence {
|
||||
def init(nodes) {
|
||||
@nodes = nodes;
|
||||
}
|
||||
|
||||
def eval(env) {
|
||||
for node in @nodes {
|
||||
node.eval(env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Loop {
|
||||
def init(seq) {
|
||||
@seq = seq;
|
||||
}
|
||||
|
||||
def eval(env) {
|
||||
while env.current_value != 0 {
|
||||
@seq.eval(env);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Parser {
|
||||
def init(str) {
|
||||
@chars = str.split("");
|
||||
}
|
||||
|
||||
def parse {
|
||||
@stack = [[]];
|
||||
for char in @chars {
|
||||
_parse_char(char);
|
||||
}
|
||||
if @stack.length != 1 {
|
||||
throw SyntaxError.new("unexpected end of input");
|
||||
}
|
||||
AST::Sequence.new(@stack.last);
|
||||
}
|
||||
|
||||
def _parse_char(char) {
|
||||
switch char {
|
||||
">" { _add(AST::Next.new); }
|
||||
"<" { _add(AST::Prev.new); }
|
||||
"+" { _add(AST::Inc.new); }
|
||||
"-" { _add(AST::Dec.new); }
|
||||
"." { _add(AST::Output.new); }
|
||||
"," { _add(AST::Input.new); }
|
||||
"[" { _open_loop(); }
|
||||
"]" { _close_loop(); }
|
||||
}
|
||||
}
|
||||
|
||||
def _add(node) {
|
||||
@stack.last.push(node);
|
||||
}
|
||||
|
||||
def _open_loop {
|
||||
@stack.push([]);
|
||||
}
|
||||
|
||||
def _close_loop {
|
||||
if @stack.length == 1 {
|
||||
throw SyntaxError.new("unexpected ']'");
|
||||
}
|
||||
|
||||
nodes = @stack.pop;
|
||||
_add(AST::Loop.new(AST::Sequence.new(nodes)));
|
||||
}
|
||||
}
|
||||
|
||||
src = File.read(ARGV.first);
|
||||
ast = Parser.new(src).parse;
|
||||
ast.eval(Env.new);
|
||||
56
samples/Squirrel/Squirrel.nut
Normal file
56
samples/Squirrel/Squirrel.nut
Normal file
@@ -0,0 +1,56 @@
|
||||
//example from http://www.squirrel-lang.org/#documentation
|
||||
|
||||
local table = {
|
||||
a = "10"
|
||||
subtable = {
|
||||
array = [1,2,3]
|
||||
},
|
||||
[10 + 123] = "expression index"
|
||||
}
|
||||
|
||||
local array=[ 1, 2, 3, { a = 10, b = "string" } ];
|
||||
|
||||
foreach (i,val in array)
|
||||
{
|
||||
::print("the type of val is"+typeof val);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
|
||||
class Entity
|
||||
{
|
||||
constructor(etype,entityname)
|
||||
{
|
||||
name = entityname;
|
||||
type = etype;
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
name = null;
|
||||
type = null;
|
||||
}
|
||||
|
||||
function Entity::MoveTo(newx,newy,newz)
|
||||
{
|
||||
x = newx;
|
||||
y = newy;
|
||||
z = newz;
|
||||
}
|
||||
|
||||
class Player extends Entity {
|
||||
constructor(entityname)
|
||||
{
|
||||
base.constructor("Player",entityname)
|
||||
}
|
||||
function DoDomething()
|
||||
{
|
||||
::print("something");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
local newplayer = Player("da playar");
|
||||
|
||||
newplayer.MoveTo(100,200,300);
|
||||
93
samples/Volt/tesla.volt
Normal file
93
samples/Volt/tesla.volt
Normal file
@@ -0,0 +1,93 @@
|
||||
// Copyright © 2012-2013, Jakob Bornecrantz. All rights reserved.
|
||||
// See copyright notice in src/volt/license.d (BOOST ver. 1.0).
|
||||
module main;
|
||||
|
||||
import core.stdc.stdio;
|
||||
import core.stdc.stdlib;
|
||||
|
||||
import watt.process;
|
||||
import watt.path;
|
||||
|
||||
import results;
|
||||
import list;
|
||||
import cmd;
|
||||
|
||||
int main()
|
||||
{
|
||||
auto cmdGroup = new CmdGroup();
|
||||
bool printOk = true;
|
||||
bool printImprovments = true;
|
||||
bool printFailing = true;
|
||||
bool printRegressions = true;
|
||||
string compiler = getEnv("VOLT");
|
||||
|
||||
if (compiler is null) {
|
||||
printf("compiler envar not set\n".ptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// @todo Scan for files
|
||||
auto tests = testList;
|
||||
|
||||
int total;
|
||||
int passed;
|
||||
int failed;
|
||||
int improved;
|
||||
int regressed;
|
||||
|
||||
auto rets = new Result[] (tests.length);
|
||||
for (size_t i; i < tests.length; i++) {
|
||||
rets[i] = new Result();
|
||||
rets[i].runTest(cmdGroup, tests[i], compiler);
|
||||
}
|
||||
|
||||
cmdGroup.waitAll();
|
||||
|
||||
for (size_t i; i < tests.length; i++) {
|
||||
auto ret = rets[i];
|
||||
total++;
|
||||
if (ret.ok) {
|
||||
passed++;
|
||||
improved += cast(int)!ret.hasPassed;
|
||||
|
||||
if (!ret.hasPassed && printImprovments) {
|
||||
printf("%s: %s, improved!\n".ptr, ret.test.ptr, ret.msg.ptr);
|
||||
} else if (printOk) {
|
||||
printf("%s: %s\n".ptr, ret.test.ptr, ret.msg.ptr);
|
||||
}
|
||||
} else {
|
||||
failed++;
|
||||
regressed += cast(int)ret.hasPassed;
|
||||
|
||||
|
||||
if (ret.hasPassed && printRegressions) {
|
||||
printf("%s: %s, regressed!\n".ptr, ret.test.ptr, ret.msg.ptr);
|
||||
} else if (printFailing) {
|
||||
printf("%s: %s\n".ptr, ret.test.ptr, ret.msg.ptr);
|
||||
}
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
auto xml = fopen("results.xml".ptr, "w+".ptr);
|
||||
if (xml !is null) {
|
||||
fprintf(xml, "<testsuites errors=\"%u\" failures=\"%u\" tests=\"%u\">\n".ptr,
|
||||
regressed, failed - regressed, total);
|
||||
for (size_t i; i < rets.length; i++) {
|
||||
rets[i].xmlLog(xml);
|
||||
}
|
||||
fprintf(xml, "</testsuites>\n".ptr);
|
||||
fflush(xml);
|
||||
fclose(xml);
|
||||
xml = null;
|
||||
}
|
||||
|
||||
auto rate = cast(float)passed / cast(float)total * 100.f;
|
||||
printf("Summary: %i tests, %i pass%s, %i failure%s, %.2f%% pass rate, %i regressions, %i improvements.\n".ptr,
|
||||
total,
|
||||
passed, (passed == 1 ? "".ptr : "es".ptr),
|
||||
failed, (failed == 1 ? "".ptr : "s".ptr),
|
||||
cast(double)rate, regressed, improved);
|
||||
|
||||
return regressed ? -1 : 0;
|
||||
}
|
||||
10
samples/XC/main.xc
Normal file
10
samples/XC/main.xc
Normal file
@@ -0,0 +1,10 @@
|
||||
int main()
|
||||
{
|
||||
int x;
|
||||
chan c;
|
||||
par {
|
||||
c <: 0;
|
||||
c :> x;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
@@ -197,6 +197,10 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert blob("C++/protocol-buffer.pb.cc").generated?
|
||||
assert blob("Java/ProtocolBuffer.java").generated?
|
||||
assert blob("Python/protocol_buffer_pb2.py").generated?
|
||||
|
||||
# Minified CSS
|
||||
assert !blob("CSS/bootstrap.css").generated?
|
||||
assert blob("CSS/bootstrap.min.css").generated?
|
||||
end
|
||||
|
||||
def test_vendored
|
||||
@@ -232,8 +236,27 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert blob("public/javascripts/jquery-1.5.2.js").vendored?
|
||||
assert blob("public/javascripts/jquery-1.6.1.js").vendored?
|
||||
assert blob("public/javascripts/jquery-1.6.1.min.js").vendored?
|
||||
assert blob("public/javascripts/jquery-1.10.1.js").vendored?
|
||||
assert blob("public/javascripts/jquery-1.10.1.min.js").vendored?
|
||||
assert !blob("public/javascripts/jquery.github.menu.js").vendored?
|
||||
|
||||
# jQuery UI
|
||||
assert blob("themes/ui-lightness/jquery-ui.css").vendored?
|
||||
assert blob("themes/ui-lightness/jquery-ui-1.8.22.custom.css").vendored?
|
||||
assert blob("themes/ui-lightness/jquery.ui.accordion.css").vendored?
|
||||
assert blob("ui/i18n/jquery.ui.datepicker-ar.js").vendored?
|
||||
assert blob("ui/i18n/jquery-ui-i18n.js").vendored?
|
||||
assert blob("ui/jquery.effects.blind.js").vendored?
|
||||
assert blob("ui/jquery-ui-1.8.22.custom.js").vendored?
|
||||
assert blob("ui/jquery-ui-1.8.22.custom.min.js").vendored?
|
||||
assert blob("ui/jquery-ui-1.8.22.js").vendored?
|
||||
assert blob("ui/jquery-ui-1.8.js").vendored?
|
||||
assert blob("ui/jquery-ui.min.js").vendored?
|
||||
assert blob("ui/jquery.ui.accordion.js").vendored?
|
||||
assert blob("ui/minified/jquery.effects.blind.min.js").vendored?
|
||||
assert blob("ui/minified/jquery.ui.accordion.min.js").vendored?
|
||||
|
||||
|
||||
# MooTools
|
||||
assert blob("public/javascripts/mootools-core-1.3.2-full-compat.js").vendored?
|
||||
assert blob("public/javascripts/mootools-core-1.3.2-full-compat-yc.js").vendored?
|
||||
@@ -249,10 +272,6 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert blob("public/javascripts/yahoo-min.js").vendored?
|
||||
assert blob("public/javascripts/yuiloader-dom-event.js").vendored?
|
||||
|
||||
# LESS
|
||||
assert blob("public/javascripts/less-1.1.0.js").vendored?
|
||||
assert blob("public/javascripts/less-1.1.0.min.js").vendored?
|
||||
|
||||
# WYS editors
|
||||
assert blob("public/javascripts/ckeditor.js").vendored?
|
||||
assert blob("public/javascripts/tiny_mce.js").vendored?
|
||||
@@ -278,6 +297,11 @@ class TestBlob < Test::Unit::TestCase
|
||||
|
||||
# jQuery validation plugin (MS bundles this with asp.net mvc)
|
||||
assert blob("Scripts/jquery.validate.js").vendored?
|
||||
assert blob("Scripts/jquery.validate.min.js").vendored?
|
||||
assert blob("Scripts/jquery.validate.unobtrusive.js").vendored?
|
||||
assert blob("Scripts/jquery.validate.unobtrusive.min.js").vendored?
|
||||
assert blob("Scripts/jquery.unobtrusive-ajax.js").vendored?
|
||||
assert blob("Scripts/jquery.unobtrusive-ajax.min.js").vendored?
|
||||
|
||||
# NuGet Packages
|
||||
assert blob("packages/Modernizr.2.0.6/Content/Scripts/modernizr-2.0.6-development-only.js").vendored?
|
||||
|
||||
@@ -160,7 +160,7 @@ class TestLanguage < Test::Unit::TestCase
|
||||
assert_equal 'cpp', Language['C++'].search_term
|
||||
assert_equal 'cfm', Language['ColdFusion'].search_term
|
||||
assert_equal 'dpatch', Language['Darcs Patch'].search_term
|
||||
assert_equal 'ocaml', Language['F#'].search_term
|
||||
assert_equal 'fsharp', Language['F#'].search_term
|
||||
assert_equal 'pot', Language['Gettext Catalog'].search_term
|
||||
assert_equal 'irc', Language['IRC log'].search_term
|
||||
assert_equal 'lhs', Language['Literate Haskell'].search_term
|
||||
@@ -191,7 +191,10 @@ class TestLanguage < Test::Unit::TestCase
|
||||
|
||||
def test_markup
|
||||
assert_equal :markup, Language['HTML'].type
|
||||
assert_equal :markup, Language['YAML'].type
|
||||
end
|
||||
|
||||
def test_data
|
||||
assert_equal :data, Language['YAML'].type
|
||||
end
|
||||
|
||||
def test_other
|
||||
|
||||
Reference in New Issue
Block a user