This sample show how to attach globally to events over dynamically created elements.
And how can data-*
attributes be used to customize behaviour.
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
puts "sfs" | |
10.times do |i| | |
puts i | |
{ "Lon\nrem", i, i + 1 } | |
sleep 1 | |
end | |
sleep 2 |
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
puts "sfs" | |
class Crystal::Playground::Agent | |
def sendp(t) | |
send(t) | |
end | |
end | |
# $p.try &.sendp("bug") | |
10.times do |i| | |
puts i |
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
require "benchmark" | |
def string_contains_word(source, word) | |
return false unless source | |
start = source.index(word) | |
return false unless start | |
return false if start > 0 && source[start-1].alphanumeric? | |
return false if start + word.size < source.size && source[start + word.size].alphanumeric? | |
true | |
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
data = [{"Brian", 42}, {"Alan", 30}, {"Brian", 32}] | |
# unstable | |
data.sort_by &.[0] # => [{"Brian", 42}, {"Alan", 30}, {"Brian", 32}] | |
# stable | |
data.map_with_index { |d,i| {d,i} }.sort_by { |di| {di[0][0], di[1]} }.map { |di| di[0] } # => [{"Alan", 30}, {"Brian", 42}, {"Brian", 32}] |
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
def ej(a, b) | |
size = [a.size, b.size].min | |
a[0...size].zip(b[0...size]) | |
.map { |e| e.max } | |
.map(&.+(4)) | |
.select(&.>=(10)) | |
.sum | |
end | |
ej [1,5,3,4], [5,3,6] |
$ brew install imagemagick
$ brew install tesseract
$ ls -l1
Basic Infrastructure.pdf
extract.rb
$ ruby extract.rb 2> /dev/null
extracting page 1
.....................
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
require "pg" | |
# start a posgress | |
# $ docker run --name mypg -e POSTGRES_DB=crystal -e POSTGRES_USER=postgress -e POSTGRES_PASSWORD= -p 5432:5432 postgres:9.5 | |
# <ctrl+c> to stop server | |
# restart it | |
# $ docker start -a mypg | |
# <ctrl+c> to stop server |
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
require "json" | |
struct Slice(T) | |
def to_json(json : JSON::Builder) | |
json.array do | |
each do |e| | |
e.to_json(json) | |
end | |
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
unless ARGV.size > 0 | |
puts " Missing executable file argument" | |
puts " Usage (in a Dockerfile)" | |
puts " RUN crystal run ./path/to/list-deps.cr -- ./bin/executable" | |
exit 1 | |
end | |
executable = File.expand_path(ARGV[0]) | |
unless File.exists?(executable) |