This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn unsafe-deserialization? [node] | |
(and (call-with-receiver-node? node) | |
(eq-receiver? node "YAML") | |
(some #(eq-method-name? node %) | |
["load" "load_documents" "load_stream" "parse_documents" "parse_stream"]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2.1.1 :001 > def test(foo:) | |
2.1.1 :002?> puts foo | |
2.1.1 :003?> end | |
=> :test | |
2.1.1 :004 > test() | |
ArgumentError: missing keyword: foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jacob@Ninja:$ bin/benchmark_rails | |
Rehearsal ------------------------------------ | |
"Codeminer encountered 2 errors parsing 1711 files" | |
6.520000 0.040000 6.560000 ( 6.564404) | |
"RubyParser encountered 26 errors parsing 1711 files" | |
17.110000 0.240000 17.350000 ( 17.340777) | |
-------------------------- total: 23.910000sec | |
user system total real |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RenameTableToLongerName < ActiveRecord::Migration | |
def change | |
remove_index :table, name: 'index_table_on_something_id' | |
remove_index :table, name: 'index_table_on_something_id' | |
rename_table :table, :incredibly_long_table_name_overflowing_index_length | |
add_index :incredibly_long_table_name_overflowing_index_length, :something_id, name: 'index_iltnoil_on_something_id' | |
add_index :incredibly_long_table_name_overflowing_index_length, :something_id, name: 'index_iltnoil_on_something_id' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 1: Swap the consequence and else statements in an if expression | |
if_node = CodeMiner.parse(<<-RUBY).each.first | |
if foo | |
begin | |
do_something | |
end | |
else | |
do_something_else | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parse results for Rails | |
user system total real | |
"Codeminer parse results: 0 parse errors, 0 runtime errors, 1621 files total" | |
7.760000 0.080000 7.840000 ( 7.980644) | |
"Codeminer sexp results: 0 parse errors, 0 runtime errors, 1621 files total" | |
11.080000 0.040000 11.120000 ( 11.136238) | |
"Codeminer (RubyParser compatible) sexp results: 0 parse errors, 0 runtime errors, 1621 files total" | |
11.250000 0.070000 11.320000 ( 11.317630) | |
"Codeminer flog results: 0 parse errors, 0 runtime errors, 1621 files total" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NilClass | |
def to_a | |
p 'calling to_a within NilClass' | |
[] | |
end | |
end | |
# irb(main):017:0> [*nil] | |
# "calling to_a within NilClass" | |
# => [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):002:0> Ripper.sexp "'foo'" | |
=> [:program, [[:string_literal, [:string_content, [:@tstring_content, "foo", [1, 1]]]]]] | |
irb(main):003:0> Ripper.sexp '"foo"' | |
=> [:program, [[:string_literal, [:string_content, [:@tstring_content, "foo", [1, 1]]]]]] | |
irb(main):004:0> Ripper.sexp '"#{foo}"' | |
=> [:program, [[:string_literal, [:string_content, [:string_embexpr, [[:vcall, [:@ident, "foo", [1, 3]]]]]]]]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Add the resulting vector to `:aot` on your dev profile | |
(def directory ".") | |
(defn- read-file [file] | |
(binding [*read-eval* false] | |
(read-string (slurp file)))) | |
(defn- require-form? [form] | |
(and (seq? form) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Core | |
(defn- maplast | |
"Apply map-fn to the last element in s | |
unless s contains only 1 element" | |
[map-fn s] | |
(if (> (count s) 1) | |
(conj (vec (butlast s)) | |
(map-fn (last s))) | |
s)) |
OlderNewer