Skip to content

Instantly share code, notes, and snippets.

@js1972
js1972 / infinite_streams.scala
Created June 17, 2014 01:09
Infinite Streams in Scala. Using infinite streams to efficiently calculate primes and square roots in a Scala Worksheet.
package week7
object primes {
//infinite stream builder
def from(n: Int): Stream[Int] = n #:: from(n + 1)
//> from: (n: Int)Stream[Int]
//infinte stream of all natural numbers
val nats = from(0) //> nats : Stream[Int] = Stream(0, ?)
val m4s = nats map (_ * 4) //> m4s : scala.collection.immutable.Stream[Int] = Stream(0, ?)
@js1972
js1972 / Pouring.scala
Created June 17, 2014 02:27
Solution to the Water Pouring problem in Scala
package week7
class Pouring(capacity: Vector[Int]) {
// States
type State = Vector[Int]
val initialState = capacity map (x => 0)
// Moves
@js1972
js1972 / sap_ui_getcore_by_id.js
Created June 24, 2014 03:04
Access a sapui5 element by id
sap.ui.getCore().byId("element_id")
@js1972
js1972 / dynamic_config_udf.java
Created June 25, 2014 02:32
Dynamic Configuration (ASMA) in a mapping UDF (User Defined Function). Note that the getTransformationParameters() method is deprecated; but it is the only way it seems to work within an ICO (iflow). Note: You create UDF's in a function library with NWDS and not in the mapping directly.
package pi_test_purchaseorder_es;
import com.sap.aii.mapping.api.*;
import java.io.*;
import java.util.*;
import com.sap.aii.mappingtool.tf7.rt.*;
import com.sap.aii.mapping.lookup.*;
import java.lang.reflect.*;
import com.sap.ide.esr.tools.mapping.core.LibraryMethod;
import com.sap.ide.esr.tools.mapping.core.ExecutionType;
@js1972
js1972 / select_changes_then_merge.sql
Created June 26, 2014 08:56
SQLServer procedure to select changes between two tables based on a hash field, then update (merge) the second table with the changes. Change ALTER to CREATE/DROP to create or delete the procedure. Note: The PI JDBC Adapter does not like any blank lines in the Procedure!
alter procedure PersonDelta
as
SET NOCOUNT ON;
/* temp table - fill with changes between tables based on hash field */
declare @rows table(name nvarchar(255), street nvarchar(255), city nvarchar(255), postcode nvarchar(255), state nvarchar(255), hash nvarchar(255));
insert into @rows (name, street, city, postcode, state, hash)
select p.name, p.street, p.city, p.postcode, p.state, p.hash from T_PERSON as p left outer join T_PERSON_HIST as h on p.name = h.name where p.hash <> isnull(h.hash,'-1');
/* merge the cahnges into the second table */
merge into T_PERSON_HIST as target using @rows as source
on target.name = source.name
@js1972
js1972 / proc.sql
Created June 26, 2014 08:57
Create a simple SQLServer procedure
CREATE PROCEDURE PersonsListByPostcode @pc nvarchar(255)
AS
SELECT *
FROM T_PERSON
WHERE postcode = @pc
@js1972
js1972 / execute_proc.sql
Created June 26, 2014 08:58
Execute a simple SQLServer procedure
EXECUTE PersonsListByPostcode @pc = '6000'
@js1972
js1972 / proxy_serialize.abap
Created June 30, 2014 05:26
How to set a sender proxy message to EOIO (serialization). Call this serialize() method just prior to execute().
method serialize.
"importing io_proxy type ref to cl_proxy_basis
"raising cx_ai_system_fault
data:
lo_async_messaging type ref to if_wsprotocol_async_messaging.
queue = get_queue_name( ).
check not queue is initial.
@js1972
js1972 / data_and_new_operators.abap
Created July 4, 2014 02:19
Using the new DATA() operator to declare a new variable in-line and the new NEW() operator for instantiating an object. These are available from ABAP 7.40. In this example we are creating a new string object, then de-referencing when we need to use it in the method call. We are also creating a new lcl_text_reader object and immediately calling t…
data(delivery_value) = new string( delivery ).
data(text) = new lcl_text_reader( )->get_as_string(
id = '0002'
name = delivery_value->*
object = 'VBBK'
).
@js1972
js1972 / abap_type_conversion.abap
Created July 4, 2014 02:55
Using the new ABAP 7.40 constructor operation CONV for converting data-types on the fly. In this example we need to pass the name to the get_as_string method. i_delivery is type vbeln_vl yet a string is expected. CONV # takes car of the conversion in-line.
method payment_terms_text.
data(text) = new lcl_text_reader( )->get_as_string(
id = '0002'
name = conv #( i_delivery )
object = 'VBBK'
).
data proxy_text_collection type zxi_text_collection_text_tab.
data proxy_text_line like line of proxy_text_collection.