SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
Some Javascript
    useful perhaps
他山之石,可以攻玉
Stones from other hills may serve
to polish the jade of this one.

advice from others may help one
overcome one's shortcomings.
Ruby
           A Programmer’s Best Friend


This time we use Ruby to polish our
               Jade.
Integer.times


                    (10).times(function
10.times do |i| 
                    (i){

print i*10, " "
                    
print( i*10 + “ ”);
end
                    });
Number.step
1.step(10, 2) { |i| print i, " " }

Math::E.step(Math::PI, 0.2) { |f| print f, " " }



(1).step(function(i){ print(i); }, 10, 2);

Math.E.step(function(f){ print(f); },
Number Object

         modulo     abs
  ceil
             floor
round
             step
String.capitalise
"hello".capitalize #=> "Hello"
"HELLO".capitalize#=> "Hello"
"123ABC".capitalize#=>
"123abc"
"hello".capitalize() > "Hello"
"HELLO".capitalize() > "Hello" 
"123ABC".capitalize() > "123abc"
String.each_char

"hello".each_char {|c| print c, ' '} #=> "h e l l o
"




“hello”.each_char (function(c) {return c+” ”}) > “h
e l l o ”
String.insert
"abcd".insert(-3, 'X')   #=> 'abXcd'
"abcd".insert(-1, 'X')   #=> 'abcdX'
"abcd".insert(1, 'X')    #=> 'aXbcd'

"abcd".insert(-3, 'X')   > 'abXcd'
"abcd".insert(-1, 'X')   > 'abcdX'
"abcd".insert(1, 'X')    > 'aXbcd'
String.reverse

"Hello".reverse     #=> "olleh"




"Hello".reverse()   > "olleh"
String Object

        casecmp      insert
each_char
            capitalise
strip                 swapcase
          start_with
   end_with
                reverse
Array.each
[1,2,3].each {|i| print i+5 }   #=> 6 7 8

[1,2,3].each(function(i){ print( i+5) }) > 6 7 8
[1,2,3].reverse_each(function(i){ print( i+5) }) >
8 7 6
[{a:1,b:2},{a:2,b:3},{a:3,b:4}].each(function(item){
    print(item.a+item.b)
}) > 3 5 7
Array.map
a = [ "a", "b", "c", "d" ]
a.map {|x|x+"!" }       #=> ["a!", "b!", "c!", "d!"]
a                       #=> ["a", "b", "c", "d"]

var a = [ "a", "b", "c", "d" ];
a.map(function(i,item){return x+”!”}) > ["a!",
"b!", "c!", "d!"]
a                                           > [ "a",
"b", "c", "d" ]
Array.remove_if
          (Array.reject)
[ "a", "b", "c" ].reject {|x| x>="b" }   #=> ["a"]




[ "a", "b", "c" ].reject( function(i,x) {return x >=
"b" })
a = [ 4, 5, 6 ]
                 Array.zip
b = [ 7, 8, 9 ]
[1,2,3].zip(a, b)     #=> [[1, 4, 7], [2, 5, 8], [3,
6, 9]]
[1,2].zip(a,b)        #=> [[1, 4, 7], [2, 5, 8]]
a.zip([1,2],[8])      #=> [[4, 1, 8], [5, 2, nil],
var a = [ 4, 5, 6 ];
[6, nil, nil]]
var b = [ 7, 8, 9 ];
[1,2,3].zip(a, b)    > [[1, 4, 7], [2, 5, 8], [3, 6,
9]]
[1,2].zip(a,b)       > [[1, 4, 7], [2, 5, 8]]
a.zip([1,2],[8])      > [[4, 1, 8], [5, 2, null], [6,
null, null]]
Array.transpose
a = [[1,2], [3,4], [5,6]]
a.transpose                    #=> [[1, 3, 5], [2, 4,
6]]




var a = [[1,2], [3,4], [5,6]];
a.transpose()                   > [[1, 3, 5], [2, 4,
6]]
Array.rotate
a = [ "a", "b", "c", "d" ]
a.rotate             #=> ["b", "c", "d", "a"]
a                    #=> ["a", "b", "c", "d"]
a.rotate(2)          #=> ["c", "d", "a", "b"]
a.rotate(-3)         #=> ["b", "c", "d", "a"]

var a = [ "a", "b", "c", "d" ];
a.rotate()             > ["b", "c", "d", "a"]
a                      > ["a", "b", "c", "d"]
a.rotate(2)           > ["c", "d", "a", "b"]
a.rotate(-3)          > ["b", "c", "d", "a"]
Array.flatten
s = [ 1, 2, 3 ]         #=> [1, 2, 3]
t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]]
a = [ s, t, 9, 10 ]     #=> [[1, 2, 3], [4, 5, 6, [7,
8]], 9, 10]
a.flatten                #=> [1, 2, 3, 4, 5, 6, 7, 8,
9, 10]

a = [ 1, 2, [3, [4, 5] ] ]
a.flatten(1)              #=> [1, 2, 3, [4, 5]]
Array.sample

[1,2,3,4,5,6,7,8,9,10].sample()    #=> 7 (just
randomly selected)


[1,2,3,4,5,6,7,8,9,10].sample(3)   #=> 3, 9, 2
Array.shuffle


a = [ 1, 2, 3 ]         #=> [1, 2, 3]
a.shuffle               #=> [2, 3, 1]

var a = [ 1, 2, 3 ];      > [1, 2, 3]
a.shuffle()                > [2, 3, 1]
Array Object
                 is_empty
         push_all          size
      reverse_eachintersect clear
  each                     deduct
       map uniq        union
sample     at shuffle values_attranspose
   contains                        last
                      transpose
 keep_if     compact      select
       remove                    insert
  remove_if        reject      zip
       index      rotate      equals
                        take
   remove_at fetchtake_while
         flatten count
Examples

(1..10).map{|i| ("a".."z").to_a[rand 26] }.join             

new Array(10).map(function(i,item){

    return
"abcdefghijklmnopqrstuvwxyz"[(26*Math.random()).floor()]
;

}).join("");

(10).times(function(i){

    return
"abcdefghijklmnopqrstuvwxyz"[(26*Math.random()).floor()];

}).join("");
Examples

(1..10).map{|i| ("a".."z").to_a[rand 26] }.join             

new Array(10).map(function(i,item){

    return
"abcdefghijklmnopqrstuvwxyz"[(26*Math.random()).floor()]
;

}).join("");

(10).times(function(i){

    return
"abcdefghijklmnopqrstuvwxyz"[(26*Math.random()).floor()];

}).join("");
How I simply try
 these snippets
            nodejs




             irb
Thanks to
What if we can write
 and test like this
require '../src/com/ciphor/ruby/Array.js'
describe 'com.ciphor.ruby.Array', ->
    testArray = null
    beforeEach ->
      testArray = [1, 2, 3, 4, 5]
                                   Test for BDD -

                                Behaviour Driven
    afterEach ->
      testArray = null
                                   Developement

    it 'adds all elements in the given array into the self', ->
     testArray.push_all [6, 7, 8]
     expect(testArray.length).toEqual(8)
     expect(testArray).toContain(8)
+

...to be continued
Not


The End

Weitere ähnliche Inhalte

Was ist angesagt?

The secrets of inverse brogramming
The secrets of inverse brogrammingThe secrets of inverse brogramming
The secrets of inverse brogrammingRichie Cotton
 
Data Types and Processing in ES6
Data Types and Processing in ES6Data Types and Processing in ES6
Data Types and Processing in ES6m0bz
 
imager package in R and examples..
imager package in R and examples..imager package in R and examples..
imager package in R and examples..Dr. Volkan OBAN
 
Ruby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と HashRuby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と Hashhigaki
 
python高级内存管理
python高级内存管理python高级内存管理
python高级内存管理rfyiamcool
 
Rのスコープとフレームと環境と
Rのスコープとフレームと環境とRのスコープとフレームと環境と
Rのスコープとフレームと環境とTakeshi Arabiki
 
Ruby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and IteratorsRuby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and IteratorsSarah Allen
 
Ruby's Arrays and Hashes with examples
Ruby's Arrays and Hashes with examplesRuby's Arrays and Hashes with examples
Ruby's Arrays and Hashes with examplesNiranjan Sarade
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyBrian Aker
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveEugene Zharkov
 
Gearman, from the worker's perspective
Gearman, from the worker's perspectiveGearman, from the worker's perspective
Gearman, from the worker's perspectiveBrian Aker
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
Logic Equations Resolver J Script
Logic Equations Resolver   J ScriptLogic Equations Resolver   J Script
Logic Equations Resolver J ScriptRoman Agaev
 

Was ist angesagt? (20)

The secrets of inverse brogramming
The secrets of inverse brogrammingThe secrets of inverse brogramming
The secrets of inverse brogramming
 
Groovy
GroovyGroovy
Groovy
 
Clojure functions midje
Clojure functions midjeClojure functions midje
Clojure functions midje
 
Data Types and Processing in ES6
Data Types and Processing in ES6Data Types and Processing in ES6
Data Types and Processing in ES6
 
imager package in R and examples..
imager package in R and examples..imager package in R and examples..
imager package in R and examples..
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
 
Ruby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と HashRuby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と Hash
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
python高级内存管理
python高级内存管理python高级内存管理
python高级内存管理
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Rのスコープとフレームと環境と
Rのスコープとフレームと環境とRのスコープとフレームと環境と
Rのスコープとフレームと環境と
 
Ruby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and IteratorsRuby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and Iterators
 
Ruby's Arrays and Hashes with examples
Ruby's Arrays and Hashes with examplesRuby's Arrays and Hashes with examples
Ruby's Arrays and Hashes with examples
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and Reactive
 
Gearman, from the worker's perspective
Gearman, from the worker's perspectiveGearman, from the worker's perspective
Gearman, from the worker's perspective
 
Millionways
MillionwaysMillionways
Millionways
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
Logic Equations Resolver J Script
Logic Equations Resolver   J ScriptLogic Equations Resolver   J Script
Logic Equations Resolver J Script
 

Andere mochten auch

Cansecwest_16_Dont_Trust_Your_Eye_Apple_Graphics_Is_Compromised
Cansecwest_16_Dont_Trust_Your_Eye_Apple_Graphics_Is_CompromisedCansecwest_16_Dont_Trust_Your_Eye_Apple_Graphics_Is_Compromised
Cansecwest_16_Dont_Trust_Your_Eye_Apple_Graphics_Is_CompromisedLiang Chen
 
Moving Towards a Paperless Classroom
Moving Towards a Paperless ClassroomMoving Towards a Paperless Classroom
Moving Towards a Paperless ClassroomMacmillan Education
 
CatAnDogme - Creative Activities and dogme (by Jimmy Astley and Mauro Espindola)
CatAnDogme - Creative Activities and dogme (by Jimmy Astley and Mauro Espindola)CatAnDogme - Creative Activities and dogme (by Jimmy Astley and Mauro Espindola)
CatAnDogme - Creative Activities and dogme (by Jimmy Astley and Mauro Espindola)Jimmy Astley
 
Dogme Workshop Materials
Dogme Workshop MaterialsDogme Workshop Materials
Dogme Workshop MaterialsAnia Rolinska
 
English world teacher training technology
English world teacher training technologyEnglish world teacher training technology
English world teacher training technologyMacmillan Education
 
Dogme ELT - a Pedagogy for Virtual Worlds
Dogme ELT - a Pedagogy for Virtual WorldsDogme ELT - a Pedagogy for Virtual Worlds
Dogme ELT - a Pedagogy for Virtual WorldsHoward Vickers
 

Andere mochten auch (8)

Cansecwest_16_Dont_Trust_Your_Eye_Apple_Graphics_Is_Compromised
Cansecwest_16_Dont_Trust_Your_Eye_Apple_Graphics_Is_CompromisedCansecwest_16_Dont_Trust_Your_Eye_Apple_Graphics_Is_Compromised
Cansecwest_16_Dont_Trust_Your_Eye_Apple_Graphics_Is_Compromised
 
Moving Towards a Paperless Classroom
Moving Towards a Paperless ClassroomMoving Towards a Paperless Classroom
Moving Towards a Paperless Classroom
 
CatAnDogme - Creative Activities and dogme (by Jimmy Astley and Mauro Espindola)
CatAnDogme - Creative Activities and dogme (by Jimmy Astley and Mauro Espindola)CatAnDogme - Creative Activities and dogme (by Jimmy Astley and Mauro Espindola)
CatAnDogme - Creative Activities and dogme (by Jimmy Astley and Mauro Espindola)
 
Dogme elt demo
Dogme elt demoDogme elt demo
Dogme elt demo
 
Dogme with young learners and beginners
Dogme with young learners and beginnersDogme with young learners and beginners
Dogme with young learners and beginners
 
Dogme Workshop Materials
Dogme Workshop MaterialsDogme Workshop Materials
Dogme Workshop Materials
 
English world teacher training technology
English world teacher training technologyEnglish world teacher training technology
English world teacher training technology
 
Dogme ELT - a Pedagogy for Virtual Worlds
Dogme ELT - a Pedagogy for Virtual WorldsDogme ELT - a Pedagogy for Virtual Worlds
Dogme ELT - a Pedagogy for Virtual Worlds
 

Ähnlich wie Useful javascript

Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About RubyIan Bishop
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)riue
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2Kevin Chun-Hsien Hsu
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilNova Patch
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpyFaraz Ahmed
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 
Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick touraztack
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Dr. Volkan OBAN
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Pythonpugpe
 
PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007Damien Seguy
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testingVincent Pradeilles
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.Dr. Volkan OBAN
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Namgee Lee
 

Ähnlich wie Useful javascript (20)

Intoduction to php arrays
Intoduction to php arraysIntoduction to php arrays
Intoduction to php arrays
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About Ruby
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
R programming language
R programming languageR programming language
R programming language
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2
 
Spark_Documentation_Template1
Spark_Documentation_Template1Spark_Documentation_Template1
Spark_Documentation_Template1
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpy
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick tour
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
 
PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testing
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 

Kürzlich hochgeladen

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Kürzlich hochgeladen (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

Useful javascript

  • 1. Some Javascript useful perhaps
  • 2. 他山之石,可以攻玉 Stones from other hills may serve to polish the jade of this one. advice from others may help one overcome one's shortcomings.
  • 3. Ruby A Programmer’s Best Friend This time we use Ruby to polish our Jade.
  • 4. Integer.times (10).times(function 10.times do |i| (i){ print i*10, " " print( i*10 + “ ”); end });
  • 5. Number.step 1.step(10, 2) { |i| print i, " " } Math::E.step(Math::PI, 0.2) { |f| print f, " " } (1).step(function(i){ print(i); }, 10, 2); Math.E.step(function(f){ print(f); },
  • 6. Number Object modulo abs ceil floor round step
  • 7. String.capitalise "hello".capitalize #=> "Hello" "HELLO".capitalize#=> "Hello" "123ABC".capitalize#=> "123abc" "hello".capitalize() > "Hello" "HELLO".capitalize() > "Hello" "123ABC".capitalize() > "123abc"
  • 8. String.each_char "hello".each_char {|c| print c, ' '} #=> "h e l l o " “hello”.each_char (function(c) {return c+” ”}) > “h e l l o ”
  • 9. String.insert "abcd".insert(-3, 'X') #=> 'abXcd' "abcd".insert(-1, 'X') #=> 'abcdX' "abcd".insert(1, 'X') #=> 'aXbcd' "abcd".insert(-3, 'X') > 'abXcd' "abcd".insert(-1, 'X') > 'abcdX' "abcd".insert(1, 'X') > 'aXbcd'
  • 10. String.reverse "Hello".reverse #=> "olleh" "Hello".reverse() > "olleh"
  • 11. String Object casecmp insert each_char capitalise strip swapcase start_with end_with reverse
  • 12. Array.each [1,2,3].each {|i| print i+5 } #=> 6 7 8 [1,2,3].each(function(i){ print( i+5) }) > 6 7 8 [1,2,3].reverse_each(function(i){ print( i+5) }) > 8 7 6 [{a:1,b:2},{a:2,b:3},{a:3,b:4}].each(function(item){ print(item.a+item.b) }) > 3 5 7
  • 13. Array.map a = [ "a", "b", "c", "d" ] a.map {|x|x+"!" } #=> ["a!", "b!", "c!", "d!"] a #=> ["a", "b", "c", "d"] var a = [ "a", "b", "c", "d" ]; a.map(function(i,item){return x+”!”}) > ["a!", "b!", "c!", "d!"] a > [ "a", "b", "c", "d" ]
  • 14. Array.remove_if (Array.reject) [ "a", "b", "c" ].reject {|x| x>="b" } #=> ["a"] [ "a", "b", "c" ].reject( function(i,x) {return x >= "b" })
  • 15. a = [ 4, 5, 6 ] Array.zip b = [ 7, 8, 9 ] [1,2,3].zip(a, b) #=> [[1, 4, 7], [2, 5, 8], [3, 6, 9]] [1,2].zip(a,b) #=> [[1, 4, 7], [2, 5, 8]] a.zip([1,2],[8]) #=> [[4, 1, 8], [5, 2, nil], var a = [ 4, 5, 6 ]; [6, nil, nil]] var b = [ 7, 8, 9 ]; [1,2,3].zip(a, b) > [[1, 4, 7], [2, 5, 8], [3, 6, 9]] [1,2].zip(a,b) > [[1, 4, 7], [2, 5, 8]] a.zip([1,2],[8]) > [[4, 1, 8], [5, 2, null], [6, null, null]]
  • 16. Array.transpose a = [[1,2], [3,4], [5,6]] a.transpose #=> [[1, 3, 5], [2, 4, 6]] var a = [[1,2], [3,4], [5,6]]; a.transpose() > [[1, 3, 5], [2, 4, 6]]
  • 17. Array.rotate a = [ "a", "b", "c", "d" ] a.rotate #=> ["b", "c", "d", "a"] a #=> ["a", "b", "c", "d"] a.rotate(2) #=> ["c", "d", "a", "b"] a.rotate(-3) #=> ["b", "c", "d", "a"] var a = [ "a", "b", "c", "d" ]; a.rotate() > ["b", "c", "d", "a"] a > ["a", "b", "c", "d"] a.rotate(2) > ["c", "d", "a", "b"] a.rotate(-3) > ["b", "c", "d", "a"]
  • 18. Array.flatten s = [ 1, 2, 3 ] #=> [1, 2, 3] t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]] a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10] a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a = [ 1, 2, [3, [4, 5] ] ] a.flatten(1) #=> [1, 2, 3, [4, 5]]
  • 19. Array.sample [1,2,3,4,5,6,7,8,9,10].sample() #=> 7 (just randomly selected) [1,2,3,4,5,6,7,8,9,10].sample(3) #=> 3, 9, 2
  • 20. Array.shuffle a = [ 1, 2, 3 ] #=> [1, 2, 3] a.shuffle #=> [2, 3, 1] var a = [ 1, 2, 3 ]; > [1, 2, 3] a.shuffle() > [2, 3, 1]
  • 21. Array Object is_empty push_all size reverse_eachintersect clear each deduct map uniq union sample at shuffle values_attranspose contains last transpose keep_if compact select remove insert remove_if reject zip index rotate equals take remove_at fetchtake_while flatten count
  • 22. Examples (1..10).map{|i| ("a".."z").to_a[rand 26] }.join new Array(10).map(function(i,item){ return "abcdefghijklmnopqrstuvwxyz"[(26*Math.random()).floor()] ; }).join(""); (10).times(function(i){ return "abcdefghijklmnopqrstuvwxyz"[(26*Math.random()).floor()]; }).join("");
  • 23. Examples (1..10).map{|i| ("a".."z").to_a[rand 26] }.join new Array(10).map(function(i,item){ return "abcdefghijklmnopqrstuvwxyz"[(26*Math.random()).floor()] ; }).join(""); (10).times(function(i){ return "abcdefghijklmnopqrstuvwxyz"[(26*Math.random()).floor()]; }).join("");
  • 24. How I simply try these snippets nodejs irb
  • 26. What if we can write and test like this require '../src/com/ciphor/ruby/Array.js' describe 'com.ciphor.ruby.Array', -> testArray = null beforeEach -> testArray = [1, 2, 3, 4, 5] Test for BDD - Behaviour Driven afterEach -> testArray = null Developement it 'adds all elements in the given array into the self', -> testArray.push_all [6, 7, 8] expect(testArray.length).toEqual(8) expect(testArray).toContain(8)