SlideShare une entreprise Scribd logo
1  sur  23
transmogrifier
   A JavaScript Utility
for Transforming Objects
trans·mog·ri·fy
•It’s a real word
   trăns-mŏg'rə-fī', trănz-
   tr.v, -fied, -fy·ing, -fies.

   To change into a different
   shape or form, especially one
   that is fantastic or bizarre.
   http://www.answers.com/transmogrify
trans·mog·ri·fy
•It’s a real word
   trăns-mŏg'rə-fī', trănz-
   tr.v, -fied, -fy·ing, -fies.

   To change into a different
   shape or form, especially one
   that is fantastic or bizarre.
   http://www.answers.com/transmogrify
what’s it for?
what’s it for?
really, what’s it for?


•To sanitize and simplify complex
  objects, like those returned by
  MLB’s services
•Inspired by getDeepValue and
  setDeepValue
•Implemented in $Q for transforming
  objects as defined in .select method
wywinwyg
wywinwyg
 what you want is not what you get
what you need
{

   "id":

   "type":

   "status":

   "venue":

   "teams": {

   
    "away": {

   
    
    "id":

   
    
    "name":

   
    
    "code":

   
    },

   
    "home": {

   
    
    "id":

   
    
    "name":

   
    
    "code":

   
    }

   },

   "pitchers": [],

   "apple":

   "banana":

   "yellow":
}
what you ge...
{

        "game_id": "2009/09/24/cinmlb-pitmlb-1",

        "game_pk": "246475",

        "game_time_is_tbd": false,

        "game_venue": "PNC Park",

        "game_time": "1253810100000",

        "game_time_offset_eastern": "-4",

        "pitcher": {

        
        "loss_id": "450203",

        
        "win_id": "276520",

        
        "win": "Arroyo",

        
        "loss_stat": "4-9",

        
        "win_stat": "14-13",

        
        "save": "Cordero",

        
        "save_stat": "39",

        
        "loss": "Morton",

        
        "save_id": "150188"

        },

        "game_location": "Pittsburgh",

        "home": {

        
        "file_code": "pit",

        
        "probable_stat": "5-9",

        
        "tv": null,

        
        "id": "134",

        
        "split": false,

        
        "probable_name_display_first_last": "Charlie Morton",

        
        "probable_report": "Morton showed some improved command in his last start, a sign that maybe he's beginning to figure out how
to use the movement he can get on his pitches to his benefit. The consistency of his command has been the biggest problem for Morton all
season, but after allowing an early run and getting out of an early jam, Morton found just that against the Padres. He matched his career high
with seven innings and has now allowed three or fewer runs in four of his past five starts. Morton is 1-1 with a 6.35 ERA in two previous
starts against Cincinnati.",

        
        "recap": "/news/gameday_recap.jsp?ymd=20090924&content_id=7131310&vkey=recap&fext=.jsp&c_id=pit",

        
        "full": "Pirates",

        
        "tickets": null,

        
        "radio": "WPGB-FM 104.7",

        
        "game_time_offset": "-4",

        
        "display_code": "PIT",
...eeeeee...

        
        "preview": "javascript:void(launchGameday({gid:'2009_09_24_cinmlb_pitmlb_1',mode:'preview',lurl:'/news/article.jsp?
ymd=20090923&content_id=7109806&vkey=news_pit&fext=.jsp&c_id=pit'}))",

        
        "wrapup": "/news/wrap.jsp?ymd=20090924&content_id=7131314&vkey=wrapup2005&fext=.jsp&team=home&c_id=pit",

        
        "audio_uri":
"javascript:bam.media.launchPlayer({content_id:'6765579',view_key:'MLBTV_MP_4',media_type:'audio',calendar_event_id:'14-246475-2009-09-24'})",

        
        "probable": "Morton",

        
        "probable_era": "4.55",

        
        "league": "104",

        
        "probable_id": "450203",

        
        "result": "1"

        },

        "division_id": "205",

        "game_time_offset_local": "-4",

        "scheduledTime": null,

        "game_status": "F",

        "mlbtv": true,

        "is_suspension_resumption": false,

        "video_uri":
"javascript:bam.media.launchPlayer({content_id:'6765575',view_key:'MLBTV_MP_4',media_type:'video',calendar_event_id:'14-246475-2009-09-24'})",

        "sport_code": "mlb",

        "venue_id": "31",

        "wrapup": "javascript:void(launchGameday({gid:'2009_09_24_cinmlb_pitmlb_1',mode:'wrap',lurl:'/news/wrap.jsp?
ymd=20090924&content_id=7131314&vkey=wrapup2005&fext=.jsp&c_id=mlb'}))",

        "preview": null,

        "game_type": "R",

        "resumptionTime": null,

        "away": {

        
        "file_code": "cin",

        
        "probable_stat": "15-13",

        
        "tv": null,

        
        "id": "113",

        
        "split": false,

        
        "probable_name_display_first_last": "Bronson Arroyo",

        
        "probable_report": "Arroyo was perfect through three innings Saturday against Florida, but a couple of costly mistakes led to
a loss, most notably a changeup to pinch-hitter Ross Gload that resulted in a two-run home run in the eighth, which lifted the Marlins to a
3-2 victory. Arroyo allowed three runs on six hits. He walked one and struck out six but allowed two home runs. Despite the loss, Arroyo
extended his streak of consecutive quality starts to 11.",

        
        "recap": "/news/gameday_recap.jsp?ymd=20090924&content_id=7131308&vkey=recap&fext=.jsp&c_id=cin",

        
        "full": "Reds",

        
        "tickets": null,
...et

        
        "radio": "WLW 700",

        
        "game_time_offset": "-4",

        
        "display_code": "CIN",

        
        "preview": "javascript:void(launchGameday({gid:'2009_09_24_cinmlb_pitmlb_1',mode:'preview',lurl:'/news/article.jsp?
ymd=20090923&content_id=7109796&vkey=news_cin&fext=.jsp&c_id=cin'}))",

        
        "wrapup": "/news/wrap.jsp?ymd=20090924&content_id=7131314&vkey=wrapup2005&fext=.jsp&team=away&c_id=cin",

        
        "audio_uri":
"javascript:bam.media.launchPlayer({content_id:'6765579',view_key:'MLBTV_MP_4',media_type:'audio',calendar_event_id:'14-246475-2009-09-24'})",

        
        "probable": "Arroyo",

        
        "probable_era": "3.84",

        
        "league": "104",

        
        "probable_id": "276520",

        
        "result": "4"

        },

        "game_dh": null,

        "game_num": "1",

        "fruit": [

        
        {

        
        
        "name": "apple",

        
        
        "color": "green"

        
        },

        
        {

        
        
        "name": "banana",

        
        
        "color": "yellow"

        
        },

        
        {

        
        
        "name": "cherry",

        
        
        "color": "red"

        
        }

        ]
}
and that’s just one!
how it works
var gameTemplate = {
  id:      'game_id',                  // output.id === input.game_id
  type:    'game_type',                // output.type === input.game_type
  status: 'game_status',               // output.status === input.game_status
  venue: 'game_venue',                 // output.venue === input.game_venue
  teams: {                             // output.teams === {}
     away: {                           // output.teams.away === {}
       id:   'away.id',                // output.teams.away.id === input.away.id
       name: 'away.full',              // output.teams.away.name === input.away.full
       code: 'away.file_code'          // output.teams.away.code === input.away.file_code
     },
     home: {                           // output.teams.home === {}
       id:   'home.id',                // output.teams.home.id === input.home.id
       name: 'home.full',              // output.teams.home.name === input.home.full
       code: 'home.file_code'          // output.teams.home.code === input.home.file_code
     }
  },
  time: function convertGameTime (obj) {
     var d = new Date(+obj.game_time),
         e = +obj.game_time_offset_eastern,
         h, m, a;
     d.setHours(d.getUTCHours() + e);
     h = d.getHours();
     m = d.getMinutes();
     h = h % 12 || 12;
     m = m < 10 ? '0' + m : m;
     a = h < 12 ? 'am' : 'pm';
     return h + ':' + m + a;           // output.time === input.game_time (h:mmaa)
  },
  pitchers: [                          // output.pitchers === []
     'pitcher.win',                    // output.pitchers[0] === input.pitcher.win
     'pitcher.loss',                   // output.pitchers[1] === input.pitcher.loss
     'pitcher.save'                    // output.pitchers[2] === input.pitcher.save
  ],
  apple: 'fruit.0',                    // output.apple === input.fruit[0]
  banana: 'fruit[1]',                  // output.banana === input.fruit[1]
  yellow: 'fruit[1].color'             // output.yellow === input.fruit[1].color
};

var gameTransmogrifier = new Transmogrifier(gameTemplate);
gameTransmogrifier.zap(gameObj);

{

   "id": "2009/09/24/cinmlb-pitmlb-1",

   "type": "R",

   "status": "F",

   "venue": "PNC Park",

   "teams": {

   
      "away": {

   
      
      "id": "113",

   
      
      "name": "Reds",

   
      
      "code": "cin"

   
      },

   
      "home": {

   
      
      "id": "134",

   
      
      "name": "Pirates",

   
      
      "code": "pit"

   
      }

   },

   "time": "12:35pm",

   "pitchers": [

   
      "Arroyo",

   
      "Morton",

   
      "Cordero"

   ],

   "apple": {

   
      "name": "apple",

   
      "color": "green"

   },

   "banana": {

   
      "name": "banana",

   
      "color": "yellow"

   },

   "yellow": "yellow"
}
two methods
.zap (objOrArr)
Transforms a single object or array
.nuke (arrOfObjs)
 Applies .zap to members of array
Transmogrify
Transmogrify

Contenu connexe

Tendances

Kevin milla arbieto informatica piktochart backup data
Kevin milla arbieto informatica   piktochart backup dataKevin milla arbieto informatica   piktochart backup data
Kevin milla arbieto informatica piktochart backup dataKevin Miguel Milla
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic trapsDamien Seguy
 
ใบงานเรื่องการคอมไพล์โปรแกรม
ใบงานเรื่องการคอมไพล์โปรแกรมใบงานเรื่องการคอมไพล์โปรแกรม
ใบงานเรื่องการคอมไพล์โปรแกรมธงชัย พาศรี
 
The Security Risks of Web 2.0 - DEF CON 17
The Security Risks of Web 2.0 - DEF CON 17The Security Risks of Web 2.0 - DEF CON 17
The Security Risks of Web 2.0 - DEF CON 17Security Ninja
 
Bai Giang 11
Bai Giang 11Bai Giang 11
Bai Giang 11nbb3i
 
Python 炒股指南
Python 炒股指南 Python 炒股指南
Python 炒股指南 Leo Zhou
 
CBSE, Grade12, Computer Science, Random Numbers - Notes
CBSE, Grade12, Computer Science, Random Numbers - NotesCBSE, Grade12, Computer Science, Random Numbers - Notes
CBSE, Grade12, Computer Science, Random Numbers - NotesMalathi Senthil
 
Comment faire ses mappings ElasticSearch aux petits oignons ? - LINAGORA
Comment faire ses mappings ElasticSearch aux petits oignons ? - LINAGORAComment faire ses mappings ElasticSearch aux petits oignons ? - LINAGORA
Comment faire ses mappings ElasticSearch aux petits oignons ? - LINAGORALINAGORA
 
Petunjuk pengisian lhkpn model a
Petunjuk pengisian lhkpn model aPetunjuk pengisian lhkpn model a
Petunjuk pengisian lhkpn model aGolden Saragih
 
cape computer science unit 1 2016
cape computer science unit 1 2016cape computer science unit 1 2016
cape computer science unit 1 2016DE Realest Thomas
 
An Introduction to Tinkerpop
An Introduction to TinkerpopAn Introduction to Tinkerpop
An Introduction to TinkerpopTakahiro Inoue
 
This drone crashed the White House lawn
This drone crashed the White House lawnThis drone crashed the White House lawn
This drone crashed the White House lawnsimmonsmqpydcoqqy
 
Dip Your Toes in the Sea of Security (PHP South Africa 2017)
Dip Your Toes in the Sea of Security (PHP South Africa 2017)Dip Your Toes in the Sea of Security (PHP South Africa 2017)
Dip Your Toes in the Sea of Security (PHP South Africa 2017)James Titcumb
 

Tendances (20)

Kevin milla arbieto informatica piktochart backup data
Kevin milla arbieto informatica   piktochart backup dataKevin milla arbieto informatica   piktochart backup data
Kevin milla arbieto informatica piktochart backup data
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
ใบงานเรื่องการคอมไพล์โปรแกรม
ใบงานเรื่องการคอมไพล์โปรแกรมใบงานเรื่องการคอมไพล์โปรแกรม
ใบงานเรื่องการคอมไพล์โปรแกรม
 
The Security Risks of Web 2.0 - DEF CON 17
The Security Risks of Web 2.0 - DEF CON 17The Security Risks of Web 2.0 - DEF CON 17
The Security Risks of Web 2.0 - DEF CON 17
 
Speeding up Red Team engagements with carnivorall
Speeding up Red Team engagements with carnivorallSpeeding up Red Team engagements with carnivorall
Speeding up Red Team engagements with carnivorall
 
Bai Giang 11
Bai Giang 11Bai Giang 11
Bai Giang 11
 
Python 炒股指南
Python 炒股指南 Python 炒股指南
Python 炒股指南
 
CBSE, Grade12, Computer Science, Random Numbers - Notes
CBSE, Grade12, Computer Science, Random Numbers - NotesCBSE, Grade12, Computer Science, Random Numbers - Notes
CBSE, Grade12, Computer Science, Random Numbers - Notes
 
FizzBuzz Trek
FizzBuzz TrekFizzBuzz Trek
FizzBuzz Trek
 
Comment faire ses mappings ElasticSearch aux petits oignons ? - LINAGORA
Comment faire ses mappings ElasticSearch aux petits oignons ? - LINAGORAComment faire ses mappings ElasticSearch aux petits oignons ? - LINAGORA
Comment faire ses mappings ElasticSearch aux petits oignons ? - LINAGORA
 
Fizzbuzzalooza
FizzbuzzaloozaFizzbuzzalooza
Fizzbuzzalooza
 
Petunjuk pengisian lhkpn model a
Petunjuk pengisian lhkpn model aPetunjuk pengisian lhkpn model a
Petunjuk pengisian lhkpn model a
 
cape computer science unit 1 2016
cape computer science unit 1 2016cape computer science unit 1 2016
cape computer science unit 1 2016
 
An Introduction to Tinkerpop
An Introduction to TinkerpopAn Introduction to Tinkerpop
An Introduction to Tinkerpop
 
Delta5 Summary
Delta5 SummaryDelta5 Summary
Delta5 Summary
 
This drone crashed the White House lawn
This drone crashed the White House lawnThis drone crashed the White House lawn
This drone crashed the White House lawn
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
123
123123
123
 
Tabledown
TabledownTabledown
Tabledown
 
Dip Your Toes in the Sea of Security (PHP South Africa 2017)
Dip Your Toes in the Sea of Security (PHP South Africa 2017)Dip Your Toes in the Sea of Security (PHP South Africa 2017)
Dip Your Toes in the Sea of Security (PHP South Africa 2017)
 

En vedette

신용대출빠른곳『BU797』.『COM』현대해상보험회사 국내가족여행지
신용대출빠른곳『BU797』.『COM』현대해상보험회사 국내가족여행지신용대출빠른곳『BU797』.『COM』현대해상보험회사 국내가족여행지
신용대출빠른곳『BU797』.『COM』현대해상보험회사 국내가족여행지foskfs
 
Tales of Suckage and Awesomeness (Full Frontal 2012)
Tales of Suckage and Awesomeness (Full Frontal 2012)Tales of Suckage and Awesomeness (Full Frontal 2012)
Tales of Suckage and Awesomeness (Full Frontal 2012)Chris Wilson
 
The Hotel By Helen Slater
The  Hotel   By  Helen  SlaterThe  Hotel   By  Helen  Slater
The Hotel By Helen SlaterHelen Slater
 
Kriyathmak anusantaan
Kriyathmak anusantaan Kriyathmak anusantaan
Kriyathmak anusantaan simisanto
 
Biserica densus (cl)
Biserica densus (cl)Biserica densus (cl)
Biserica densus (cl)VASILE Viorel
 
Hybris Biblia - Vendetta annunciata
Hybris Biblia - Vendetta annunciataHybris Biblia - Vendetta annunciata
Hybris Biblia - Vendetta annunciataGiovanna Esse
 
Un Bain De Lumiere
Un Bain De LumiereUn Bain De Lumiere
Un Bain De Lumierewestberti71
 
Sexy factureren Factureringscongres 2012
Sexy factureren Factureringscongres 2012Sexy factureren Factureringscongres 2012
Sexy factureren Factureringscongres 2012Vincent Everts
 
Hugo Chavez Sueldos De La Bolioligraquia
Hugo Chavez   Sueldos De La BolioligraquiaHugo Chavez   Sueldos De La Bolioligraquia
Hugo Chavez Sueldos De La Bolioligraquiarevedery
 
Worst Photoshop mistakes ever
Worst Photoshop mistakes everWorst Photoshop mistakes ever
Worst Photoshop mistakes everMicAymeric
 

En vedette (17)

신용대출빠른곳『BU797』.『COM』현대해상보험회사 국내가족여행지
신용대출빠른곳『BU797』.『COM』현대해상보험회사 국내가족여행지신용대출빠른곳『BU797』.『COM』현대해상보험회사 국내가족여행지
신용대출빠른곳『BU797』.『COM』현대해상보험회사 국내가족여행지
 
Tales of Suckage and Awesomeness (Full Frontal 2012)
Tales of Suckage and Awesomeness (Full Frontal 2012)Tales of Suckage and Awesomeness (Full Frontal 2012)
Tales of Suckage and Awesomeness (Full Frontal 2012)
 
The Hotel By Helen Slater
The  Hotel   By  Helen  SlaterThe  Hotel   By  Helen  Slater
The Hotel By Helen Slater
 
Kriyathmak anusantaan
Kriyathmak anusantaan Kriyathmak anusantaan
Kriyathmak anusantaan
 
Airtel
AirtelAirtel
Airtel
 
Biserica densus (cl)
Biserica densus (cl)Biserica densus (cl)
Biserica densus (cl)
 
Hybris Biblia - Vendetta annunciata
Hybris Biblia - Vendetta annunciataHybris Biblia - Vendetta annunciata
Hybris Biblia - Vendetta annunciata
 
Un Bain De Lumiere
Un Bain De LumiereUn Bain De Lumiere
Un Bain De Lumiere
 
Ppt a13c.ppsx
Ppt a13c.ppsxPpt a13c.ppsx
Ppt a13c.ppsx
 
Heimwerker
HeimwerkerHeimwerker
Heimwerker
 
Sexy factureren Factureringscongres 2012
Sexy factureren Factureringscongres 2012Sexy factureren Factureringscongres 2012
Sexy factureren Factureringscongres 2012
 
Ce au devenit(1)
Ce au devenit(1)Ce au devenit(1)
Ce au devenit(1)
 
Asta e africa (ab)
Asta e africa (ab)Asta e africa (ab)
Asta e africa (ab)
 
Jardins
JardinsJardins
Jardins
 
Hugo Chavez Sueldos De La Bolioligraquia
Hugo Chavez   Sueldos De La BolioligraquiaHugo Chavez   Sueldos De La Bolioligraquia
Hugo Chavez Sueldos De La Bolioligraquia
 
X 47 B
X 47 BX 47 B
X 47 B
 
Worst Photoshop mistakes ever
Worst Photoshop mistakes everWorst Photoshop mistakes ever
Worst Photoshop mistakes ever
 

Similaire à Transmogrify

WordPressでIoTをはじめよう
WordPressでIoTをはじめようWordPressでIoTをはじめよう
WordPressでIoTをはじめようYuriko IKEDA
 
Dip Your Toes in the Sea of Security
Dip Your Toes in the Sea of SecurityDip Your Toes in the Sea of Security
Dip Your Toes in the Sea of SecurityJames Titcumb
 
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docxcalc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docxRAHUL126667
 
Dip Your Toes In The Sea Of Security (PHPNW16)
Dip Your Toes In The Sea Of Security (PHPNW16)Dip Your Toes In The Sea Of Security (PHPNW16)
Dip Your Toes In The Sea Of Security (PHPNW16)James Titcumb
 
Dip Your Toes in the Sea of Security (IPC Fall 2017)
Dip Your Toes in the Sea of Security (IPC Fall 2017)Dip Your Toes in the Sea of Security (IPC Fall 2017)
Dip Your Toes in the Sea of Security (IPC Fall 2017)James Titcumb
 
Dip Your Toes in the Sea of Security (CoderCruise 2017)
Dip Your Toes in the Sea of Security (CoderCruise 2017)Dip Your Toes in the Sea of Security (CoderCruise 2017)
Dip Your Toes in the Sea of Security (CoderCruise 2017)James Titcumb
 
Dip Your Toes in the Sea of Security (phpDay 2016)
Dip Your Toes in the Sea of Security (phpDay 2016)Dip Your Toes in the Sea of Security (phpDay 2016)
Dip Your Toes in the Sea of Security (phpDay 2016)James Titcumb
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...DevGAMM Conference
 
ELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboardELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboardGeorg Sorst
 
R57shell
R57shellR57shell
R57shellady36
 
Instant Dynamic Forms with #states
Instant Dynamic Forms with #statesInstant Dynamic Forms with #states
Instant Dynamic Forms with #statesKonstantin Käfer
 

Similaire à Transmogrify (20)

Esperwhispering
EsperwhisperingEsperwhispering
Esperwhispering
 
WordPressでIoTをはじめよう
WordPressでIoTをはじめようWordPressでIoTをはじめよう
WordPressでIoTをはじめよう
 
Dip Your Toes in the Sea of Security
Dip Your Toes in the Sea of SecurityDip Your Toes in the Sea of Security
Dip Your Toes in the Sea of Security
 
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docxcalc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
 
Dip Your Toes In The Sea Of Security (PHPNW16)
Dip Your Toes In The Sea Of Security (PHPNW16)Dip Your Toes In The Sea Of Security (PHPNW16)
Dip Your Toes In The Sea Of Security (PHPNW16)
 
SUMO simulation CODES AND STEPS
SUMO simulation CODES AND STEPSSUMO simulation CODES AND STEPS
SUMO simulation CODES AND STEPS
 
Dip Your Toes in the Sea of Security (IPC Fall 2017)
Dip Your Toes in the Sea of Security (IPC Fall 2017)Dip Your Toes in the Sea of Security (IPC Fall 2017)
Dip Your Toes in the Sea of Security (IPC Fall 2017)
 
Code em Poker
Code em PokerCode em Poker
Code em Poker
 
AI For Texam Hold'em poker
AI For Texam Hold'em pokerAI For Texam Hold'em poker
AI For Texam Hold'em poker
 
Php functions
Php functionsPhp functions
Php functions
 
Dip Your Toes in the Sea of Security (CoderCruise 2017)
Dip Your Toes in the Sea of Security (CoderCruise 2017)Dip Your Toes in the Sea of Security (CoderCruise 2017)
Dip Your Toes in the Sea of Security (CoderCruise 2017)
 
Drupal Mobile
Drupal MobileDrupal Mobile
Drupal Mobile
 
Pop3ck sh
Pop3ck shPop3ck sh
Pop3ck sh
 
Dip Your Toes in the Sea of Security (phpDay 2016)
Dip Your Toes in the Sea of Security (phpDay 2016)Dip Your Toes in the Sea of Security (phpDay 2016)
Dip Your Toes in the Sea of Security (phpDay 2016)
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
 
ELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboardELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboard
 
R57shell
R57shellR57shell
R57shell
 
Fbd@cfg
Fbd@cfgFbd@cfg
Fbd@cfg
 
Instant Dynamic Forms with #states
Instant Dynamic Forms with #statesInstant Dynamic Forms with #states
Instant Dynamic Forms with #states
 
Mug17 gurgaon
Mug17 gurgaonMug17 gurgaon
Mug17 gurgaon
 

Dernier

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
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
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
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
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Dernier (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
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
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
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
 
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)
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
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
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

Transmogrify

  • 1. transmogrifier A JavaScript Utility for Transforming Objects
  • 2. trans·mog·ri·fy •It’s a real word trăns-mŏg'rə-fī', trănz- tr.v, -fied, -fy·ing, -fies. To change into a different shape or form, especially one that is fantastic or bizarre. http://www.answers.com/transmogrify
  • 3. trans·mog·ri·fy •It’s a real word trăns-mŏg'rə-fī', trănz- tr.v, -fied, -fy·ing, -fies. To change into a different shape or form, especially one that is fantastic or bizarre. http://www.answers.com/transmogrify
  • 6. really, what’s it for? •To sanitize and simplify complex objects, like those returned by MLB’s services
  • 7. •Inspired by getDeepValue and setDeepValue •Implemented in $Q for transforming objects as defined in .select method
  • 9. wywinwyg what you want is not what you get
  • 10. what you need { "id": "type": "status": "venue": "teams": { "away": { "id": "name": "code": }, "home": { "id": "name": "code": } }, "pitchers": [], "apple": "banana": "yellow": }
  • 11. what you ge... { "game_id": "2009/09/24/cinmlb-pitmlb-1", "game_pk": "246475", "game_time_is_tbd": false, "game_venue": "PNC Park", "game_time": "1253810100000", "game_time_offset_eastern": "-4", "pitcher": { "loss_id": "450203", "win_id": "276520", "win": "Arroyo", "loss_stat": "4-9", "win_stat": "14-13", "save": "Cordero", "save_stat": "39", "loss": "Morton", "save_id": "150188" }, "game_location": "Pittsburgh", "home": { "file_code": "pit", "probable_stat": "5-9", "tv": null, "id": "134", "split": false, "probable_name_display_first_last": "Charlie Morton", "probable_report": "Morton showed some improved command in his last start, a sign that maybe he's beginning to figure out how to use the movement he can get on his pitches to his benefit. The consistency of his command has been the biggest problem for Morton all season, but after allowing an early run and getting out of an early jam, Morton found just that against the Padres. He matched his career high with seven innings and has now allowed three or fewer runs in four of his past five starts. Morton is 1-1 with a 6.35 ERA in two previous starts against Cincinnati.", "recap": "/news/gameday_recap.jsp?ymd=20090924&content_id=7131310&vkey=recap&fext=.jsp&c_id=pit", "full": "Pirates", "tickets": null, "radio": "WPGB-FM 104.7", "game_time_offset": "-4", "display_code": "PIT",
  • 12. ...eeeeee... "preview": "javascript:void(launchGameday({gid:'2009_09_24_cinmlb_pitmlb_1',mode:'preview',lurl:'/news/article.jsp? ymd=20090923&content_id=7109806&vkey=news_pit&fext=.jsp&c_id=pit'}))", "wrapup": "/news/wrap.jsp?ymd=20090924&content_id=7131314&vkey=wrapup2005&fext=.jsp&team=home&c_id=pit", "audio_uri": "javascript:bam.media.launchPlayer({content_id:'6765579',view_key:'MLBTV_MP_4',media_type:'audio',calendar_event_id:'14-246475-2009-09-24'})", "probable": "Morton", "probable_era": "4.55", "league": "104", "probable_id": "450203", "result": "1" }, "division_id": "205", "game_time_offset_local": "-4", "scheduledTime": null, "game_status": "F", "mlbtv": true, "is_suspension_resumption": false, "video_uri": "javascript:bam.media.launchPlayer({content_id:'6765575',view_key:'MLBTV_MP_4',media_type:'video',calendar_event_id:'14-246475-2009-09-24'})", "sport_code": "mlb", "venue_id": "31", "wrapup": "javascript:void(launchGameday({gid:'2009_09_24_cinmlb_pitmlb_1',mode:'wrap',lurl:'/news/wrap.jsp? ymd=20090924&content_id=7131314&vkey=wrapup2005&fext=.jsp&c_id=mlb'}))", "preview": null, "game_type": "R", "resumptionTime": null, "away": { "file_code": "cin", "probable_stat": "15-13", "tv": null, "id": "113", "split": false, "probable_name_display_first_last": "Bronson Arroyo", "probable_report": "Arroyo was perfect through three innings Saturday against Florida, but a couple of costly mistakes led to a loss, most notably a changeup to pinch-hitter Ross Gload that resulted in a two-run home run in the eighth, which lifted the Marlins to a 3-2 victory. Arroyo allowed three runs on six hits. He walked one and struck out six but allowed two home runs. Despite the loss, Arroyo extended his streak of consecutive quality starts to 11.", "recap": "/news/gameday_recap.jsp?ymd=20090924&content_id=7131308&vkey=recap&fext=.jsp&c_id=cin", "full": "Reds", "tickets": null,
  • 13. ...et "radio": "WLW 700", "game_time_offset": "-4", "display_code": "CIN", "preview": "javascript:void(launchGameday({gid:'2009_09_24_cinmlb_pitmlb_1',mode:'preview',lurl:'/news/article.jsp? ymd=20090923&content_id=7109796&vkey=news_cin&fext=.jsp&c_id=cin'}))", "wrapup": "/news/wrap.jsp?ymd=20090924&content_id=7131314&vkey=wrapup2005&fext=.jsp&team=away&c_id=cin", "audio_uri": "javascript:bam.media.launchPlayer({content_id:'6765579',view_key:'MLBTV_MP_4',media_type:'audio',calendar_event_id:'14-246475-2009-09-24'})", "probable": "Arroyo", "probable_era": "3.84", "league": "104", "probable_id": "276520", "result": "4" }, "game_dh": null, "game_num": "1", "fruit": [ { "name": "apple", "color": "green" }, { "name": "banana", "color": "yellow" }, { "name": "cherry", "color": "red" } ] }
  • 16. var gameTemplate = { id: 'game_id', // output.id === input.game_id type: 'game_type', // output.type === input.game_type status: 'game_status', // output.status === input.game_status venue: 'game_venue', // output.venue === input.game_venue teams: { // output.teams === {} away: { // output.teams.away === {} id: 'away.id', // output.teams.away.id === input.away.id name: 'away.full', // output.teams.away.name === input.away.full code: 'away.file_code' // output.teams.away.code === input.away.file_code }, home: { // output.teams.home === {} id: 'home.id', // output.teams.home.id === input.home.id name: 'home.full', // output.teams.home.name === input.home.full code: 'home.file_code' // output.teams.home.code === input.home.file_code } }, time: function convertGameTime (obj) { var d = new Date(+obj.game_time), e = +obj.game_time_offset_eastern, h, m, a; d.setHours(d.getUTCHours() + e); h = d.getHours(); m = d.getMinutes(); h = h % 12 || 12; m = m < 10 ? '0' + m : m; a = h < 12 ? 'am' : 'pm'; return h + ':' + m + a; // output.time === input.game_time (h:mmaa) }, pitchers: [ // output.pitchers === [] 'pitcher.win', // output.pitchers[0] === input.pitcher.win 'pitcher.loss', // output.pitchers[1] === input.pitcher.loss 'pitcher.save' // output.pitchers[2] === input.pitcher.save ], apple: 'fruit.0', // output.apple === input.fruit[0] banana: 'fruit[1]', // output.banana === input.fruit[1] yellow: 'fruit[1].color' // output.yellow === input.fruit[1].color }; var gameTransmogrifier = new Transmogrifier(gameTemplate);
  • 17.
  • 18. gameTransmogrifier.zap(gameObj); { "id": "2009/09/24/cinmlb-pitmlb-1", "type": "R", "status": "F", "venue": "PNC Park", "teams": { "away": { "id": "113", "name": "Reds", "code": "cin" }, "home": { "id": "134", "name": "Pirates", "code": "pit" } }, "time": "12:35pm", "pitchers": [ "Arroyo", "Morton", "Cordero" ], "apple": { "name": "apple", "color": "green" }, "banana": { "name": "banana", "color": "yellow" }, "yellow": "yellow" }
  • 20. .zap (objOrArr) Transforms a single object or array
  • 21. .nuke (arrOfObjs) Applies .zap to members of array