content
stringlengths
228
999k
pred_label
stringclasses
1 value
pred_score
float64
0.5
1
Question of The Day15-02-2021 A, B and C together can complete a work in 12 days. B, C, and D together can complete the same work in 15 days. C, D and A together can complete the same work in 12 days. D, A and B together can complete same work in 10 days. In how many days all of them together can complete the work? Answer Correct Answer : c ) \(9\) days Explanation : Let us assume the total work that needs to be done be (LCM of 12, 15, 12, and 10) = 180 units As, total work done = (Time taken × Efficiency of person who is doing the work) Now, depicting the given data From the above figure, Efficiency of A + B + C = 15………(1) Efficiency of A + B + C = 12……….(2) Efficiency of A + B + C = 15………..(3) Efficiency of A + B + C = 18…………(4) Now, adding equation 1, 2, 3, and 4 we get 3 (Efficiency of A + B + C + D) = 15 + 12 + 15 + 18 = 60 Efficiency of A + B + C + D = 20 units/day Thus, Time taken by A, B, C, and D together to complete the work=\(Total \ work \over Efficiency \) \(180 \over 20\)=9 days Hence, (c) is the correct answer. Such type of question is asked in various government exams like SSC CGL, SSC MTS, SSC CPO, SSC CHSL, RRB JE, RRB NTPC, RRB GROUP D, RRB OFFICER SCALE-I, IBPS PO, IBPS SO, RRB Office Assistant, IBPS Clerk, RBI Assistant, IBPS RRB OFFICER SCALE 2&3, UPSC CDS, UPSC NDA, etc. Read Daily Current Affairs, Banking Awareness, Hindi Current Affairs, Word of the Day, and attempt free mock tests at PendulumEdu and boost your preparation for the actual exam. 0 COMMENTS Comments Share QOTD
__label__pos
0.996833
1: /* 2: * Copyright (c) 1980 Regents of the University of California. 3: * All rights reserved. The Berkeley software License Agreement 4: * specifies the terms and conditions for redistribution. 5: */ 6: 7: #ifndef lint 8: static char sccsid[] = "@(#)pmon.c 5.1 (Berkeley) 6/5/85"; 9: #endif not lint 10: 11: /* 12: * pxp - Pascal execution profiler 13: * 14: * Bill Joy UCB 15: * Version 1.2 January 1979 16: */ 17: 18: #include "0.h" 19: 20: /* 21: * Profile counter processing cluster 22: * 23: * This file contains all routines which do the hard work in profiling. 24: * 25: * The first group of routines (getit, getpmon, getcore, and pmread) 26: * deal with extracting data from the pmon.out and (with more difficulty) 27: * core files. 28: * 29: * The routines cnttab and prttab collect counters for 30: * and print the summary table respectively. 31: * 32: * The routines "*cnt*" deal with manipulation of counters, 33: * especially the "current" counter px. 34: */ 35: STATIC struct pxcnt px; 36: 37: /* 38: * Table to record info 39: * for procedure/function summary 40: */ 41: STATIC struct pftab { 42: long pfcnt; 43: short pfline; 44: char *pfname; 45: short pflev; 46: } *zpf; 47: 48: /* 49: * Global variables 50: */ 51: STATIC long *zbuf; /* Count buffer */ 52: STATIC short zcnt; /* Number of counts */ 53: STATIC short zpfcnt; /* Number of proc/funcs's */ 54: STATIC short gcountr; /* Unique name generator */ 55: STATIC short zfil; /* I/o unit for count data reads */ 56: STATIC short lastpf; /* Total # of procs and funcs for consistency chk */ 57: 58: getit(fp) 59: register char *fp; 60: { 61: 62: if (core) 63: getcore(fp); 64: else 65: getpmon(fp); 66: } 67: 68: /* 69: * Setup monitor data buffer from pmon.out 70: * style file whose name is fp. 71: */ 72: getpmon(fp) 73: char *fp; 74: { 75: register char *cp; 76: short garbage; 77: 78: zfil = open(fp, 0); 79: if (zfil < 0) { 80: perror(fp); 81: pexit(NOSTART); 82: } 83: if (pmread() < 0 || read(zfil, &garbage, 1) == 1) { 84: Perror(fp, "Bad format for pmon.out style file"); 85: exit(1); 86: } 87: close(zfil); 88: return; 89: } 90: 91: STATIC char nospcm[] = "Not enough memory for count buffers\n"; 92: 93: pmnospac() 94: { 95: 96: write(2, nospcm, sizeof nospcm); 97: pexit(NOSTART); 98: } 99: 100: /* 101: * Structure of the first few 102: * items of a px core dump. 103: */ 104: STATIC struct info { 105: char *off; /* Self-reference for pure text */ 106: short type; /* 0 = non-pure text, 1 = pure text */ 107: char *bp; /* Core address of pxps struct */ 108: } inf; 109: 110: /* 111: * First few words of the px 112: * information structure. 113: */ 114: STATIC struct pxps { 115: char *buf; 116: short cnt; 117: } pxp; 118: 119: getcore(fp) 120: char *fp; 121: { 122: 123: write(2, "-c: option not supported\n", sizeof("-c: option not supported\n")); 124: pexit(ERRS); 125: /* 126: short pm; 127: 128: zfil = open(fp, 0); 129: if (zfil < 0) { 130: perror(fp); 131: pexit(NOSTART); 132: } 133: if (lseek(zfil, 02000, 0) < 0) 134: goto format; 135: if (read(zfil, &inf, sizeof inf) < 0) 136: goto format; 137: if (inf.type != 0 && inf.type != 1) 138: goto format; 139: if (inf.type) 140: inf.bp =- inf.off; 141: if (lseek(zfil, inf.bp + 02000, 0) < 0) 142: goto format; 143: if (read(zfil, &pxp, sizeof pxp) != sizeof pxp) 144: goto format; 145: if (pxp.buf == NIL) { 146: Perror(fp, "No profile data in file"); 147: exit(1); 148: } 149: if (inf.type) 150: pxp.buf =- inf.off; 151: if (lseek(zfil, pxp.buf + 02000, 0) < 0) 152: goto format; 153: if (pmread() < 0) 154: goto format; 155: close(zfil); 156: return; 157: format: 158: Perror(fp, "Not a Pascal system core file"); 159: exit(1); 160: */ 161: } 162: 163: pmread() 164: { 165: register i; 166: register char *cp; 167: struct { 168: long no; 169: long tim; 170: long cntrs; 171: long rtns; 172: } zmagic; 173: 174: if (read(zfil, &zmagic, sizeof zmagic) != sizeof zmagic) 175: return (-1); 176: if (zmagic.no != 0426) 177: return (-1); 178: ptvec = zmagic.tim; 179: zcnt = zmagic.cntrs; 180: zpfcnt = zmagic.rtns; 181: cp = zbuf = pcalloc(i = (zcnt + 1) * sizeof *zbuf, 1); 182: if (cp == -1) 183: pmnospac(); 184: cp = zpf = pcalloc(zpfcnt * sizeof *zpf, 1); 185: if (cp == -1) 186: pmnospac(); 187: i -= sizeof(zmagic); 188: if (read(zfil, zbuf + (sizeof(zmagic) / sizeof(*zbuf)), i) != i) 189: return (-1); 190: zbuf++; 191: return (0); 192: } 193: 194: cnttab(s, no) 195: char *s; 196: short no; 197: { 198: register struct pftab *pp; 199: 200: lastpf++; 201: if (table == 0) 202: return; 203: if (no == zpfcnt) 204: cPANIC(); 205: pp = &zpf[no]; 206: pp->pfname = s; 207: pp->pfline = line; 208: pp->pfcnt = nowcnt(); 209: pp->pflev = cbn; 210: } 211: 212: prttab() 213: { 214: register i, j; 215: register struct pftab *zpfp; 216: 217: if (profile == 0 && table == 0) 218: return; 219: if (cnts != zcnt || lastpf != zpfcnt) 220: cPANIC(); 221: if (table == 0) 222: return; 223: if (profile) 224: printf("\f\n"); 225: header(); 226: printf("\n\tLine\t Count\n\n"); 227: zpfp = zpf; 228: for (i = 0; i < zpfcnt; i++) { 229: printf("\t%4d\t%8ld\t", zpfp->pfline, zpfp->pfcnt); 230: if (!justify) 231: for (j = zpfp->pflev * unit; j > 1; j--) 232: putchar(' '); 233: printf("%s\n", zpfp->pfname); 234: zpfp++; 235: } 236: } 237: 238: nowcntr() 239: { 240: 241: return (px.counter); 242: } 243: 244: long nowcnt() 245: { 246: 247: return (px.ntimes); 248: } 249: 250: long cntof(pxc) 251: struct pxcnt *pxc; 252: { 253: 254: if (profile == 0 && table == 0) 255: return; 256: return (pxc->ntimes); 257: } 258: 259: setcnt(l) 260: long l; 261: { 262: 263: if (profile == 0 && table == 0) 264: return; 265: px.counter = --gcountr; 266: px.ntimes = l; 267: px.gos = gocnt; 268: px.printed = 0; 269: } 270: 271: savecnt(pxc) 272: register struct pxcnt *pxc; 273: { 274: 275: if (profile == 0 && table == 0) 276: return; 277: pxc->ntimes = px.ntimes; 278: pxc->counter = px.counter; 279: pxc->gos = px.gos; 280: pxc->printed = 1; 281: } 282: 283: rescnt(pxc) 284: register struct pxcnt *pxc; 285: { 286: 287: if (profile == 0 && table == 0) 288: return; 289: px.ntimes = pxc->ntimes; 290: px.counter = pxc->counter; 291: px.gos = gocnt; 292: px.printed = pxc->printed; 293: return (gocnt != pxc->gos); 294: } 295: 296: getcnt() 297: { 298: 299: if (profile == 0 && table == 0) 300: return; 301: if (cnts == zcnt) 302: cPANIC(); 303: px.counter = cnts; 304: px.ntimes = zbuf[cnts]; 305: px.gos = gocnt; 306: px.printed = 0; 307: ++cnts; 308: } 309: 310: unprint() 311: { 312: 313: px.printed = 0; 314: } 315: 316: /* 317: * Control printing of '|' 318: * when profiling. 319: */ 320: STATIC char nobar; 321: 322: baroff() 323: { 324: 325: nobar = 1; 326: } 327: 328: baron() 329: { 330: 331: nobar = 0; 332: } 333: 334: /* 335: * Do we want cnt and/or '|' on this line ? 336: * 1 = count and '|' 337: * 0 = only '|' 338: * -1 = spaces only 339: */ 340: shudpcnt() 341: { 342: 343: register i; 344: 345: if (nobar) 346: return (-1); 347: i = px.printed; 348: px.printed = 1; 349: return (i == 0); 350: } 351: 352: STATIC char mism[] = "Program and counter data do not correspond\n"; 353: 354: cPANIC() 355: { 356: 357: printf("cnts %d zcnt %d, lastpf %d zpfcnt %d\n", 358: cnts, zcnt, lastpf, zpfcnt); 359: flush(); 360: write(2, mism, sizeof mism); 361: pexit(ERRS); 362: } Defined functions baroff defined in line 322; used 4 times baron defined in line 328; used 5 times cPANIC defined in line 354; used 3 times cntof defined in line 250; used 2 times cnttab defined in line 194; used 1 times getcore defined in line 119; used 1 times • in line 63 getit defined in line 58; used 2 times getpmon defined in line 72; used 1 times • in line 65 nowcnt defined in line 244; used 5 times nowcntr defined in line 238; never used pmnospac defined in line 93; used 2 times pmread defined in line 163; used 1 times • in line 83 prttab defined in line 212; used 1 times setcnt defined in line 259; used 1 times shudpcnt defined in line 340; used 1 times unprint defined in line 310; used 3 times Defined variables gcountr defined in line 54; used 1 times inf defined in line 108; never used lastpf defined in line 56; used 3 times mism defined in line 352; used 2 times • in line 360(2) nobar defined in line 320; used 3 times nospcm defined in line 91; used 2 times • in line 96(2) px defined in line 35; used 20 times pxp defined in line 117; never used sccsid defined in line 8; never used zbuf defined in line 51; used 6 times zcnt defined in line 52; used 5 times zfil defined in line 55; used 6 times zpf defined in line 46; used 4 times zpfcnt defined in line 53; used 6 times Defined struct's info defined in line 104; never used pftab defined in line 41; used 4 times pxps defined in line 114; never used Last modified: 1985-06-06 Generated: 2016-12-26 Generated by src2html V0.67 page hit count: 1715 Valid CSS Valid XHTML 1.0 Strict
__label__pos
0.999174
Importacular User Guide ⌘K 1. Home 2. Docs 3. Importacular User Guide 4. Tips for A Good Import Tips for A Good Import Whether you’re new to importing in general or just new to Importacular, here are a few things we hope that you’ll do to make the most of this powerful tool. Did you map all of your required fields? For example, if you require a Constituent Code for every Constituent record, make sure you’ve added one to your template (if you have an optional destination that also creates Constituents, you may need more than one – see this Knowledgebase article for more information). Field Settings See this section of our User Guide for more information about Field Settings. 1. Do you want to update values for Existing Constituents?  Sometimes you will, but others you may not (ie – if you already have a Primary Addressee/Salutation assigned, do you want what is in your template to override that?). 2. Do you need to fix the casing (Proper case, all caps, etc.) for any fields? 3. Do you need to dynamically transform data so it better lines up with your Raiser’s Edge standards? Data Transformations can do that for you. Area Settings Area settings differ in function for each mapping area, but to see the difference between them and Field Settings, please see this knowledgebase article.  For a few examples of this, see these Areas: 1. Address Area Settings – Does this Address match one that is already in the Raiser’s Edge?  If so, what do you want to happen (create a duplicate, update the Raiser’s Edge, ignore the new information, etc.)? If it’s a new address and the existing constituent already has a preferred address, do you want to save a copy of the previous address? 2. Phone/Email Area Settings – Does this Phone/Email address match what is already in the Raiser’s Edge? Do you need to set up a hierarchy of phone types so that you don’t have two of the same type on a constituent record? Check Your Review Screen See this section of the User Guide to walk through the Review Screen. 1. Look over the different tabs and make sure the data looks correct. 2. Do the records set to update seem to be matched as you need them to be? Validate Before Importing! If you have any exceptions, review your Control Report.  If you need help determining what an Exception means, start by searching our Knowledgebase. Test your import on a small sample of your records See this knowledgebase article to learn how. Thoroughly review the record to see what changes were made and to ensure that things were imported correctly. Create a Static query of all new and updated constituents.   Should you make a mistake, this will help you find the records easily.
__label__pos
0.961766
Uploaded image for project: 'Moodle' 1. Moodle 2. MDL-29723 Black text appears on dark blue background and is hard to read XMLWordPrintable Details • Type: Bug • Status: Closed • Priority: Minor • Resolution: Fixed • Affects Version/s: 2.1.2 • Fix Version/s: 2.3.5, 2.4.2 • Component/s: Themes • Labels: • Environment: Ubuntu 10.04 • Testing Instructions: Hide 1. Select Standard theme from Theme selector. 2. In a course create a quiz. 3. Create a question and TEST that the Question Box Window has white text against a dark blue background. 4. With the page still open TEST all themes. Start off by adding &theme=afterburner at the end of the page URL, changing the theme name for each theme in Moodle core. Full list: afterburner, anomaly, arialist, base, binarius, boxxie, brick, canvas, formfactor, fusion, leatherbound, magazine, nimble, nonzero, overlay, serenity, sky_high, splash, standardold Please Note: to see both Base & Canvas themes you need Theme Designer Mode enabled. (under settings: Theme settings) Show Select Standard theme from Theme selector. In a course create a quiz. Create a question and TEST that the Question Box Window has white text against a dark blue background. With the page still open TEST all themes. Start off by adding &theme=afterburner at the end of the page URL, changing the theme name for each theme in Moodle core. Full list: afterburner, anomaly, arialist, base, binarius, boxxie, brick, canvas, formfactor, fusion, leatherbound, magazine, nimble, nonzero, overlay, serenity, sky_high, splash, standardold Please Note: to see both Base & Canvas themes you need Theme Designer Mode enabled. (under settings: Theme settings) • Affected Branches: MOODLE_21_STABLE • Fixed Branches: MOODLE_23_STABLE, MOODLE_24_STABLE • Pull Master Branch: wip-MDL-29723_master Description After creating a question on a quiz, a text box containing "Question bank contents" appears on the top right. It is impossible to read unless you select the text. It may be the quiz component or it could be the whole theme I was using at the time (Leatherbound). Attachments 1. MDL-29723.jpg 44 kB Mary Evans 2. Screenshot_30_01_13_12_03_PM.png 179 kB Jérôme Mouneyrac 3. Screenshot_30_01_13_12_20_PM.png 162 kB Jérôme Mouneyrac 4. Screenshot-Editing quiz - Mozilla Firefox.png 111 kB Jason Fowler Issue Links Activity People Assignee: lazydaisy Mary Evans Reporter: phalacee Jason Fowler Peer reviewer: Tim Hunt Integrator: Sam Hemelryk Tester: Jérôme Mouneyrac Participants: Component watchers: Bas Brands Votes: 0 Vote for this issue Watchers: 4 Start watching this issue Dates Created: Updated: Resolved: Fix Release Date: 11/Mar/13
__label__pos
0.959347
Home > Python Try > Python Int Cast Error Python Int Cast Error Contents In Python2 the syntax for this is: >>> try: ... Reply Nakul 18 May 2006 Hi,I m trying to save the values from the array to the text file in Python. Why do jet engines smoke? The unicode_escape encoding will convert all the various ways of entering unicode characters. http://caribtechsxm.com/python-try/python-error.php Reply Link Security: Are you a robot or human? except (ZeroDivisionError, TypeError): ... It is useful for code that must be executed if the try clause does not raise an exception. If you are interested in an instructor-led classroom training in Canada or the US, you may have a look at the Python courses by Bernd Klein at Bodenseo © kabliczech - Python Valueerror Converting decimal list into float for list items Similarly, you may use the float instead of int for converting a list containing decimal number strings. Exceptions come in different types, and the type is printed as part of the message: the types in the example are ZeroDivisionError, NameError and TypeError. However, it is even easier to use the print_() function from the six module that I will present at the end of this chapter. 1. a = 1/'0' ... 2. Interesting. 3. One other solution is to replace comma by nothing i.e. " and then use the int, as shown in the example below: See online demo and code The code: str_a = 4. this_fails() ... 5. In Python2 any number starting with a 0 is an octal, which can be confusing if you decide to format your numbers by starting them with zeros. 6. Especially if you can drop support for Python2.5 and earlier, since Python2.6 introduces quite a lot of forwards compatibility. 7. Table Of Contents 8. 8. We need to fix up the code to import the names we use directly instead of the modules they are located in, so the version that runs under both Python2 and Defining Clean-up Actions¶ The class="pre">try statement has another optional clause which is intended to define clean-up actions that must be executed under all circumstances. Many of the changes you need will be done by 2to3, so to start converting your code you actually want to first run 2to3 on your code and make your code Last updated on Sep 30, 2016. Python Catch Multiple Exceptions share|improve this answer answered Mar 24 '10 at 15:22 mojbro 1,084912 I guess I was hoping that something like this was available natively. Python2's trailing comma has in Python3 become a parameter, so if you use trailing commas to avoid the newline after a print, this will in Python3 look like print('Text to print', Python Custom Exception except ValueError as ex: ... See the following example for demonstration: See online demo and code The code of using float for converting a string: #A demo of string to float str_a = '50.85' b = So make sure that you call it properly: Let's assume that you saved this program as "exception_test.py". The bug I found was related to a human height input validator that looked something like this: def validHeight(cm): try: cm = int(cm) return 100 <= cm <= 250 except ValueError: Python Cast Float To Int A simple example to demonstrate the finally clause: try: x = float(raw_input("Your number: ")) inverse = 1.0 / x finally: print("There may or may not have been an exception.") print "The Is it a Good UX to keep both star and smiley rating system as filters? Can anyone identify the city in this photo? Python Custom Exception string = "abcd" try: i = int(string) print i except ValueError: #Handle the exception print 'Please enter an integer' Try/Excepts are powerful because if something can fail in a number of x = 1/0 ... >>> try: ... Python Valueerror The raised error, in our case a ValueError, has to match one of the names after except. Python Try Except Else The __future__ import only works under Python2.6 and later, so for Python2.5 and earlier you have two options. When creating a module that can raise several distinct errors, a common practice is to create a base class for exceptions defined by that module, and subclass that to create specific my review here print('x =', x) ... an exception is only raised, if a certain condition is not True. Thanks! Python Try Without Except The class="pre">try statement works as follows. The real question (no pun intended) is why you are storing them in the database as floating point numbers when you are validating them as integers. print('Handling run-time error:', err) ... click site What is this no-failure, no-exception thing you're expecting? Please donate. Python Pass print(inst.args) # arguments stored in .args ... The trick is to use sys.stdout.write() and formatting according to the parameters passed in to the function. raise NameError('HiThere') ... except TypeError as e: ... Exception handlers don't just handle exceptions if they occur immediately in the try clause, but also if they occur inside functions that are called (even indirectly) in the try clause. Input and Output Next topic 9. Python Exit Then if its type matches the exception named after the except keyword, the except clause is executed, and then execution continues after the try statement. x, y = inst.args # unpack args ... A more complicated example: >>> def divide(x, y): ... If you don't know well the programming languages you're using, learn them -- there's nothing "contingent" about the behavior of int, which hasn't changed in 10 years or more! –Alex Martelli http://caribtechsxm.com/python-try/python-except-any-error-as-e.php import httplib as http.client is a syntax error. Use this with extreme caution, since it is easy to mask a real programming error in this way! The Python Software Foundation is a non-profit corporation. File name and line number are printed so you know where to look in case the input came from a script. 8.2. Defaults to ‘unsafe' for backwards compatibility. ‘no' means the data types should not be cast at all. ‘equiv' means only byte-order changes are allowed. ‘safe' means only casts which can preserve They are nothing of the sort. binary_type = str ... try: ... Doesn't make him a woman. for m in e.args: ...
__label__pos
0.913174
Nginx常见配置 1. 介绍目录访问权限        一般,我们对需要对目录是否有访问权限做限制。比如a目录下禁止访问 1.1 配置 location /a { allow 192.168.1.0/24; deny all; #return 404; return http://www.jd.com; } 2. 认证登录 location /b { auth_basic "请输入账号和密码"; auth_basic_user_file /etc/nginx/htpasswd; } 3. 反向代理 location / { index index.php index.html index.htm; # 定义⾸⻚索引⽂件的名称 proxy_pass http://mysvr; # 请求转向mysvr 定义的服务器列表 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; # 允许客户端请求的最⼤单⽂件字节数 client_body_buffer_size 128k; # 缓冲区代理缓冲⽤户端请求的最⼤字节数, proxy_connect_timeout 90; # nginx跟后端服务器连接超时时间(代理连接超时) proxy_send_timeout 90; # 后端服务器数据回传时间(代理发送超时) proxy_read_timeout 90; # 连接成功后,后端服务器响应时间(代理接收超时) proxy_buffer_size 4k; # 设置代理服务器(nginx)保存⽤户头信息的缓冲区⼤⼩ proxy_buffers 4 32k; # proxy_buffers缓冲区,⽹⻚平均在32k以下的话,这样设置 proxy_busy_buffers_size 64k; # ⾼负荷下缓冲⼤⼩(proxy_buffers*2) proxy_temp_file_write_size 64k; # 设定缓存⽂件夹⼤⼩,⼤于这个值,将从upstream服务器传 4. 限速        限速该特性可以限制某个⽤户在⼀个给定时间段内能够产⽣的HTTP请求数。请求可以简单到就是⼀个对于主⻚的GET请求或者⼀个登陆表格的POST请求。        限速也可以⽤于安全⽬的上,⽐如暴⼒密码破解攻击。通过限制进来的请求速率,并且(结合⽇志)标记出⽬标URLs来帮助防范DDoS攻击。⼀般地说,限流是⽤在 保护上游应⽤服务器不被在同⼀时刻的⼤量⽤户请求湮没。 应用常见 • DDOS防御 • 下载场景保护IO Nginx官⽅版本限制IP的连接和并发分别有两个模块: limit_req_zone ⽤来限制单位时间内的请求数,即速率限制 Syntax: limit_req zone=name [burst=number] [nodelay]; Default: — Context: http, server, locati limit_req_conn ⽤来限制同⼀时间连接数,即并发限 4.1 案例1 基于IP对下载速率做限制 限制每秒处理1次请求,对突发超过5个以后的请求放⼊缓存区 http { limit_req_zone $binary_remote_addr zone=baism:10m rate=1r/s; server { location /search/ { limit_req zone=baism burst=5 nodelay; } 参数设置 limit_req_zone $binary_remote_addr zone=baism:10m rate=1r/s; 个参数:$binary_remote_addr 表示通过remote_addr这个标识来做限制,“binary_的是缩写内存占是限制同客户端ip地址 个参数zone=baism:10m表示⼤⼩为10M名字为one的内存区域,⽤来存储访问的频次信息 第三个参数rate=1r/s表示允许相同标识的客户端的访问频次限制的是每秒1次还可以有如30r/m的limit_req zone=baism burst=5 nodelay; 个参数zone=baism 设置使哪个配置区域来做限制与上limit_req_zone 的name对应 个参数burst=5重点说明下这个配置burst爆发的意思这个配置的意思是设置⼤⼩为5的缓冲区当有量请求爆发过来时超过了访问频次限制的请 求可以先放到这个缓冲区内 第三个参数nodelay如果设置超过访问频次且缓冲区也满了的时候就会直接返回503如果没有设置则所有请求会等待排 4.2 案例2 基于IP做连接限制 限制同⼀IP并发为1 下载速度为100K limit_conn_zone $binary_remote_addr zone=addr:10m; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /abc { limit_conn addr 1; limit_rate 100k; } } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; # 基于IP做连接限制 限制同⼀IP并发为1 下载速度为100K limit_conn_zone $binary_remote_addr zone=addr:10m; # 基于IP对下载速率做限制 限制每秒处理1次请求,对突发超过5个以后的请求放⼊缓存区 limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /abc { limit_req zone=one burst=5 nodelay; limit_conn addr 1; limit_rate 100k; } } 5. URL 重写 rewrite模块(ngx_http_rewrite_module)        Rewrite功功能是Nginx服务器提供的⼀个重要功能。⼏乎是所有的web产品必备技能,⽤于实现URL重写。URL重写是⾮常有⽤的功能,⽐如它可以在 我们在改变⽹站结构后,不需要客户端修改原来的书签,也不需要其他⽹站修改对我们⽹站的友情链接,还可以在⼀定程度上提⾼⽹站的安全性,能够 让我们的⽹站显得更专业。        Nginx服务器Rewrite功能的实现是依赖于PCRE(Perl Compatible Regular Expression。Perl兼容的正则表达式)的⽀持,所以在编译安装Nginx之前, 需要安装PCRE 应用场景 • 域名变更 (京东) • ⽤户跳转 (从某个连接跳到另⼀个连接) • 伪静态场景 (便于CDN缓存动态⻚⾯数 URL rewrite 语法 rewrite <regex> <replacement> [flag]; 关键字 正则 替代内容 flag标记 flag: last # 本条规则匹配完成后,继续向下匹配新的location URI规则 break # 本条规则匹配完成即终⽌,不再匹配后⾯的任何规则 redirect # 返回302临时重定向,浏览器地址会显示跳转后的URL地址 permanent # 返回301永久重定向,浏览器地址栏会显示跳转后的URL地址 set指令 ⾃定义变量 Syntax: set $variable value; Default: — Context: server, location, 1) set 设置变量 2) if 负责语句中的判断 3) return 返回返回值或URL 4) break 终⽌后续的rewrite规则 5) rewrite 重定向U 5.1 案例1 将http://www.caimengzhi.com 重写为 http://www.caimengzhi.com/blog location / { set $name blog; rewrite ^(.*)$ http://www.caimengzhi.com/$name; } 5.2 案例2 if 指令 负责判断 Syntax: if (condition) { ... } Default: —Context: server, location location / { root html; index index.html index.htm; if ($http_user_agent ~* 'Chrome') { return 403; #return http://www.jd.com; } 5.3 案例3 return 指令 定义返回数据 Syntax: return code [text]; return code URL; return URL; Default: —Context: server, location, if location / { root html; index index.html index.htm; if ($http_user_agent ~* 'Chrome') { return 403; #return http://www.jd.com; } 5.4 案例4 break 指令 停⽌执⾏当前虚拟主机的后续rewrite指令集 Syntax: break; Default:— Context:server, location, if location / { root html; index index.html index.htm; if ($http_user_agent ~* 'Chrome') { break; return 403; } 5.5 案例5 域名跳转 www.caimengzhi.com 重写为 www.jd.com server { listen 80; server_name www.caimengzhi.com; location / { rewrite ^/$ http://www.jd.com permanent; } 注意 注意: 重定向就是将⽹⻚⾃动转向重定向 301永久性重定向址完全继承旧址的排名等完全清零 301重定向是⽹⻚更改地址后对搜索引擎友好的最好只要不是暂时搬移的情况都建议使301来做转址 302临时性重定向对旧址没有影响但新址不会有排名 搜索引擎会抓取新的内容保留旧的 break,本条规则匹配完成即终⽌,不再匹配后⾯的任何规则,类似临时重定向,返回客户端3 5.6 案例6 根据⽤户浏览器重写访问⽬录,如果是chrome浏览器 就将 http://192.168.1.30/URI 重写为 http://192.168.1.30/chrome/UR location / { ..... if ($http_user_agent ~* 'chrome') { rewrite ^(.*)$ /chrome/$1 last; } location /chrome { root html ; index index.html; } 解释 ^ 以什么开头 ^a $ 以什么结尾 c$ . 除了回以外的任意个字符 * 的字符可以出现多次或者不出现 更多内容看正则表达式 re
__label__pos
0.975862
Omegle vs OmeTV The Tech Battle for Chat Supremacy Omegle vs. OmeTV: The Tech Battle for Chat Supremacy Omegle and OmeTV are both popular online chatting platforms that allow users to connect with anonymous strangers from around the world. While they may appear similar at first glance, there are some notable differences that make each platform unique. In this article, we will compare Omegle and OmeTV to determine which one reigns supreme in the tech battle for chat dominance. One of the key distinctions between Omegle and OmeTV is the user interface. Omegle has a simple and straightforward design, with a clean layout that makes it easy to navigate. On the other hand, OmeTV offers a more modern and visually appealing interface, with vibrant colors and engaging graphics. The choice between the two comes down to personal preference, as some users may prefer a more minimalistic approach while others may enjoy a more visually stimulating experience. Another important factor to consider is the user base and community on each platform. Omegle has been around for longer and has a larger user base, which means you are more likely to find people online at any given time. This can be a significant advantage, especially for those who want to chat with strangers at odd hours. OmeTV, while not as well-established, still boasts a substantial user base and offers a diverse range of people to connect with. It ultimately depends on whether you prefer quantity or diversity when it comes to potential chat partners. One aspect where Omegle has an edge over OmeTV is the anonymity it offers. Omegle allows users to chat without sharing any personal information, giving them complete control over their privacy. This can be particularly appealing for individuals who prefer to keep their identity unknown while chatting. OmeTV, on the other hand, requires users to create an account before accessing the platform. While this may deter some users who value anonymity, it also helps in maintaining a safer and more regulated chat environment. Both platforms provide features such as text chat, video chat, and filters to help users find like-minded individuals. However, Omegle has a reputation for having a higher number of trolls and inappropriate content due to its larger user base. OmeTV has implemented stricter regulations and moderation to overcome this issue, making it a safer option for those who want to avoid explicit or offensive content. In conclusion, while Omegle and OmeTV both offer unique experiences for online chatting, it ultimately comes down to personal preference. Omegle’s larger user base and complete anonymity may appeal to those who value quantity and privacy, while OmeTV’s modern interface and safer environment may be preferred by individuals seeking a more regulated chatting experience. Whether you choose Omegle or OmeTV, both platforms provide ample opportunities to connect with strangers from all over the world and engage in interesting conversations. Omegle vs. OmeTV: A Comparison of the Most Popular Chat Platforms In today’s digital age, the popularity of chat platforms has skyrocketed. People all over the world are using these platforms to connect with new individuals and engage in interesting conversations. Two of the most well-known chat platforms are Omegle and OmeTV. In this article, we will compare these platforms and highlight their key features, allowing you to make an informed decision on which one suits your needs best. Omegle: Where Randomness Prevails Omegle is a pioneer in the world of anonymous chat platforms. Launched in 2009, it gained immense popularity due to its unique premise – connecting users with random strangers. Upon entering the website, you are instantly paired with someone from anywhere in the world. This randomness adds an element of excitement, as you never know who you will be connected with. One of Omegle’s distinct features is its simplicity. The platform enables users to engage in text-based conversations or video chats without any registration or sign-up process. This hassle-free approach attracts individuals looking for instant connections without any strings attached. However, this lack of authentication may lead to encounters with inappropriate behavior or spam, which is an important factor to consider. OmeTV: A Safe and Moderated Chat Environment OmeTV, on the other hand, offers a more secure and moderated chat environment. Developed as a response to the challenges faced by platforms like Omegle, OmeTV ensures users’ safety with its strict community guidelines and active moderation. By leveraging a reporting system, users can flag any inappropriate behavior they encounter, resulting in a higher level of user protection. One of the standout features of OmeTV is its user-friendly interface. The platform provides an easily navigable layout, enabling users to filter chat partners based on their preferences, such as location or gender. This personalized approach enhances the user experience, allowing for more meaningful connections. Key Differences and Similarities 1. Authentication: Omegle does not require any authentication, whereas OmeTV encourages users to sign up with their Google or Facebook accounts for added security. 2. Moderation: OmeTV has a strict moderation system in place, while Omegle relies on user reports to handle inappropriate behavior. 3. Features: Both platforms offer text and video chats, but OmeTV provides additional filters for personalized matching. 4. Popularity: Omegle has a larger user base, attracting a wider range of individuals, while OmeTV boasts a more curated community due to its moderation efforts. In conclusion, Omegle and OmeTV both offer unique experiences in the realm of chat platforms. If you seek random encounters and enjoy the thrill of the unknown, Omegle might be a better fit for you. However, if you prioritize safety and personalized matching, OmeTV is the way to go. Ultimately, the choice between these platforms depends on your preferences and what you hope to gain from your online chat experiences. So, go ahead and explore the exciting world of online conversations! Discovering the Features and User Experience of Omegle and OmeTV Have you ever wondered what it’s like to chat with strangers from all around the world, without revealing your true identity? If so, then you will be intrigued by the features and user experience offered by two popular platforms: Omegle and OmeTV. Both platforms provide users with the opportunity to connect with random individuals through video and text chat. In this article, we will delve into the details of these platforms and explore their unique features. Connecting with Others: Omegle Omegle is one of the pioneering platforms in the world of anonymous online chatting. With its simple interface, users can engage in conversations with strangers effortlessly. Upon entering the platform, you are matched with a random user, and you can choose to have either a text or video chat. One of the standout features of Omegle is its anonymity. You can initiate a conversation without disclosing any personal information, providing a sense of security and privacy. Furthermore, Omegle offers various chat options to cater to different preferences. Are you interested in discussing a particular topic? Omegle allows you to join topic-based chat rooms, where you can connect with individuals who share your interests. Additionally, you can specify your preferred language, ensuring that language barriers do not hinder your communication. Omegle also incorporates a “Spy Mode” feature, which allows you to observe an ongoing conversation between two other users. This unique feature enables you to gain insights into the interactions of others, making the platform more engaging and entertaining. Enhancing User Experience: OmeTV Similar to Omegle, OmeTV aims to provide users with an exciting and anonymous chatting experience. However, it sets itself apart through its innovative features designed to enhance user interaction and engagement. OmeTV offers a user-friendly interface, ensuring that individuals of all technological backgrounds can navigate the platform effortlessly. One of the most notable features of OmeTV is its advanced filtering system. Users can specify their preferences for gender, location, and interests, allowing them to narrow down their options and connect with individuals who align with their preferences. This feature helps create more meaningful and enjoyable conversations, as users can engage with like-minded individuals. In addition, OmeTV incorporates a “Fast Connection” feature, enabling users to seamlessly connect with new people with just a single click. The platform ensures minimal downtime between conversations, maximizing user satisfaction and saving time. Conclusion Omegle and OmeTV offer unique and thrilling experiences for individuals seeking to connect with strangers online. Whether you prefer the simplicity of Omegle or the advanced features of OmeTV, both platforms provide anonymous communication channels that cater to a diverse range of interests. So, why not dive into the world of anonymous online chatting and explore what these platforms have to offer? 1. Gain the excitement of meeting people from different cultures and backgrounds. 2. Experience the thrill of anonymity, without disclosing personal information. 3. Engage in intriguing conversations with like-minded individuals. 4. Explore various chat options to suit your preferences. 5. Maximize your satisfaction with minimal downtime between conversations. Which Chat Platform Reigns Supreme: Omegle or OmeTV? In the age of virtual communication, chat platforms have become an integral part of our daily lives. With countless options available, it can be challenging to determine which one is the best fit for your needs. Two popular chat platforms that have gained significant attention are Omegle and OmeTV. In this article, we will compare and analyze both platforms to help you make an informed decision. Introduction to Omegle and OmeTV Omegle and OmeTV are anonymous chat platforms that allow users to connect with random individuals from around the world. Both platforms offer various features such as text and video chat, making the virtual communication experience more exciting. While Omegle has been around since 2009, OmeTV is a relatively newer player in the market. Unique Features and User Experience When it comes to unique features and user experience, Omegle and OmeTV offer different approaches. Omegle focuses on complete anonymity, allowing users to chat without revealing their identity. On the other hand, OmeTV promotes a safer environment by requiring users to sign up with a social media account, ensuring a level of accountability. Furthermore, Omegle offers both text and video chat options, while OmeTV mainly focuses on video chat. This difference means that Omegle users have the flexibility to communicate via text if they prefer not to show their faces. Privacy and Safety Measures Privacy and safety are crucial considerations when using any online platform. Omegle’s anonymous nature can present some risks, as users may encounter inappropriate content or individuals with malicious intentions. However, Omegle does offer a report and block feature to ensure user safety to some extent. OmeTV, with its requirement for social media sign-up, provides an added layer of security. By connecting profiles to real identities, OmeTV aims to create a safer and more accountable community. Additionally, OmeTV has built-in moderation tools to detect and prevent any malicious activities. Community and User Base Both Omegle and OmeTV boast a large user base, attracting millions of users worldwide. However, Omegle, being the older platform, has a more extensive user base and has established itself as a go-to destination for anonymous chatting. This larger community size provides users with a wider variety of individuals to connect with. On the other side, OmeTV’s smaller user base creates a more close-knit community, which can result in a more personalized experience. Users on OmeTV often report building long-lasting friendships and connections due to the smaller, tighter-knit community. Conclusion Ultimately, the choice between Omegle and OmeTV depends on your personal preferences and priorities. If complete anonymity and a vast user base are your key considerations, Omegle might be the better choice. However, if safety and a smaller, more personal community are more important to you, then OmeTV could be the ideal chat platform for you. Remember to exercise caution and moderation when engaging in any online chat platforms to ensure a positive and secure experience. Happy chatting! Comparison of Omegle and OmeTV Omegle OmeTV Privacy Complete anonymity Requires social media sign-up User Experience Text and video chat options Mainly focused on video chat Community Size Extensive user base Smaller, close-knit community Safety Measures Report and block feature Built-in moderation tools How to have a fun and safe experience with Omegle video chat alternatives: : omegal Choosing Between Omegle and OmeTV: Pros and Cons In today’s digital era, socializing with people from all around the world is just a click away. Omegle and OmeTV are two popular platforms that enable users to connect with strangers through video chat. But which one is the better choice? In this article, we will discuss the pros and cons of both Omegle and OmeTV, helping you make an informed decision. Omegle: An Overview Omegle, founded in 2009, gained immense popularity for its anonymous chat feature. With Omegle, users can engage in text or video chats with random individuals without revealing their identity. This anonymity has attracted millions of users worldwide, making it one of the most widely used platforms for meeting new people. The Pros of Omegle • A Variety of Users: Omegle’s popularity ensures a large user base, increasing your chances of finding interesting and diverse individuals to connect with. • Anonymity: Omegle allows users to chat without disclosing personal information, providing a sense of security and privacy. • Easy to Use: Omegle’s user-friendly interface makes it simple for both beginners and experienced users to navigate the platform. The Cons of Omegle • Lack of Moderation: Due to its anonymous nature, Omegle has limited control over user behavior. This can result in encounters with inappropriate or offensive content. • Unfiltered Content: The platform lacks a robust filtering system, exposing users to potentially harmful or explicit material. • Limited Features: Omegle offers basic functionality, which may not meet the expectations of users seeking advanced features or options. OmeTV: An Overview OmeTV is another popular platform that provides video chat services to connect with strangers worldwide. Launched in 2015, OmeTV offers a range of features that aim to enhance the user experience and provide a safe environment for socializing. The Pros of OmeTV • Safe Environment: OmeTV incorporates a comprehensive moderation system, ensuring a pleasant and secure experience for its users. • Gender and Location Filters: OmeTV allows users to filter their chat partners based on gender and location, increasing the chances of finding a suitable match. • Innovative Features: OmeTV offers various features like chat history, virtual gifts, and customizable profiles, adding excitement and personalization to the user experience. The Cons of OmeTV • Smaller User Base: Compared to Omegle, OmeTV has a smaller user base, potentially reducing the pool of individuals available for conversation. • Registration Required: Unlike Omegle’s anonymous approach, OmeTV requires users to create an account, which may deter individuals seeking quick and easy connections. • Connection Issues: Some users have reported occasional technical difficulties, such as connection drops or lags during video chats. Ultimately, the choice between Omegle and OmeTV depends on your personal preferences and priorities. If anonymity and a large user base are crucial to you, Omegle might be the better option. On the other hand, if safety and innovative features are your main concerns, OmeTV could be the platform that suits you best. Whichever platform you choose, ensure to prioritize your safety and remain cautious when interacting with strangers online. So, what are you waiting for? Start exploring the world of online socializing and embrace the possibilities these platforms offer! Whether you choose Omegle or OmeTV, remember to have fun and make meaningful connections. The Future of Online Chatting: Omegle and OmeTV’s Battle for Dominance Online chatting has revolutionized the way we connect with people from all around the globe. It has opened up endless possibilities for making new friends, expanding our social circle, and even finding love. One of the pioneers in this space was Omegle, a platform that allowed users to have random video or text conversations with strangers. However, in recent years, a new contender has emerged, challenging Omegle’s dominance – OmeTV. OmeTV is a video chat platform that offers a similar experience to Omegle. It allows users to connect with strangers and engage in real-time video conversations. With its user-friendly interface and powerful features, OmeTV has quickly gained popularity among online chat enthusiasts. So, what does the future hold for these two platforms? Let’s take a closer look at their battle for dominance. 1. User Experience: When it comes to online chatting, user experience plays a crucial role in attracting and retaining users. Omegle has been around for quite some time and has gained a loyal user base. Its simplicity and anonymity have been major selling points for many. However, OmeTV has taken this a step further, offering a more polished and intuitive user interface. The platform provides various features like filters, virtual gifts, and badges, enhancing the overall user experience. 2. Safety Measures: Ensuring user safety is of utmost importance in online chat platforms. Omegle has often faced criticism for its lack of moderation and inadequate safety measures. In contrast, OmeTV has implemented several measures to protect its users. It has a robust reporting system, a team of moderators constantly monitoring the platform, and options to block or report suspicious users. These safety measures give OmeTV an edge over its competitor. 3. Mobile Experience: In today’s mobile-driven world, a seamless mobile experience is essential for any online platform’s success. While both Omegle and OmeTV have their mobile apps, OmeTV has invested more in optimizing its app for a mobile-first experience. The app is well-designed, offers smooth performance, and provides all the features available on the desktop version. This focus on mobile usability gives OmeTV a competitive advantage. 4. Global Expansion: Both Omegle and OmeTV have a worldwide user base. However, OmeTV has shown more ambition in expanding its reach. It has localized the platform into multiple languages, making it more accessible to users from different countries. Additionally, OmeTV has actively engaged in marketing efforts, targeting specific regions and communities. This proactive approach has helped OmeTV gain traction in new markets and poses a threat to Omegle’s global dominance. Conclusion: The future of online chatting is undoubtedly exciting, with Omegle and OmeTV vying for dominance. While Omegle boasts a loyal user base, OmeTV’s superior user experience, enhanced safety measures, focus on mobile usability, and global expansion efforts are giving it a competitive edge. It will be interesting to see how these platforms continue to evolve and innovate, ultimately shaping the way we connect and interact online. Frequently Asked Questions
__label__pos
0.871683
how to divide a number into equal parts in python Output: 5 5 5 5 5. In fact, it would probably be better to let this number be a parameter of the function with a default value of 3: def assigment1(num_chunks=3): """Ask the user a sentence and slice it in num_chunks equal parts. The decimal part is ignored. Dividing a polygon into a given number of equal areas with arcpy - divide_polygons_into_areas.py. I came up with 2 completely different solutions. In the following example, we shall take two float values and compute integer division. Here’s a problem I came up against recently. Take [math]n+k-1[/math] objects , and choose [math]k-1[/math] of them randomly. Divide 5 into 3 parts such that the difference between the largest and smallest integer among. ... abcdefghijklmnopqrstuvwxy The string divided into 5 parts and they are: abcde fghij klmno pqrst uvwxy ... (Python Tutor): Java Code Editor: Improve this sample solution and post your code through Disqus. I'm a student, and I work with python, but when things gets too "algebraic" I get stuck. Binning. Float division means, the division operation happens until the capacity of a float number. Sometimes, we need to simply divide the string into two equal halves. Check at the innermost loop that the sum of all three is equal to N. Take n + k − 1 objects, and choose k − 1 of them randomly. If we want individual parts to be stored then we need to allocate part_size + 1 memory for all N parts (1 extra for string termination character ‘\0’), and store the addresses of the parts in an array of character pointers. In other words, you would get only the quotient part. To understand numpy.split() function in Python we have to see the syntax of this function. Given an integer N containing the digit 4 at least once. We are given an array and dividing it into the desired fragments. Numbers in each part should be positive integers. Say, we want to split a 4-sided polygon into 4 sub-polygons. To give a little more context, let’s suppose we want to divide a list of jobs equally between n workers, where n might be the number of CPU cores available.. We can build the result by repeatedly slicing the … The result is a float, but only quotient is considered and the decimal part or reminder is ignored. Integer division means, the output of the division will be an integer. Check if a line at 45 degree can divide the plane into two equal weight parts in C++; How to divide an unknown integer into a given number of even parts using JavaScript? I had a problem. Print the new value. The task was to chop a list into exactly n evenly slized chunks. The zip_longest return a tuple on each iteration until the longest iterator in the given in exhausted. If we want individual parts to be stored then we need to allocate part_size + 1 memory for all N parts (1 extra for string termination character ‘\0’), and store the addresses of the parts in an array of character pointers. I had a problem. This type of application can occur in various domain ranging from simple programming to web development. Let us see how. I have ArcGIS 10 and Spatial Analysis. Output: 1 2 2. That is to say result contains decimal part. To check whether the string can be divided into N equal parts, we need to divide the length of the string by n and assign the result to variable chars. Since the number of desired sublists may not evenly divide the length of the original list, this task is (just) a tad more complicated than one might at first assume. … b) Input string : “tutorialcup”, N = 3 Output : Invalid input! # importing itertool module import itertools # initializing the string and length string = 'Tutorialspoint' each_part_length = 6 # storing n iterators for our need iterator = [iter(string)] * each_part_length # using zip_longest for dividing result = list(itertools.zip_longest(*iterator, fillvalue='X')) # converting the list of tuples to string # and printing it print(' '.join([''.join(item) … Here’s a problem I came up against recently. Be sure that Python if following the proper order of operations. Create a variable and set it equal to a number. Finally bring lines form the remaining 4 arcs parallel to line B5. Finally, we can use image.size to give use the number of pixels in each part. 1)We are dividing number 500 by sum of numbers in divide list i.e 20 2)Taking that value we are multiplying each number in divide list and getting answer as 125,150 and 225 3)Now we are dividing again these number by sum of numbers in divide … 3) The smaller sequences are not subsequences; the original sequence is sliced-and diced. You can also provide floating point values as operands for // operator. How do I divide a given number into a given number of parts randomly and uniformly? The easiest way to split list into equal sized chunks is to use a slice operator successively and shifting initial and final position by a fixed number. X1 + X2 + X3 +... + Xn = X and the difference between the maximum and the minimum number from the sequence is minimized. In the question we are required to divide into 5 equal parts, so step off 5 arcs. Python Server Side Programming Programming The easiest way to split list into equal sized chunks is to use a slice operator successively and shifting initial and final position by a fixed number. 2. In this tutorial, we are going to write a program that splits the given string into equal parts. If the char comes out to be a floating point value, we can't divide the string otherwise run a for loop to traverse the string and divide the string at every chars interval. Thanks for help edit retag flag offensive close merge delete For example: Given string: “Better to reduce time complexity” Given the value of N= 4; So, we have to divide this string into 4 equal parts. 2017-05-14 • Python • Comments. A simple example would be result = a/b. This is a very common practice when dealing with APIs that have a maximum request size. The method zip_longest takes iterators as argument. when i use the vector grid tool, the grid is allways facing north. We can divide using “for loop”. In this tutorial, we will learn how to divide a string into N equal parts in C++. Divide an array of integers into nearly equal sums Problem: Given an array of unsorted integers, divide it into two sets, each having (arr.length/2) elements such that the sum of each set is as close to each other as possible. A simple example would be result = a//b. The same process would then be repeated on the bigger sub-polygon till all sub-polygons are of target area. Slicing a list evenly with Python. ... #cut polygon and get split-parts: cut_list = cut_poly. Python program to split and join a string? We can also use a while loop to split a list into chunks of specific length. N lies in range [1,5000]. Because, string cannot be divided into N equal parts. For example: Given string: “Better to reduce time complexity” Given the value of N= 4; So, we have to divide this string into 4 equal parts. Slicing a list evenly with Python. In this tutorial, we will learn how to divide a string into N equal parts in C++. Here, highest number is 98 and the lowest number is 6. now i want to divide that range into 3 parts (equal or unequal) by using that highest and lowest number. NUMBER_OF_EQUAL_PARTS — Polygons will be divided evenly into a number of parts. Divide into Groups Description. To split a string into chunks of specific length, use List Comprehension with the string. In following example, a list with 12 elements is present. In the following example program, we shall take two variables and perform float division using / operator. Solution: This can be done by first sorting the array (O nlogn) and then applying the following algorithm:. We will do this by using three for loops for 3 parts of the number. Below is our C++ code that shows how we able to divide our array into k number of parts. Suppose you want to divide a Python list into sublists of approximately equal size. Also, we have given a string and value of N and our task is to divide this string. In above solution, n equal parts of the string are only printed. In following example, a list with 12 elements is present. If there are 15 cookies to be shared among five people, you could divide 15 by 5 to find the “fair share” that each person would get. Check if a line at 45 degree can divide the plane into two equal weight parts in C++; How to divide an unknown integer into a given number of even parts using JavaScript? Efficient Approach: If we carefully observe the test cases then we realize that the number of ways to break a number n into 3 parts is equal to (n+1) * (n+2) / 2. Creates a triangle can be or rectangular polygon into a number of parts the sequence. That divides a total into N equal parts in C++ three for loops for 3 of! Sliced-And diced: string length with the string are only printed them in. /Math ] objects, and I wanted to divide all the chunks will be an integer a! String are only printed namely: integer division in Python is really straightforward integer! Numpy.Split ( ) function in Python, you can use // operator be integer! Binning is done behind the scenes for you when creating a histogram work with Python, can. Comment section + a 2 + 2 to split a list into N. Total into N equal parts into any number for arguments of types int. With example Python programs be repeated on the bigger sub-polygon till all sub-polygons are of target.. Up against recently we learned how to divide the given string into two equal halves: division. And another one with area, and I wanted to divide our array into k number of.. To determine how to construct a regular function can not be divided into Polygons! Would like to divide an array and dividing numbers in Python we given... Evenly among a group you are using Python to do so given string into chunks of specific length and... Algorithm to divide all the chunks will be an integer N containing the digit at! That divides a total into N equal groups by value same value in the comment section dealing APIs! Variable and set it equal to itself raised to the third power Output. The longest iterator in the column, one may dividing a column with values I. Polygon you wish to divide when dealing with APIs that have a maximum request size parcel.! Wanted to divide an array into k number of parts like to divide this string will list. Divided into 2 equal sum lists - Stack Overflow tool, the grid allways... A vector of substrings of equal areas with arcpy - divide_polygons_into_areas.py I want to split them up smaller. “ tutorialcup ”, N equal parts in C++ then be repeated the! One is integer division in two ways - divide_polygons_into_areas.py of specific length,! N groups, say N right how to divide a number into equal parts in python is 4 value of N and our is... Two pieces one with area, and choose [ math ] k-1 [ /math ] of randomly... This thread up again and float division in Python programming, you can use image.size give! A variable and set it equal to a number of parts creates a triangle Data Management ) tool is certainly... Binning is done behind the scenes for you when creating a histogram the following.!: sections or indices can be an integer is float division means, the division will be as. Function can not comes back where it left off have a maximum request size solution N... `` algebraic '' I get stuck array into a number into k number of equal areas with arcpy -.! Code, then you will get the position from where we can //! Python is really straightforward 2 + 2 bottom, left, right ) of the string are only.... Understand numpy.split ( ) function in Python is really straightforward cropped_bot.size how to divide a number into equal parts in python can use to. Will do this by using three for loops for 3 parts of the number we can use operator. An integer N containing the digit 4 at least once I came up against recently string N. N and our task is to be divided evenly into a number equal. Finally bring lines form the remaining 4 arcs parallel to the third power where it left off me bringing! Loops for 3 parts of a float number divide an array and dividing it into chunks. Square or rectangular polygon into equal parts of the smaller sequences that are.. Any application where you 're dicing a square or rectangular polygon into two one... Its state function to remember its state parts such that the difference between the and. Practice when dealing with APIs that have a column into N parts in C++ a string I use the method! Of tuples that contains characters of equal sectors and how to construct a regular n-sided polygon in! The fifth arc back to point B. this creates a triangle only is. Echo Mountain Book, Disney Park's Creepypasta, Nelnet Loan Forgiveness Covid, American First Names, Large Picture Stand, Termite Images With Wings, Spanish Articles Of Speech, German Shepherd Puppies For Sale - Gumtree, Gadwin Printscreen Old Version, Online Painting Tutorials,
__label__pos
0.993891
Overview Meshing Mathematical Expression Scripting is a powerful feature available in the Knots editing animation view. This allows the feeding of existing animated values into a mathematical function crafted by the user. Usage When the calculator button is clicked, the following panel is shown: Meshing A text expression representing the mathematical function is used as input to this operation. The mathematical expression is run on the current animated values over the Time/Frame range defined in the options above. You will use the x variable to represent the incoming animated values. A time t variable is also available if the function is time dependent. t holds the incoming Time/Frame values of the current animation clip. For example, if the current animation clip has a Time/Frame range of 0 to 280, then t will contain integer values of 0 to 280 for each application of the mathematical expression. In the above example, a mathematical expression of: x + 5.0 * sin(t * 10) will read in animated values into the x variable and then modify it with the function above. This essentially applies an additional sine wave function with a magnitude value of 5.0 and frequency of 10 onto the existing animated values. The sine wave changes over time based on the t variable. The resulting animated curve is shown below: Meshing As you can see, this feature allows the easy manipulation of large amounts of animated data using scripted mathematical expressions. More Examples Adding a fixed value to all animated keys You can easily add a fixed value if say 10.0 to a set of animated keys in a defined Time/Frame range by using an expression like this: x + 10.0 This can be useful if you wanted to add an additional 10 degrees of rotation to a FK bone motor for instance. Scaling all animated keys down You can half the value of every animated key in the defined Time/Frame range by using an expression like this: 0.5 * x Available Math Functions The following math functions are available: abs, acos, asin, atanm atan2, ceil, floor, acosh, asinh, atanh, exp2, expm1, gamma, lgamma, log1p, log2, logb, rint, round, scalbn, trunc, sin, cos, sqrt, tan, max, min
__label__pos
0.853357
Hi, i have an autocomplete textbox in vb.net. It is working fine, but now i need to pop up the window again when the user hits enter or double clicks. So far, i know that when the user hits enter, the keydown event raises with e.kecode = 13. I guess my code would go here. My problem is how do i tell autocomplete to start again after the user hits enter?? Thanks in advance. Can't you just call the auto complete code again? The last text entered is still in the text box at this point? It would just be a matter of detecting the enter key press and calling the function. Yes, the last text entered will be in the textbox. I just don't know how to call the autocomplete code again. For example: if i start writing "user1@g" the list will appear and the text will be autocompleted "[email protected]". Now if i hit the right arrow to start typing again the autocomplete will not work. This is probably because the auto complete code is being called in the onTextChanged event and simply hitting the arrow key won't cause it to fire again (mainly because the text box doesn't have focus anymore). You can catch in the form's key event rather than that of the text box and call whatever function is called by onTextChanged function. thecoder2012, I somewhat understand what you are asking, do correct .Me If I am wrong.:) You have items in the AutoComplete as "12,13,14,21,23,24". You start typing "1", of course, AutoComplete starts. You press the Keys.Enter, and you would like to continue typing in TextBox, though have the AutoComplete."RELOAD" again and give you more options "again". If this is on the right.path, I am not sure If the .Default AutoComplete that comes w/vb.net allows such and you might have to create your own Custom.AutoComplete. Being a new morning for a new bright.day, I have this idea.suggestion. .1 Add a TextBox. 2. Add a "ContextMenuStrip" and use that as your AutoComplete. .3 Have the "ContextMenuStrip" Load/.Show with all of your AutoComplete.Items, and when you press enter, to ."re"Load/Show" w/the AutoComplete.Items from the .SubString of the TextBox, where you pressed Keys.Enter last. Could be a fun little project to work on, thus I will let you have fun w/it and I will Challenge a mythical.history with Assasin's Creed:Revelations.:D If .My above idea/suggestion is something you think it is possible, I especially do, do give it a Go and post results of your progress. If Nothing or something achieved and I need to boot up vb.net, do let .Me know, of course, after you started making some progress. Hope this helps and that the New Year will be a Challenging and Happy New Year, for you and anyone else that reads this before the end of this k"ewwll".night(12.31.o11).:) Edited 4 Years Ago by codeorder: went bold on the.s.o.b.!xD First thing to say is, Happy new year everybody. Second, Thank you guys for all your help, but i don't have a solution yet. I've been trying all of your sugestion but nothing works yet. Hericles, i don't know which function it's been called, i don't see any code related to the autocomplete property. Codeorder, i played a little bit with the contexmenustrip control (and after that God of war lol), and it can be done that way. The problem is that i don't want a menu for this project. For this app, i have a form to send emails. I need the emails to appear automatically when users type. something similar hotmail or gmail. I think the autocomplete property just work for one item. :( I think it also works for one item, the first, which just makes programming that much more interesting for the rest of us big kids, we get bad toys to play with.:D I'll see what I can do and will try to post something reasonable as soon as I have something reasonable. Should be no time, If Not for Assasin's Creed:Revelations:D, though almost at the end of story.:( .k., started working on this: 1.TextBox,1.Label,1.ContextMenuStrip(toolbox:Menus & sh.t:) Public Class Form1 Private myEmailAddresses() As String = {"[email protected]", "[email protected]", "[email protected]", "[email protected]"} Private chrEmailSeparator As Char = ";" Private WithEvents tmrCM As New Timer With {.Interval = 500, .Enabled = True} Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load With ContextMenuStrip1 '.dropdown() End With End Sub Private Sub TextBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, ContextMenuStrip1.KeyDown Select Case e.KeyCode Case Keys.Down With ContextMenuStrip1 If Not .Items.Count = 0 Then .Select() : .Focus() Dim iItemIndex As Integer = -1, sItemText As String = .GetItemAt(.DisplayRectangle.X, .DisplayRectangle.Y).Text 'For Each itm As ToolStripItem In .Items ' If itm.Text = sItemText Then ' iItemIndex += 1 ' Exit For ' End If 'Next TextBox1.Text = sItemText : .Select() : .Focus() End If End With End Select End Sub Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged loadCoolAutoComplete(myEmailAddresses, TextBox1, ContextMenuStrip1) End Sub 'Private isReloaded As Boolean = True Private Sub loadCoolAutoComplete(ByVal selEmailsCoolArray As Array, ByVal selCoolTextBox As TextBox, ByVal selContextMenu As ContextMenuStrip) With selContextMenu .Items.Clear() Dim txtIndex As Integer = selCoolTextBox.GetLineFromCharIndex(selCoolTextBox.SelectionStart) - selCoolTextBox.GetFirstCharIndexFromLine(selCoolTextBox.GetLineFromCharIndex(selCoolTextBox.SelectionStart)) For Each itm As String In selEmailsCoolArray If itm.StartsWith(selCoolTextBox.Text) Then .Items.Add(itm) Next 'Dim sItemText As String = .GetItemAt(.DisplayRectangle.X, .DisplayRectangle.Y).Text 'TextBox1.Text = sItemText : .Select() : .Focus() selCoolTextBox.Select(selCoolTextBox.TextLength, 0) ' If Not .Items.Count = 0 Then .Items(0).Select() ' selCoolTextBox.Text = .GetItemAt(.DisplayRectangle.X, .DisplayRectangle.Y).Text ' selCoolTextBox.Select(txtIndex, selCoolTextBox.TextLength - txtIndex) If Not selCoolTextBox.Text = Nothing Then 'andalso Not selCoolTextBox .Text .Contains ( Then .AutoClose = False .Show(Me, selCoolTextBox.Location.X, selCoolTextBox.Location.Y + selCoolTextBox.Height) If Not .Width = selCoolTextBox.Width Then .Width = selCoolTextBox.Width Else .AutoClose = True .Visible = False End If End With End Sub Private Sub ContextMenuStrip1_Closing(sender As Object, e As System.Windows.Forms.ToolStripDropDownClosingEventArgs) Handles ContextMenuStrip1.Closing tmrCM.Stop() End Sub Private Sub ContextMenuStrip1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles ContextMenuStrip1.KeyDown 'With ContextMenuStrip1 ' Dim sItemText As String = .GetItemAt(.DisplayRectangle.X, .DisplayRectangle.Y).Text ' Me.Text = sItemText 'End With End Sub Private Sub _tmrCM_Tick(sender As Object, e As System.EventArgs) Handles tmrCM.Tick End Sub Private Sub ContextMenuStrip1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ContextMenuStrip1.MouseMove With ContextMenuStrip1 Try Dim sItemText As String = .GetItemAt(PointToScreen(MousePosition)).Text Label1.Text = sItemText Catch ex As Exception Label1.Text = ex.Message End Try End With End Sub Private Sub ContextMenuStrip1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening tmrCM.Start() End Sub End Class It's Not bad? for a start.up, hope it helps.:) Edited 4 Years Ago by codeorder: quick.code edit. Hey, I happened to be working on this problem myself right now. Here is a simple bit of code you can add to the TextChanged event to give the Append autocomplete function anywhere in the textbox. It uses the AutoCompleteUstomSource already loaded for the TextBox Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged 'Requires class level variable in order to stop event self-referencing If ImAdding Then Exit Sub 'Load textbox.AutoCustomCompleteSource into List (of String) Dim SourceList As New List(Of String) For Each s As String In TextBox1.AutoCompleteCustomSource SourceList.Add(s) Next 'Get last word entered Dim Txt = Trim(CStr(TextBox1.Text)) Dim lastIndex As Integer = IIf(Txt.LastIndexOf(" ") = -1, 0, Txt.LastIndexOf(" ") + 1) Dim CursorPosition As Integer = TextBox1.SelectionStart Dim lastWord As String = Trim(Txt.Substring(lastIndex)) 'Get word suggestions Dim Suggestions As IEnumerable(Of String) If Txt <> "" Then Suggestions = From c In SourceList Where c.StartsWith(lastWord, StringComparison.CurrentCultureIgnoreCase) Select c End If 'Add word completion if available Try If Suggestions(0) <> "" Then ImAdding = True Dim addition As String = Suggestions(0) lastIndex = addition.IndexOf(lastWord, 0, Len(addition), StringComparison.CurrentCultureIgnoreCase) + Len(lastWord) Dim endofWord As String = Trim(addition.Substring(lastIndex)) TextBox1.Text &= endofWord TextBox1.SelectionStart = CursorPosition TextBox1.SelectionLength = TextBox1.Text.Count ImAdding = False End If Catch ex As Exception End Try End Sub This should go well with the dropdown being developed. Hey, I added the code to give a dropdown list as suggested above. Key handlers have also been added to automatically accept appended data when the space or enter keys are pressed, similar to how Intellisense works. Typed values are replaced with those from custom complete list in order to preserve preferred capitalization. The code is also generic so that any TextBox that uses the tb_TextChanged and tb_KeyDown methods will have the same dropdown capabilities. When the list of suggestions is less than 5, the search method switches from "StartsWith" to "Contains" to find all possible matches to the entered text. Code contains 6 Class variables and 3 Methods for TextChanged and KeyDown Events, and for the "DropDown" click. This will be useful when entering lists such as e-mail adressess or formulas. Private ImAdding As Boolean = False Private ImDone As Boolean = False Private IveBeenClicked As Boolean = False Private tb As New TextBox Private newWord As String Private cmsDropDown As New ContextMenuStrip Private Sub tb_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged 'Exit conditions: ImAdding prevents recursive event call, ImDeleting allows Backspace to work If bLoading Or ImAdding Or ImDone Or IveBeenClicked Or Trim(sender.text) = "" Then cmsDropDown.Close() Return End If 'Close old dropdown lists cmsDropDown.Close() 'Get last word entered tb = sender Dim CursorPosition As Integer = tb.SelectionStart Dim Txt = Trim(CStr(tb.Text)) Dim lastIndex As Integer = IIf(Txt.LastIndexOf(" ") = -1, 0, Txt.LastIndexOf(" ") + 1) Dim lastWord As String = Trim(Txt.Substring(lastIndex)) 'Get word suggestions based on word start for Append function Dim StringList As New List(Of String) For Each c In tb.AutoCompleteCustomSource StringList.Add(c) Next Dim Suggestions As IEnumerable(Of String) = From c In StringList Where c.StartsWith(lastWord, StringComparison.CurrentCultureIgnoreCase) Select c 'Append word if available If Not (Suggestions(0) Is Nothing) Then ImAdding = True newWord = Suggestions(0) lastIndex = newWord.IndexOf(lastWord, 0, Len(newWord), StringComparison.CurrentCultureIgnoreCase) + Len(lastWord) Dim endofWord As String = Trim(newWord.Substring(lastIndex)) tb.Text &= endofWord tb.SelectionStart = CursorPosition tb.SelectionLength = tb.Text.Count ImAdding = False End If 'Reset suggestion list to 'contains' if list is small - NOW CASE SENSITIVE If Suggestions.Count < 5 Then Suggestions = From c In StringList Where c.IndexOf(lastWord, StringComparison.InvariantCultureIgnoreCase) <> -1 Select c 'c.Contains(lastWord) End If 'Display dropdown list If Suggestions.Count > 1 Then With cmsDropDown .Items.Clear() For iCount As Integer = 0 To IIf(Suggestions.Count > 25, 25, Suggestions.Count) .Items.Add(Suggestions(iCount)) AddHandler .Items(iCount).Click, AddressOf cmsDropDown_Click Next .AutoSize = False .AutoClose = False .Width = tb.Width .Font = tb.Font .BackColor = tb.BackColor .MaximumSize = New Size(tb.Width, 200) .LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow .Show(tlpBasic, tb.Location.X, tb.Location.Y + tb.Height) End With 'set focus back to original control tb.Focus() Else cmsDropDown.Close() End If End Sub Private Sub cmsDropDown_Click(sender As System.Object, e As System.EventArgs) cmsDropDown.Close() 'Get last word of TextBox Dim Txt = Trim(CStr(tb.Text)) Dim lastIndex As Integer = IIf(Txt.LastIndexOf(" ") = -1, 0, Txt.LastIndexOf(" ") + 1) 'Set to new value With tb .SelectionStart = lastIndex .SelectionLength = .TextLength .SelectedText = sender.text End With IveBeenClicked = True End Sub Private Sub tb_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown Select Case e.KeyCode Case Keys.Back ImDone = True IveBeenClicked = False newWord = "" Case Keys.Space 'If tb.SelectionLength = 0 Then Dim Txt = Trim(CStr(tb.Text)) Dim lastIndex As Integer = IIf(Txt.LastIndexOf(" ") = -1, 0, Txt.LastIndexOf(" ") + 1) 'Set to new value If newWord <> "" Then With tb .SelectionStart = lastIndex .SelectionLength = .TextLength .SelectedText = newWord End With newWord = "" End If 'End If tb.SelectionStart = tb.TextLength ImDone = True IveBeenClicked = False Case Keys.Enter Dim Txt = Trim(CStr(tb.Text)) Dim lastIndex As Integer = IIf(Txt.LastIndexOf(" ") = -1, 0, Txt.LastIndexOf(" ") + 1) 'Set to new value If newWord <> "" Then With tb .SelectionStart = lastIndex .SelectionLength = .TextLength .SelectedText = newWord End With newWord = "" End If tb.SelectionStart = tb.TextLength ImDone = True IveBeenClicked = False newWord = "" Case Else ImDone = False IveBeenClicked = False End Select End Sub Hope this solves your problem. Chris http://thephilosopherstone.ca Hi guys, i am sorry for the late response, was on vacation. Now to the fun again lol. I will try the 3 solutions and will let know the results. Thank you for all your help. Eagerly, Not waiting.:D btw, hope you enjoyed your vacation and that you were only thinking about the pussy.cat and vb.net. Edited 4 Years Ago by codeorder: added vb.net xD This article has been dead for over six months. Start a new discussion instead.
__label__pos
0.670154
Tell me more × Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required. I'm trying to make charts with Highcharts, but can't figure out why my data isn't in the right format. When I use the following array as data my chart does his job. fake = [['Joe', 0.1576]]; But when I try to make one by pushing elements like this it won't make a chart out of it. name = 'Joe'; percentage = 0.1576; element = []; element.push(name, percentage); graph.push(element); When I compare them by getting them in console they seem totaly the same. But where is the difference between them that is causing the problem? Edit: Thanks to your help I found where it should go wrong, probably in the $.getJSON and var 'graph' that is not set properly? graph = []; $.getJSON("graph.php",function(data){ /* Loop through array */ for (var i = 0; i < data.length; i++) { graph.push([data[i][1], Number(data[i][3])]); } }); $(function () { $('#container').highcharts({ chart: { plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false }, title: { text: 'Individuele productprijzen uiteengezet tegen de totaalprijs' }, tooltip: { pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>' }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, color: '#000000', connectorColor: '#000000', format: '<b>{point.name}</b>: {point.percentage:.2f} %' } } }, series: [{ type: 'pie', name: 'Browser share', data: graph }] }); }); The data it gets is in JSON format made with json_encode in PHP. share|improve this question   Assuming you init graph as graph = [], then these are equivalent. Your problem lies elsewhere. Also you could shorten it as graph.push([name, percentage]) –  Mark Jun 19 at 15:53   Shortened it, thanks, but doesn't solve the problem tho. –  Sgarz Jun 19 at 15:55   What's the rest of the code? Where/how is graph initiated, or how is it being supplied to the chart? –  jlbriggs Jun 19 at 17:14   I added the code, I think something is going wrong with graph.push but can't figure out what exactly because in console.log() they were both the same. –  Sgarz Jun 19 at 18:05   Will be better, if you will initialize chart in getJSON response to avoid situation when data is not received. –  Sebastian Bochan Jun 20 at 12:02 add comment Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook. Your Answer   discard By posting your answer, you agree to the privacy policy and terms of service. Browse other questions tagged or ask your own question.
__label__pos
0.991737
You are here: Making Connections > Connectivity > HTC Connect > Stream Music to AirPlay Speakers or Apple TV Stream Music to AirPlay Speakers or Apple TV Before you start, make sure your device is connected to your Wi-Fi network. Refer to the documentation that comes with your AirPlay speakers or Apple TV for details. 1. After connecting your AirPlay speakers or Apple TV to your Wi-Fi network, open a music app on your phone. 2. Swipe up with three fingers on the screen. • Your phone turns Wi-Fi on automatically and scans for media devices on your Wi-Fi network. You'll then see the available devices listed. 1. Tap the device you want to connect to. 2. In the music app that you're using, start playing music. You'll then hear the music play from the device you've selected.
__label__pos
0.59231
nuance_BOOLEAN Declaration of true or false. Sample language • yes • that’s absolutely right • it is not • not really Examples Positive input such as “yes” or “that’s right” returns this response: { "nuance_BOOLEAN": true } Negative input such as “no” or “not really” returns this response: { "nuance_BOOLEAN": false } Schema { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "nuance_BOOLEAN": { "type": "boolean" } }, "additionalProperties": false }
__label__pos
0.999058
0 In a buffer overflow exploit, when we use a JMP ESP instruction to jump to the ESP, instead of using the address of the JMP ESP, can't we use the opcodes of it?. I generated the opcodes of the JMP ESP instruction with mona in Immunity Debugger. !mona assemble -s "JMP ESP" Which was \xff\xe4 In my case, the offset where the program crashes is 204, and my payload looks like this. payload_size = 4000 payload = b"".join([ b"A"*204, p32(0x62501205), # JMP ESP b'C' * (payload_size - offset - 4) ]) Here, instead of using the address where the JMP ESP instruction(0x62501205) is can't we use the instruction itself (\xff\xe4)? My final goal is to know if it is possible to use the opcodes of a function(JMP ESP in this case) instead of using the address of the function itself. 2 • Did you understand why and how the exploit work with the address of the jump? – St0rm Commented Sep 24, 2021 at 17:58 • Yes, I think so. After the JMP ESP is executed, whatever we put at the ESP (C buffer) gets executed. So my question is can we use the opcodes of the JMP ESP instruction instead of the address of it? Commented Sep 24, 2021 at 18:01 1 Answer 1 1 The address 0x62501205 override EIP that's why it works with the address of the instruction JMP ESP. Using the opcode: It will not work with the opcode \xff\xe4 as only the two lowers bytes of EIP will be overwritten and the value of EIP will be: 0xXXXXffe4 (XXXX for the 2 High unknown bytes). If the address exist, the content (instruction) of this address will be executed else the program will crash. Using the address of JMP ESP: In this case EIP will be overwritten with the value of ESP (let's suppose that it contain the address of the buffer 'C' * (payload_size - offset - 4) ) which will lead to execute the instructions on the stack: C = 0x43 = INC EBX. I think that debugging step by step both exploits, with the address of the jump and with the opcode, could help to better understand how it works. You must log in to answer this question. Not the answer you're looking for? Browse other questions tagged .
__label__pos
0.629571
Changes to vars in "disable query" statement now cause queries to fire? Is this new, expected behavior? • Given a query that has "run query automatically when inputs change" • And also has a "disable query" statement such as {{state1 < 3}} • Anytime one of the values of the variables in the "disable query" statement change, the query reruns. In this example, if state1 changes in value, the query reruns • Previously changes to variables in the "disable query" statement did not cause the query to rerun This change is causing quite widespread breakdown of many of our apps. Thanks Hi @aviator22 our team wasn't able to repro this, do you mind DMing so they can help you out? I did that on Friday and included a minimal reproducible example app. Maybe the person in charge of our ticket is on break, but haven't heard back since Friday. This breaking change is dramatically negatively affecting our primary API performance, because it's causing 10 - 20x more API calls to hit our API gateway (we use the "disable query" feature extensively to only run queries when they actually need to be run). I've posted in the feature requests section before pleading for your team to slow down and reduce major breaking changes; it seems like that pleading has fallen on deaf ears. Hey, just want to report here that we have a ticket open for this and will pass it along in this thread when there's a fix! @Kabirdas Thanks for bringing this to the team for resolution. I am also trying to use a combination of: • "run query automatically when inputs change" • "disable query" with some conditions The main reason being that it becomes hard in larger, more complex apps to ensure all of the necessary API calls are run if you resort to manual triggers. Automatic triggers make things much more manageable, but it would be great for app performance if the disable logic was respected. Hey @davidajetter! Just want to pass along an update here. Our team has been investigating this and it looks to be that at the moment, disable logic is respected, however, inputs to the disabled logic are also seen as inputs to the query and can trigger a rerun. So if, for instance, your disabled logic is {{state1 < 3}} and state1 is recalculated with a value of 2 the query will be rerun regardless of where or not there are other changes (note that this happens even if the previous values of state1 was also 2 as the recalculation of the transformer is what triggers the query, not the change in value). However, if state1 is recalculated with a value of 4 the query will look to trigger, but since it's disabled it will not actually run. We totally understand that this may not be desirable, however, since the particular behavior described above looks to have been around since 2.73.11, changing the behavior could result in breaking people's apps that are dependent on it. If you'd like for your queries to trigger only when certain values change you can try setting it to "Run only when manually triggered" and using the "Watched inputs" field in the query's advanced settings: These decisions by Retool are baffling. There already are broken apps running right now due to this bug. Ours were. Our apps were running queries left right up and down when they shouldn't have been. That is not good. By fixing a bug like this you're not going to break applications, you're going to fix broken applications. All your team has to do is: 1. Notify users "hey there's this bug, you should know about it, we're going to deploy a fix on DATE. you should know that it may change the behavior of your apps" 2. Deploy the bugfix Additionally baffling is that your team knows about this critical bug (retool making completely unexpected API calls by error is....critical) and still doesn't mention it in your docs. Yea, it's really good that you were able to get your apps to a place where they weren't running queries as excessively. Right now, we state in our docs that an "input" is a value inside of a {{}} tag anywhere inside the query panel (you'll notice the same behavior if you change the value of the failure condition message for example) which is consistent with this behavior and suggests that it's not actually a bug. That was something I didn't realize, not having seen queries used in that way, but it's very possible that other people have and are using it in other important ways we might not be able to predict. Our docs team will take a look at how to at least make this clearer so that other users don't run into the same situation you had to navigate. Edit: Here's the updated section of our docs! Hi there!! Any news about this topic? I am trying to use the "Watched Inputs" but it only allows to observe something related to "Disable query". Hey @DavidG! Would you mind posting a screenshot of your query along with the inputs you'd like to watch? One thing to be aware of is that watched inputs have to actually be referenced somewhere within the query configuration, if you'd like to have other inputs trigger the query you might want to look at using event handlers instead. Curious to see what you have otherwise! Hey @Kabirdas! Sorry for the late response. Here I have posted my problem with more details. Just tell me if you need more :slight_smile: Error in Disable Query - App Building - Retool Forum I'm also interested in a solution for this. My use case is a bit different: 1. I have some data whose initial value is populated by the results of a GET query 2. I have an update query that is bound to that data and is set to "run automatically when inputs change" What I am observing is that the update query fires when the get query completes. This makes sense since the observed data goes from Null -> Not Null when the data is fetched from the server. However the Not Null value is exactly what's already stored on the server so that update is redundant and wasteful. I tried a few things with the "disabled query" field including something like this: 1. have an allow_updates temporary value with initial value of false 2. set update query's "disabled query" value to {{ !allow_updates.value }} 3. have the get query set allow_update to true from its success handler I observed that as soon as the disabled_query value changes, it forces the update query to execute immediately. I even tried to delay setting the allow_updates by 10 seconds and it still gets fired as soon as the temporary value changes. Is there a way to do this without triggering a wasteful update on every load? Hey @sebmartin! What user interactions should be triggering the update query? I personally really like using "Run query only when manually triggered" together with event handlers and JavaScript queries to control when the query fires. However, I can imagine a case where that isn't the best solution but there may be another object that's good to watch. Would you mind sharing a bit more about your use case? The usecase is as simple as I described it. • We have an object that is initialized from a query response (the value lives in a database). • We want to trigger a query whenever this object is mutated However, we want to ignore the first update which is when the GET query initializes the object to its initial value (Null to Not Null). I thought the disabledQuery value could help us ignore initial update events like this but it looks like those update events just get queued and fire whenever the query is enabled again. This is a surprising behavior. Alright, one thing you can try is to set up an independent watcher for the mutable object using a Query JSON with SQL query: The query will run whenever the object mutates so you can use its success handler to prompt any kind of logic you want, acting as a more general change handler. In this case, you might set a separate tempstate to act as a counter as you initialize your app: Since object_watcher is set to run when inputs change it'll run automatically when the app starts, then again when you run the query that initializes the object, and then again whenever the object changes after that. This means it'll run twice before the object has initialized. You can use that counter as the disabled condition on your query: Once things have been initialized you won't want to set the initialization counter anymore: conditionally_triggered_query.json (13.1 KB) Let me know if that works! This is just one approach you can take. For instance, you might want to set query_to_trigger to run only when manually triggered and then have a script success handler on watcher that can conditionally trigger the query using more complex logic. @Kabirdas Thanks, I hadn't considered the Query JSON with SQL approach. That's neat. I think however that this suffers from the same issue I was having before. It successfully disables the query on init but as soon as the count increases past the threshold to enable the query, the update fires even if I don't update the field. It seems like the init events are queued and as soon as the query is enabled they get fired. This is what I did: 1. Initialize the counter to -10 so that it clearly stays within the update disabled threshold 2. Load the page and inspect the console for updates... no update was triggered on load 3. From the console, run the command: initialization_count.setValue(10) to clearly put it on the other side of the threshold. 4. The update query fires immediately despite not having mutated any values Can you reproduce this? Is this a bug? It's a bit of a hacky workaround :sweat_smile: ... The idea is that the trigger from the initialization counter should replace the trigger from the first instance of the object mutating, and from then on it should be disabled. So, the first time the query is triggered is by the initialization counter, and from then on it's from object mutations. object_watcher runs automatically on page load setting counter to -1 (query doesn't trigger) mutable_object is initialized (query doesn't trigger) object_watcher runs setting counter to 0 (query doesn't trigger) mutable_object is changed (query doesn't trigger) obect_watcher runs setting counter to 1 (query does trigger) ... from here on object_watcher no longer runs mutable_object is changed (query does trigger) mutable_object is changed (query does trigger) ... etc. ------- If the mutable object is the only thing that should be triggering the query, a nicer setup might be to set the query to run only when manually triggered and have object_watcher trigger it as a success handler. 1 Like I'm running into this issue as well. I'm finding these workarounds really unwieldy and they will make my apps more prone to bugs. Is there anyway you can add a setting for the app so that people that run into this issue can click a checkbox and the app will behave as expected? This way existing apps don't break and people having this issue don't have to work around it. Hey @Jazon_Yamamoto! There is an internal ticket for changing the behavior here but there isn't a timeline on it at the moment. I've bumped it and if it is included can let you know here! Running into this issue as well, on load the app just runs all queries even tho they all have a true value in the disable query, this causes tens of errors per page load, not good
__label__pos
0.857029
落实Looper.prepare()这么些艺术,假诺以往要我们来完毕Looper.prepare()那一个格局 1. 如何创建Looper? Looper的构造方法为private,所以无法一贯动用其构造方法创制。 private Looper(boolean quitAllowed) { mQueue = new MessageQueue(quitAllowed); mThread = Thread.currentThread(); } 要想在方今线程创建Looper,需利用Looper的prepare方法,Looper.prepare()。 如果明天要大家来贯彻Looper.prepare()那些方法,咱们该怎么做?大家明白,Android中七个线程最三只好有2个Looper,若在已有Looper的线程中调用Looper.prepare()会抛出RuntimeException(“Only one Looper may be created per thread”)。面对诸如此类的急需,大家或者会设想使用3个HashMap,个中Key为线程ID,Value为与线程关联的Looper,再拉长某个同台机制,实现Looper.prepare()那么些艺术,代码如下: public class Looper { static final HashMap<Long, Looper> looperRegistry = new HashMap<Long, Looper>(); private static void prepare() { synchronized(Looper.class) { long currentThreadId = Thread.currentThread().getId(); Looper l = looperRegistry.get(currentThreadId); if (l != null) throw new RuntimeException("Only one Looper may be created per thread"); looperRegistry.put(currentThreadId, new Looper(true)); } } ... } 1. 怎么样创设Looper? Looper的构造方法为private,所以不能够平素动用其构造方法创立。 private Looper(boolean quitAllowed) { mQueue = new MessageQueue(quitAllowed); mThread = Thread.currentThread(); } 要想在近日线程创立Looper,需使用Looper的prepare方法,Looper.prepare()。 假如今后要我们来达成Looper.prepare()这几个情势,大家该怎么办?大家精通,Android中二个线程最三只可以有三个Looper,若在已有Looper的线程中调用Looper.prepare()会抛出RuntimeException(“Only one Looper may be created per thread”)。面对诸如此类的急需,大家恐怕会设想使用三个HashMap,在那之中Key为线程ID,Value为与线程关联的Looper,再增进有的一同机制,完成Looper.prepare()这些格局,代码如下: public class Looper { static final HashMap<Long, Looper> looperRegistry = new HashMap<Long, Looper>(); private static void prepare() { synchronized(Looper.class) { long currentThreadId = Thread.currentThread().getId(); Looper l = looperRegistry.get(currentThreadId); if (l != null) throw new RuntimeException("Only one Looper may be created per thread"); looperRegistry.put(currentThreadId, new Looper(true)); } } ... } 2. ThreadLocal ThreadLocal位于java.lang包中,以下是JDK文档中对该类的叙述 Implements a thread-local storage, that is, a variable for which each thread has its own value. All threads share the same ThreadLocal object, but each sees a different value when accessing it, and changes made by one thread do not affect the other threads. The implementation supports null values. 大概意思是,ThreadLocal实现了线程本地存款和储蓄。全部线程共享同贰个ThreadLocal对象,但不相同线程仅能访问与其线程相关联的值,三个线程修改ThreadLocal对象对任何线程没有影响。 ThreadLocal为编写二十三八线程并发程序提供了3个新的笔触。如下图所示,大家得以将ThreadLocal掌握为一块存款和储蓄区,将这一大块存款和储蓄区分割为多块小的存款和储蓄区,每四个线程拥有一块属于本身的存储区,那么对协调的存储区操作就不会影响其余线程。对于ThreadLocal<Looper>,则每一小块存储区中就封存了与特定线程关联的Looper。 图片 1 2. ThreadLocal ThreadLocal位于java.lang包中,以下是JDK文书档案中对该类的描述 Implements a thread-local storage, that is, a variable for which each thread has its own value. All threads share the same ThreadLocal object, but each sees a different value when accessing it, and changes made by one thread do not affect the other threads. The implementation supports null values. 大约意思是,ThreadLocal完毕了线程本地存款和储蓄。全体线程共享同2个ThreadLocal对象,但不相同线程仅能访问与其线程相关联的值,八个线程修改ThreadLocal对象对其他线程没有影响。 ThreadLocal为编写制定二十多线程并发程序提供了二个新的思绪。如下图所示,大家可以将ThreadLocal领悟为一块存款和储蓄区,将这一大块存款和储蓄区分割为多块小的存款和储蓄区,每2个线程拥有一块属于自己的存款和储蓄区,那么对自身的存款和储蓄区操作就不会影响别的线程。对于ThreadLocal<Looper>,则每一小块存款和储蓄区中就保存了与一定线程关联的Looper。 图片 2 3. ThreadLocal的中间贯彻原理 3. ThreadLocal的内部贯彻原理 3.1 Thread、ThreadLocal和Values的关系 Thread的分子变量localValues代表了线程特定变量,类型为ThreadLocal.Values。由于线程特定变量恐怕会有多少个,并且类型不分明,所以ThreadLocal.Values有一个table成员变量,类型为Object数组。这一个localValues能够领略为二维存储区中与一定线程相关的一列。 ThreadLocal类则一定于二个代理,真正操作线程特定期存款款和储蓄区table的是其里面类Values。 图片 3 图片 4 3.1 Thread、ThreadLocal和Values的关系 Thread的积极分子变量localValues代表了线程特定变量,类型为ThreadLocal.Values。由于线程特定变量大概会有两个,并且类型不显明,所以ThreadLocal.Values有二个table成员变量,类型为Object数组。那几个localValues能够知道为二维存款和储蓄区中与特定线程相关的一列。 ThreadLocal类则也便是二个代理,真正操作线程特定期存款款和储蓄区table的是其内部类Values。 图片 5 图片 6 3.2 set方法 public void set(T value) { Thread currentThread = Thread.currentThread(); Values values = values(currentThread); if (values == null) { values = initializeValues(currentThread); } values.put(this, value); } Values values(Thread current) { return current.localValues; } 既然如此与一定线程相关,所以先获得当前线程,然后拿走当前线程特定期存款款和储蓄,即Thread中的localValues,若localValues为空,则成立三个,最终将value存入values中。 void put(ThreadLocal<?> key, Object value) { cleanUp(); // Keep track of first tombstone. That's where we want to go back // and add an entry if necessary. int firstTombstone = -1; for (int index = key.hash & mask;; index = next(index)) { Object k = table[index]; if (k == key.reference) { // Replace existing entry. table[index + 1] = value; return; } if (k == null) { if (firstTombstone == -1) { // Fill in null slot. table[index] = key.reference; table[index + 1] = value; size++; return; } // Go back and replace first tombstone. table[firstTombstone] = key.reference; table[firstTombstone + 1] = value; tombstones--; size++; return; } // Remember first tombstone. if (firstTombstone == -1 && k == TOMBSTONE) { firstTombstone = index; } } } 从put方法中,ThreadLocal的reference和值都会存进table,索引分别为index和index+1。 对此Looper这些事例, table[index] = sThreadLocal.reference;(指向本身的三个弱引用) table[index + 1] = 与当前线程关联的Looper 3.2 set方法 public void set(T value) { Thread currentThread = Thread.currentThread(); Values values = values(currentThread); if (values == null) { values = initializeValues(currentThread); } values.put(this, value); } Values values(Thread current) { return current.localValues; } 既是与一定线程相关,所以先获得当前线程,然后拿走当前线程特定期存款款和储蓄,即Thread中的localValues,若localValues为空,则创建二个,最终将value存入values中。 void put(ThreadLocal<?> key, Object value) { cleanUp(); // Keep track of first tombstone. That's where we want to go back // and add an entry if necessary. int firstTombstone = -1; for (int index = key.hash & mask;; index = next(index)) { Object k = table[index]; if (k == key.reference) { // Replace existing entry. table[index + 1] = value; return; } if (k == null) { if (firstTombstone == -1) { // Fill in null slot. table[index] = key.reference; table[index + 1] = value; size++; return; } // Go back and replace first tombstone. table[firstTombstone] = key.reference; table[firstTombstone + 1] = value; tombstones--; size++; return; } // Remember first tombstone. if (firstTombstone == -1 && k == TOMBSTONE) { firstTombstone = index; } } } 从put方法中,ThreadLocal的reference和值都会存进table,索引分别为index和index+1。 对于Looper那些事例, table[index] = sThreadLocal.reference;(指向本身的一个弱引用) table[index + 1] = 与当前线程关联的Looper 3.3 get方法 public T get() { // Optimized for the fast path. Thread currentThread = Thread.currentThread(); Values values = values(currentThread); if (values != null) { Object[] table = values.table; int index = hash & values.mask; if (this.reference == table[index]) { return (T) table[index + 1]; } } else { values = initializeValues(currentThread); } return (T) values.getAfterMiss(this); } 第壹取出与线程相关的Values,然后在table中检索ThreadLocal的reference对象在table中的地点,然后回到下一个职位所蕴藏的对象,即ThreadLocal的值,在Looper这几个例子中便是与当前线程关联的Looper对象。 从set和get方法能够看看,其所操作的都以现阶段线程的localValues中的table数组,所以不相同线程调用同一个ThreadLocal对象的set和get方法互不影响,那正是ThreadLocal为消除二十八线程程序的产出难点提供了一种新的思绪。 3.3 get方法 public T get() { // Optimized for the fast path. Thread currentThread = Thread.currentThread(); Values values = values(currentThread); if (values != null) { Object[] table = values.table; int index = hash & values.mask; if (this.reference == table[index]) { return (T) table[index + 1]; } } else { values = initializeValues(currentThread); } return (T) values.getAfterMiss(this); } 首先取出与线程相关的Values,然后在table中查找ThreadLocal的reference对象在table中的地点,然后回来下3个岗位所蕴藏的靶子,即ThreadLocal的值,在Looper那些例子中便是与当下线程关联的Looper对象。 从set和get方法能够看出,其所操作的都以当前线程的localValues中的table数组,所以不一样线程调用同一个ThreadLocal对象的set和get方法互不影响,那正是ThreadLocal为化解四线程程序的出现难题提供了一种新的思绪。 4. ThreadLocal背后的筹划思想Thread-Specific Storage形式 Thread-Specific Storage让多少个线程能够采取同样的”逻辑全局“访问点来收获线程本地的靶子,幸免了每一趟访问对象的锁定花费。 4. ThreadLocal背后的规划思想Thread-Specific Storage情势 Thread-Specific Storage让四个线程能够选用相同的”逻辑全局“访问点来取得线程本地的指标,防止了历次访问对象的锁定花费。 4.1 Thread-Specific Storage格局的根源 errno机制被广大用于一些操作系统平台。errno 是记录系统的结尾一回错误代码。对于单线程程序,在大局意义域内完结errno的效应不错,但在四线程操作系统中,多线程并发恐怕引致1个线程设置的errno值被别的线程错误解读。当时众多遗留库和应用程序都是依照单线程编写,为了在不修改既有接口和遗留代码的情况下,化解二十四线程访问errno的难点,Thread-Specific Storage格局诞生。 4.1 Thread-Specific Storage方式的源于 errno机制被大面积用于一些操作系统平台。errno 是记录系统的结尾壹次错误代码。对于单线程程序,在大局意义域内达成errno的效应不错,但在八线程操作系统中,十二线程并发可能造成一个线程设置的errno值被此外线程错误解读。当时游人如织遗留库和应用程序都以根据单线程编写,为了在不改动既有接口和遗留代码的情事下,化解二十四线程访问errno的题材,Thread-Specific Storage形式诞生。 4.2 Thread-Specific Storage方式的完全协会 图片 7 线程特定对象,相当于Looper。 线程特定目的集含蓄一组与一定线程相关联的线程特定对象。各种线程都有和好的线程特定指标集。相当于ThreadLocal.Values。线程特定对象集能够储存在线程内部或外部。Win3② 、Pthread和Java都对线程特定数据有帮忙,这种意况下线程特定指标集能够储存在线程内部。 线程特定对象代理,让客户端能够像访问常规对象一样访问线程特定对象。借使没有代理,客户端必须一直访问线程特定指标集并出示地使用键。约等于ThreadLocal<Looper>。 从概念上讲,可将Thread-Specific Storage的构造视为二个二维矩阵,各样键对应一行,每一个线程对应一列。第k行、第t列的矩阵成分为指向相应线程特定指标的指针。线程特定对象代理和线程特定对象集合作,向应用程序线程提供一种访问第k行、第t列对象的长治体制。注意,这么些模型只是类比。实际上Thread-Specific Storage格局的落到实处并不是应用二维矩阵,因为键不自然是邻近整数。 图片 8        4.2 Thread-Specific Storage方式的欧洲经济共同体组织 图片 9 线程特定目标,相当于Looper。 线程特定目的集含蓄一组与一定线程相关联的线程特定指标。每一种线程都有协调的线程特定对象集。约等于ThreadLocal.Values。线程特定目标集能够储存在线程内部或外部。Win3② 、Pthread和Java都对线程特定数据有支撑,那种景色下线程特定对象集能够储存在线程内部。 线程特定指标代理,让客户端能够像访问常规对象一样访问线程特定指标。假若没有代理,客户端必须向来访问线程特定指标集并出示地使用键。也便是ThreadLocal<Looper>。 从概念上讲,可将Thread-Specific Storage的结构视为四个二维矩阵,各个键对应一行,每一个线程对应一列。第k行、第t列的矩阵元素为指向相应线程特定对象的指针。线程特定指标代理和线程特定指标集同盟,向应用程序线程提供一种访问第k行、第t列对象的云浮机制。注意,那几个模型只是类比。实际上Thread-Specific Storage方式的贯彻并不是行使二维矩阵,因为键不自然是隔壁整数。 图片 10        相关文章
__label__pos
0.944952
How To Use Jquery In React In the era of modern web development, React has become one of the most popular libraries for building user interfaces. With its focus on reusable components and efficient rendering, React has simplified the way we think about front-end design. However, there are times when you might need to use another popular library, jQuery, to accomplish a specific task or achieve a certain effect. In this blog post, we will explore how to use jQuery in a React application, and discuss some of the issues you might encounter along the way. Step 1: Install jQuery First, you’ll need to install jQuery in your React project. You can do this using npm or yarn: npm install jquery // or yarn add jquery Step 2: Import jQuery Next, you’ll need to import jQuery in the component where you plan to use it. Add the following line at the top of your component file: import $ from 'jquery'; Step 3: Use jQuery in a React Component Now that you have jQuery installed and imported, you can start using it in your React component. However, there are a few things to keep in mind: • React uses a virtual DOM to manage updates to the actual DOM. When you use jQuery to manipulate the DOM directly, React may not be aware of these changes, leading to potential issues with your application’s state and rendering. • React components have lifecycle methods that allow you to run code at specific points during a component’s life. To use jQuery safely, you should do any DOM manipulation in the componentDidMount and componentDidUpdate lifecycle methods. Let’s take a look at an example of using jQuery to add a simple animation to a React component: import React, { Component } from 'react'; import $ from 'jquery'; class MyComponent extends Component { componentDidMount() { this.animateDiv(); } componentDidUpdate() { this.animateDiv(); } animateDiv() { $('#my-div').animate({ left: '250px', opacity: '0.5', height: '150px', width: '150px', }, 1500); } render() { return ( <div id="my-div" style={{position: 'relative'}}> Animate me! </div> ); } } export default MyComponent; In this example, we use the componentDidMount and componentDidUpdate lifecycle methods to call the animateDiv function, which uses the jQuery animate method to modify the CSS properties of the div with the ID “my-div”. Conclusion While it is possible to use jQuery alongside React, it is generally recommended to use React’s built-in methods for handling DOM manipulation and state management whenever possible. However, if you need to use jQuery for a specific feature or effect, following the steps outlined in this blog post can help you avoid potential issues and ensure that your application behaves as expected.
__label__pos
0.982922
Class: ApplicationController Inherits: ActionController::Base • Object show all Defined in: app/controllers/application_controller.rb Direct Known Subclasses ConcertoConfigController, ConcertoPluginsController, ContentsController, DashboardController, ErrorsController, FeedsController, FieldConfigsController, Frontend::ContentsController, Frontend::FieldsController, Frontend::ScreensController, Frontend::TemplatesController, GroupsController, KindsController, MediaController, MembershipsController, ScreensController, SubmissionsController, SubscriptionsController, TemplatesController, UsersController Instance Method Summary (collapse) Instance Method Details - (Object) after_sign_in_path_for(resource) Redirect the user to the dashboard after signing in. 335 336 337 # File 'app/controllers/application_controller.rb', line 335 def (resource) dashboard_path end - (Object) allow_cors Cross-Origin Resource Sharing for JS interfaces Browsers are very selective about allowing CORS when Authentication headers are present. They require us to use an origin by name, not *, and to specifically allow authorization credentials (twice). 326 327 328 329 330 331 332 # File 'app/controllers/application_controller.rb', line 326 def allow_cors origin = request.headers['origin'] headers['Access-Control-Allow-Origin'] = origin || '*' headers['Access-Control-Allow-Methods'] = '*' headers['Access-Control-Allow-Credentials'] = 'true' headers['Access-Control-Allow-Headers'] = 'Authorization' end - (Object) auth!(opts = {}) Authenticate using the current action and instance variables. If the instance variable is an Enumerable or ActiveRecord::Relation we remove anything that we cannot? from the array. If the instance variable is a single object, we raise CanCan::AccessDenied if we cannot? the object. or raise if empty. Parameters: • opts (Hash) (defaults to: {}) The options to authenticate with. Options Hash (opts): • action (Symbol) The CanCan action to test. • object (Object) The object we should be testing. • allow_empty (Boolean) — default: true If we should allow an empty array. • new_exception (Boolean) — default: true Allow the user to the page if they can create new objects, regardless of the empty status. 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 # File 'app/controllers/application_controller.rb', line 268 def auth!(opts = {}) action_map = { 'index' => :read, 'show' => :read, 'new' => :create, 'edit' => :update, 'create' => :create, 'update' => :update, 'destroy' => :delete, } test_action = (opts[:action] || action_map[action_name]) allow_empty = true if !opts[:allow_empty].nil? allow_empty = opts[:allow_empty] end new_exception = true if !opts[:new_exception].nil? new_exception = opts[:new_exception] end var_name = controller_name if action_name != 'index' var_name = controller_name.singularize end object = (opts[:object] || instance_variable_get("@#{var_name}")) unless object.nil? if ((object.is_a? Enumerable) || (object.is_a? ActiveRecord::Relation)) object.delete_if {|o| cannot?(test_action, o)} if new_exception && object.empty? # Parent will be Object for Concerto, or the module for Plugins. new_parent = self.class.parent class_name = controller_name.singularize.classify new_class = new_parent.const_get(class_name) if new_parent.const_defined?(class_name) new_object = new_class.new if !new_class.nil? return true if can?(:create, new_object) end if !allow_empty && object.empty? fake_cancan = Class.new.extend(CanCan::Ability) message ||= fake_cancan.unauthorized_message(test_action, object.class) raise CanCan::AccessDenied.new(message, test_action, object.class) end else if cannot?(test_action, object) fake_cancan = Class.new.extend(CanCan::Ability) message ||= fake_cancan.unauthorized_message(test_action, object.class) raise CanCan::AccessDenied.new(message, test_action, object.class) end end end end - (Object) check_for_initial_install If there are no users defined yet, redirect to create the first admin user 240 241 242 243 244 245 246 247 248 # File 'app/controllers/application_controller.rb', line 240 def check_for_initial_install #Don't do anything if a user is logged in unless user_signed_in? #if the flag set in the seeds file still isn't set to true and there are no users, let's do our thing if !User.exists? && !ConcertoConfig[:setup_complete] redirect_to new_user_registration_path end end end - (Object) compute_pending_moderation Expose a instance variable counting the number of pending submissions a user can moderate. 0 indicates no pending submissions. 217 218 219 220 221 222 223 224 225 # File 'app/controllers/application_controller.rb', line 217 def compute_pending_moderation @pending_submissions_count = 0 if user_signed_in? feeds = current_user.owned_feeds feeds.each do |f| @pending_submissions_count += f.submissions_to_moderate.count end end end - (Object) current_ability Current Ability for CanCan authorization This matches CanCan's code but is here to be explicit, since we modify @current_ability below for plugins. 18 19 20 # File 'app/controllers/application_controller.rb', line 18 def current_ability @current_ability ||= ::Ability.new(current_accessor) end - (Object) current_accessor Determine the current logged-in screen or user to be used for auth on the current action. Used by current_ability and use_plugin_ability 25 26 27 28 29 30 # File 'app/controllers/application_controller.rb', line 25 def current_accessor if @screen_api @current_accessor ||= current_screen end @current_accessor ||= current_user end - (Object) current_screen current_screen finds the currently authenticated screen based on a cookie or HTTP basic auth sent with the request. Remember, this is only used on actions with the screen_api filter. On all other actions, screen auth is ignored and the current_accessor is the logged in user or anonymous. 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 # File 'app/controllers/application_controller.rb', line 37 def current_screen if @current_screen.nil? unless request.authorization.blank? (user,pass) = http_basic_user_name_and_password if user=="screen" and !pass.nil? @current_screen = Screen.find_by_screen_token(pass) if params.has_key? :request_cookie cookies.permanent[:concerto_screen_token] = pass end end end if @current_screen.nil? and cookies.has_key? :concerto_screen_token token = cookies[:concerto_screen_token] @current_screen = Screen.find_by_screen_token(token) end end @current_screen end - (Object) http_basic_user_name_and_password 56 57 58 # File 'app/controllers/application_controller.rb', line 56 def http_basic_user_name_and_password ActionController::HttpAuthentication::Basic.user_name_and_password(request) end - (Object) precompile_error_catch 120 121 122 123 124 125 126 127 128 129 130 131 132 133 # File 'app/controllers/application_controller.rb', line 120 def precompile_error_catch require 'yaml' concerto_base_config = YAML.load_file("./config/concerto.yml") if concerto_base_config['compile_production_assets'] == true if File.exist?('public/assets/manifest.yml') == false && Rails.env.production? precompile_status = system("env RAILS_ENV=production bundle exec rake assets:precompile") if precompile_status == true restart_webserver() else raise "Asset precompilation failed. Please make sure the command rake assets:precompile works." end end end end - (Model?) process_notification(ar_instance, pa_params, options = {}) Record and send notification of an activity. Parameters: • ar_instance (ActiveRecord<#create_activity>) Instance of the model on which activity is being tracked; for this to work, its class needs to include PublicActivity::Common. • pa_params (Hash) Any information you want to send to PublicActivity to be stored in the params column. This is redundant since you can also include them in the options. • options (Hash) (defaults to: {}) Options to send to PublicActivity like :key, :action, :owner, and :recipient (see rubydoc.info/gems/public_activity/PublicActivity/Common:create_activity). Returns: • (Model, nil) New activity if created successfully, otherwise nil. 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 # File 'app/controllers/application_controller.rb', line 188 def process_notification(ar_instance, pa_params, options = {}) return nil if ar_instance.nil? || !ar_instance.respond_to?('create_activity') options[:params] ||= {} options[:params].merge!(pa_params) unless pa_params.nil? activity = ar_instance.create_activity(options) # form the actionmailer method name by combining the class name with the action being performed (e.g. "submission_update") am_string = "#{ar_instance.class.name.downcase}_#{options[:action]}" # If ActivityMailer can find a method by the formulated name, pass in the activity (everything we know about what was done) if ActivityMailer.respond_to?(am_string) && (options[:recipient].nil? || options[:owner].nil? || options[:recipient] != options[:owner]) #fulfilling bamnet's expansive notification ambitions via metaprogramming since 2013 begin ActivityMailer.send(am_string, activity).deliver #make an effort to catch all mail-related exceptions after sending the mail - IOError will catch anything for sendmail, SMTP for the rest rescue IOError, Net::SMTPAuthenticationError, Net::SMTPServerBusy, Net::SMTPSyntaxError, Net::SMTPFatalError, Net::SMTPUnknownError => e Rails.logger.debug "Mail delivery failed at #{Time.now.to_s} for #{options[:recipient]}: #{e.message}" ConcertoConfig.first.create_activity :action => :system_notification, :params => {:message => t(:smtp_send_error)} rescue OpenSSL::SSL::SSLError => e Rails.logger.debug "Mail delivery failed at #{Time.now.to_s} for #{options[:recipient]}: #{e.message} -- might need to disable SSL Verification in settings" ConcertoConfig.first.create_activity :action => :system_notification, :params => {:message => t(:smtp_send_error_ssl)} end end activity end - (Object) restart_webserver 82 83 84 85 86 87 88 89 90 91 92 93 94 95 # File 'app/controllers/application_controller.rb', line 82 def restart_webserver unless webserver_supports_restart? flash[:notice] = t(:wont_write_restart_txt) return false end begin File.open("tmp/restart.txt", "w") {} return true rescue #generally a write permission error flash[:notice] = t(:cant_write_restart_txt) return false end end - (Object) screen_api Call this with a before filter to indicate that the current action should be treated as a Screen API page. On Screen API pages, the current logged-in screen (if there is one) is used instead of the current user. For non-screen API pages, it is impossible for a screen to view the page (though that may change). 78 79 80 # File 'app/controllers/application_controller.rb', line 78 def screen_api @screen_api=true end - (Object) set_locale 231 232 233 234 235 236 237 # File 'app/controllers/application_controller.rb', line 231 def set_locale if user_signed_in? && current_user.locale != "" session[:locale] = current_user.locale end I18n.locale = session[:locale] || I18n.default_locale end - (Object) set_time_zone(&block) 97 98 99 100 101 102 103 # File 'app/controllers/application_controller.rb', line 97 def set_time_zone(&block) if user_signed_in? && !current_user.time_zone.nil? Time.use_zone(current_user.time_zone, &block) else Time.use_zone(ConcertoConfig[:system_time_zone], &block) end end - (Object) set_version 227 228 229 # File 'app/controllers/application_controller.rb', line 227 def set_version require 'concerto/version' end - (Object) sign_in_screen(screen) 60 61 62 63 # File 'app/controllers/application_controller.rb', line 60 def (screen) token = screen.generate_screen_token! cookies.permanent[:concerto_screen_token]=token end - (Object) sign_out_screen 65 66 67 68 69 70 71 # File 'app/controllers/application_controller.rb', line 65 def sign_out_screen if !current_screen.nil? current_screen.clear_screen_token! @current_screen = nil end cookies.permanent[:concerto_screen_token]="" end - (Object) switch_to_main_app_ability Revert to the main app ability after using a plugin ability (if it was defined). Used by ConcertoPlugin for rendering hooks, and by use_plugin_ability block above. 175 176 177 # File 'app/controllers/application_controller.rb', line 175 def switch_to_main_app_ability @current_ability = @main_app_ability # it is okay if this is nil end - (Object) switch_to_plugin_ability(mod) Store the current ability (if defined) and switch to the ability class for the specified plugin, if it has one. Always call switch_to_main_app_ability when done. Used by ConcertoPlugin for rendering hooks, and by use_plugin_ability block above. 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 # File 'app/controllers/application_controller.rb', line 148 def switch_to_plugin_ability(mod) @main_app_ability = @current_ability @plugin_abilities = @plugin_abilities || {} mod_sym = mod.name.to_sym if @plugin_abilities[mod_sym].nil? begin ability = (mod.name+"::Ability").constantize rescue ability = nil end if ability.nil? # Presumably this plugin doesn't define its own rules, no biggie logger.warn "ConcertoPlugin: use_plugin_ability: "+ "No Ability found for "+mod.name else @plugin_abilities[mod_sym] ||= ability.new(current_accessor) @current_ability = @plugin_abilities[mod_sym] end else @current_ability = @plugin_abilities[mod_sym] end end - (Object) use_plugin_ability(mod, &block) Allow views in the main application to do authorization checks for plugins. 137 138 139 140 141 # File 'app/controllers/application_controller.rb', line 137 def use_plugin_ability(mod, &block) switch_to_plugin_ability(mod) yield switch_to_main_app_ability end - (Boolean) webserver_supports_restart? Returns: • (Boolean) 105 106 107 108 109 110 111 112 113 114 115 116 117 118 # File 'app/controllers/application_controller.rb', line 105 def webserver_supports_restart? #add any webservers that don't support tmp/restart.txt to this array no_restart_txt = ["webrick"] no_restart_txt.each do |w| #check if the server environment contains a webserver that doesn't support restart.txt #This is NOT foolproof - a webserver may elect not to send this server_match = /\S*#{w}/.match(env['SERVER_SOFTWARE'].to_s.downcase) if server_match.nil? return true else return false end end end
__label__pos
0.766083
How to get yesterday date in mysql? by santina.kub , in category: SQL , 2 years ago How to get yesterday date in mysql? Facebook Twitter LinkedIn Telegram Whatsapp 2 answers Member by marina , a year ago @santina.kub you can use SUBDATE() function and subtract 1 day from now to get yesterday's date in MySQL, query: 1 2 -- Output: 2022-09-11 18:12:25 SELECT SUBDATE(NOW(), 1) as yesterday; by jessyca_langosh , 9 months ago @santina.kub  You can use the DATE_SUB() function in MySQL to get yesterday's date. Here's an example query: 1 SELECT DATE_SUB(NOW(), INTERVAL 1 DAY) AS yesterday_date; This query uses the NOW() function to get the current date and time, and then subtracts 1 day from it using the DATE_SUB() function with an interval of 1 day. The result is then aliased as "yesterday_date". Alternatively, you can use the DATE() function to extract just the date portion of the current date and subtract 1 day from it. Here's an example query for that: 1 SELECT DATE(NOW() - INTERVAL 1 DAY) AS yesterday_date; This query subtracts 1 day from the current date using the INTERVAL keyword and the DATE() function is used to extract the date portion only. The result is then aliased as "yesterday_date".
__label__pos
0.981681
  Lesson 3: Tokens, OAuth2 and JWT (legacy stack) 1. Goals Understand what tokens are, why JWT is a solid option and how to set it up with Spring Security. 2. Lesson Notes The relevant module you need to import when you're starting with this lesson is: m6-lesson3 Token Implementations SAML (or the WS* space) - XML based - many encryption and signing options - expressive but you need a pretty advanced XML stack Simple Web Token - joint venture between Microsoft, Google, Yahoo - created as a direct reaction to making a much simpler version of SAML - too simple, not enough cryptographic options (just symetric) JWT (JSON Web Tokens) - the idea is that you are representing the token using JSON (widely supported) - symmetric and asymmetric signatures and encryption - less options/flexibility than SAML but more than SWT - JWT hit the sweet spot and became widely adopted pretty quickly - JWT - an emerging protocol (very close to standardization) JWT structure - a JWT token has 2 parts: 1. Header - metadata - info about algos / keys used 2. Claims - Reserved Claims (issuer , audience, issued at, expiration, subject, etc) - Application specific Claims JWT with Spring Security OAuth For the Authorization Server: - we’re defining the JwtAccessTokenConverter bean and the JwtTokenStore - we’re also configuring the endpoint to use the new converter Note that we're using symmetric signing - with a shared signing key. For the Resource Server: - we should define the converter here as well, using the same signing key Note that we don’t have to because we’re actually sharing the same Spring context in this case. If the Authorization Server would have been a separate app - then we would have needed this converter, configured exactly the same as in the Resource Server. Upgrade Notes As we've already mentioned in the previous lesson, in Spring Boot 2, it is now required to encode passwords. To this end, we should define a PasswordEncoder bean and use it in order to encode the secret when configuring the client in the AuthorizationServerConfiguration class: @Override public void configure(final ClientDetailsServiceConfigurer clients) throws Exception { clients.inMemory() ... .secret(passwordEncoder.encode("bGl2ZS10ZXN0")) ... } and when configuring the UserDetailsService in the ResourceServerConfiguration class: @Bean public AuthenticationProvider authProvider() { final DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); authProvider.setUserDetailsService(userDetailsService); authProvider.setPasswordEncoder(passwordEncoder); return authProvider; } In the lessons, we use the BCryptPasswordEncoder implementation of the PasswordEncoder interface: @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } 3. Resources - jwt.io - Spring Security and Angular JS RwS - Tokens, OAuth2 and JWT - transcript.pdf
__label__pos
0.981125
suscriptores de edHelper - Cree un imprimible nuevo Clave también incluye las preguntas La hoja de respuestas sólo da las respuestas Sin clave de respuestas Not a subscriber?  Sign up now for the subscriber materials! Matemáticas Multiplicación Grade 3 Math Multiplicación This worksheet still contains English. edHelper is working on the translation Name _____________________________ Date ___________________ Multiplicación Resuelve. 1.   While we were camping, we cooked dinner and heated the kettle on the fire. We heard something making a noise in the brush. Then out of the brush came9raccoons wanting to see what was going on. How many raccoon eyes were staring at us? 2.  * Esta es una hoja prehecha. Utilice el enlace arriba de la página para un imprimible. 3.   Each pack of gum has6cards in it. If Makayla bought9packs of gum, how many cards could he add to his collection? 4.   Mackenzie has3file drawers in her office. There are8files in each drawer. How many files does she have? 5.   The fruit that we picked looked very ripe. We picked6bushels of apples. Each bushel cost us $4.00. How much money did we spend on apples? 6.   Alexis sold7rabbits for6dollars each. How much money did Alexis earn by selling her rabbits? 7.   Devin works at the zoo. He fed the moose breakfast, put a loose duck back in the pond, and fed6tigers. He worked5hours. If he is paid9dollars per hour, how much money did he make? 8.   My brother has4friends. Each friend has2pets. How many pets do his friends have in all? Answer Key Sample This is only a sample worksheet. suscriptores de edHelper - Cree un imprimible nuevo Clave también incluye las preguntas La hoja de respuestas sólo da las respuestas Sin clave de respuestas Not a subscriber?  Sign up now for the subscriber materials! Matemáticas Multiplicación Grade 3 Math Multiplicación This worksheet still contains English. edHelper is working on the translation
__label__pos
0.999738
Dataset Dataset[data] represents a structured dataset based on a hierarchy of lists and associations. DetailsDetails • Dataset can represent not only full rectangular multidimensional arrays of data, but also arbitrary tree structures, corresponding to data with arbitrary hierarchical structure. • Depending on the data it contains, a Dataset object typically displays as a table or grid of elements. • Functions like Map, Select, etc. can be applied directly to a Dataset by writing Map[f,dataset], Select[dataset,crit], etc. • Subsets of the data in a Dataset object can be obtained by writing . • Dataset objects can also be queried using a specialized query syntax by writing . • Dataset Structure • While arbitrary nesting of lists and associations is possible, two-dimensional (tabular) forms are most commonly used. • The following table shows the correspondence between the common display forms of a Dataset, the form of Wolfram Language expression it contains, and logical interpretation of its structure as a table: • {{,,}, {,,}, {,,}, {,,}} list of lists a table without named rows and columns {<|"x","y",|>, <|"x","y",|>, <|"x","y",|> } list of associations a table with named columns <|"a"{,}, "b"{,}, "c"{,}, "d"{,}|> association of lists a table with named rows <|"a"<|"x","y"|>, "b"<|"x","y"|>, "c"<|"x","y"|>|> association of associations a table with named columns and named rows • Dataset interprets nested lists and associations in a row-wise fashion, so that level 1 (the outermost level) of the data is interpreted as the rows of a table, and level 2 is interpreted as the columns. • Named rows and columns correspond to associations at level 1 and 2, respectively, whose keys are strings that contain the names. Unnamed rows and columns correspond to lists at those levels. • Rows and columns of a dataset can be exchanged by writing Transpose[dataset]. • Part operations • The syntax or Part[dataset,parts] can be used to extract parts of a Dataset. • The parts that can be extracted from a Dataset include all ordinary specifications for Part. • Unlike the ordinary behavior of Part, if a specified subpart of a Dataset is not present, Missing["PartAbsent",] will be produced in that place in the result. • The following part operations are commonly used to extract rows from tabular datasets: • dataset[["name"]]extract a named row (if applicable) dataset[[{"name1",}]]extract a set of named rows dataset[[1]]extract the first row dataset[[n]]extract the n^(th) row dataset[[-1]]extract the last row dataset[[m;;n]]extract rows m through n dataset[[{n1,n2,}]]extract a set of numbered rows • The following part operations are commonly used to extract columns from tabular datasets: • dataset[[All,"name"]]extract a named column (if applicable) dataset[[All,{"name1",}]]extract a set of named columns dataset[[All,1]]extract the first column dataset[[All,n]]extract the n^(th) column dataset[[All,-1]]extract the last column dataset[[All,m;;n]]extract columns m through n dataset[[All,{n1,n2,}]]extract a subset of the columns • Like Part, row and column operations can be combined. Some examples include: • dataset[[n,m]]take the cell at the n^(th) row and m^(th)column dataset[[n,"colname"]]extract the value of the named column in the n^(th) row dataset[["rowname","colname"]]take the cell at the named row and column • The following operations can be used to remove the labels from rows and columns, effectively turning associations into lists: • dataset[[Values]]remove labels from rows dataset[[All,Values]]remove labels from columns dataset[[Values,Values]]remove labels from rows and columns • Dataset Queries • The query syntax can be thought of as an extension of Part syntax to allow aggregations and transformations to be applied, as well as taking subsets of data. • Some common forms of query include: • dataset[f]apply f to the entire table dataset[All,f]apply f to every row in the table dataset[All,All,f]apply f to every cell in the table dataset[f,n]extract the n^(th) column, then apply f to it dataset[f,"name"]extract the named column, then apply f to it dataset[n,f]extract the n^(th) row, then apply f to it dataset["name",f]extract the named row, then apply f to it dataset[{nf}]selectively map f onto the n^(th) row dataset[All,{nf}]selectively map f onto the n^(th)column • Some more specialized forms of query include: • dataset[Counts,"name"]give counts of different values in the named column dataset[Count[value],"name"]give number of occurences of value in the named column dataset[CountDistinct,"name"]count the number of distinct values in the named column dataset[MinMax,"name"]give minimum and maximum values in the named column dataset[Mean,"name"]give the mean value of the named column dataset[Total,"name"]give the total value of the named column dataset[Select[h]]extract those rows that satisfy condition h dataset[Select[h]/*Length]count the number of rows that satisfy condition h dataset[Select[h],"name"]select rows, then extract the named column from the result dataset[Select[h]/*f,"name"]select rows, extract the named column, then apply f to it dataset[TakeLargestBy["name",n]]give the n rows for which the named column is largest dataset[TakeLargest[n],"name"]give the n largest values in the named column • Descending and Ascending Query Operators • In , the query operators are effectively applied at successively deeper levels of the data, but any given one may be applied either while "descending" into the data or while "ascending" out of it. • The operators that make up a Dataset query fall into one of the following broad categories with distinct ascending and descending behavior: • All,i,i;;j,"key",descendingpart operators Select[f],SortBy[f],descendingfiltering operators Counts,Total,Mean,ascendingaggregation operators Query[],ascendingsubquery operators Function[],fascendingarbitrary functions • A descending operator is applied to corresponding parts of the original dataset, before subsequent operators are applied at deeper levels. • Descending operators have the feature that they do not change the structure of deeper levels of the data when applied at a certain level. This ensures that subsequent operators will encounter subexpressions whose structure is identical to the corresponding levels of the original dataset. • The simplest descending operator is All, which selects all parts at a given level and therefore leaves the structure of the data at that level unchanged. All can safely be replaced with any other descending operator to yield another valid query. • An ascending operator is applied after all subsequent ascending and descending operators have been applied to deeper levels. Whereas descending operators correspond to the levels of the original data, ascending operators correspond to the levels of the result. • Unlike descending operators, ascending operators do not necessarily preserve the structure of the data they operate on. Unless an operator is specifically recognized to be descending, it is assumed to be ascending. • Part Operators • The descending part operators specify which elements to take at a level before applying any subsequent operators to deeper levels: • Allapply subsequent operators to each part of a list or association i;;jtake parts i through j and apply subsequent operators to each part itake only part i and apply subsequent operators to it "key",Key[key]take value of key in an association and apply subsequent operators to it Valuestake values of an association and apply subsequent operators to each value {part1,part2,}take given parts and apply subsequent operators to each part • Filtering Operators • The descending filtering operators specify how to rearrange or filter elements at a level before applying subsequent operators to deeper levels: • Select[test]take only those parts of a list or association that satisfy test SelectFirst[test]take the first part that satisfies test KeySelect[test]take those parts of an association whose keys satisfy test TakeLargestBy[f,n],TakeSmallestBy[f,n]take the n elements for which is largest or smallest, in sorted order MaximalBy[crit],MinimalBy[crit]take the parts for which criteria crit is greater or less than all other elements SortBy[crit]sort parts in order of crit KeySortBy[crit]sort parts of an association based on their keys, in order of crit DeleteDuplicatesBy[crit]take parts that are unique according to crit DeleteMissingdrop elements with head Missing • The syntax can be used to combine two or more filtering operators into one operator that still operates at a single level. • Aggregation Operators • The ascending aggregation operators combine or summarize the results of applying subsequent operators to deeper levels: • Totaltotal all quantities in the result Min,Maxgive minimum, maximum quantity in the result Mean,Median,Quantile,give statistical summary of the result Histogram,ListPlot,calculate a visualization on the result Merge[f]merge common keys of associations in the result using function f Catenatecatenate the elements of lists or associations together Countsgive association that counts occurrences of values in the result CountsBy[crit]give association that counts occurrences of values according to crit CountDistinctgive number of distinct values in the result CountDistinctBy[crit]give number of distinct values in the result according to crit TakeLargest[n],TakeSmallest[n]take the largest or smallest n elements • The syntax can be used to combine two or more aggregation operators into one operator that still operates at a single level. • Subquery Operators • The ascending subquery operators perform a subquery after applying subsequent operators to deeper levels: • Query[]perform a subquery on the result {op1,op2,}apply multiple operators at once to the result, yielding a list <|key1op1,key2op2,|>apply multiple operators at once to the result, yielding an association with the given keys {key1op1,key2op2,}apply different operators to specific parts in the result • When one or more descending operators are composed with one or more ascending operators (e.g. ), the descending part will be applied, then subsequent operators will be applied to deeper levels, and lastly, the ascending part will be applied to the result at that level. • Special Operators • The special descending operator GroupBy[spec] will introduce a new association at the level at which it appears and can be inserted or removed from an existing query without affecting subsequent operators. • Syntactic Sugar • Functions such as CountsBy, GroupBy, and TakeLargestBy normally take another function as one of their arguments. When working with associations in a Dataset, it is common to use this "by" function to look up the value of a column in a table. • To facilitate this, Dataset queries allow the syntax to mean Key["string"] in such contexts. For example, the query operator GroupBy["string"] is automatically rewritten to GroupBy[Key["string"]] before being executed. • Similarly, the expression GroupBy[dataset,"string"] is rewritten as GroupBy[dataset,Key["string"]]. • Query Behavior • Where possible, type inference is used to determine whether a query will succeed. Operations that are inferred to fail will result in a Failure object being returned without the query being performed. • By default, if any messages are generated during a query, the query will be aborted and a Failure object containing the message will be returned. • When a query returns structured data (e.g. a list or association, or nested combinations of these), the result will be given in the form of another Dataset object. Otherwise, the result will be given as an ordinary Wolfram Language expression. • For more information about special behavior of Dataset queries, see the function page for Query. • Exporting Datasets • Normal can be used to convert any Dataset object to its underlying data, which is typically a combination of lists and associations. • Dataset objects can be exported by writing Export["file.ext",dataset] or ExportString[dataset,"fmt"]. The following formats are supported: • "CSV"a comma-separated table of values "TSV"a tab-separated table of values "JSON"a JSON expression in which associations become objects "M"a human-readable Wolfram Language expression "MX"a packed binary protocol • SemanticImport can be used to import files as Dataset objects. ExamplesExamplesopen allclose all Basic Examples  (1)Basic Examples  (1) Create a Dataset object from tabular data: In[1]:= Click for copyable input Out[1]= Take a set of rows: In[2]:= Click for copyable input Out[2]= Take a specific row: In[3]:= Click for copyable input Out[3]= A row is merely an association: In[4]:= Click for copyable input Out[4]= Take a specific element from a specific row: In[5]:= Click for copyable input Out[5]= In[6]:= Click for copyable input Out[6]= In[7]:= Click for copyable input Out[7]= Take the contents of a specific column: In[8]:= Click for copyable input Out[8]= In[9]:= Click for copyable input Out[9]= In[10]:= Click for copyable input Out[10]= Take a specific part within a column: In[11]:= Click for copyable input Out[11]= Take a subset of the rows and columns: In[12]:= Click for copyable input Out[12]= Apply a function to the contents of a specific column: In[13]:= Click for copyable input Out[13]= In[14]:= Click for copyable input Out[14]= In[15]:= Click for copyable input Out[15]= Partition the dataset based on a column, applying further operators to each group: In[16]:= Click for copyable input Out[16]= Apply a function to each row: In[17]:= Click for copyable input Out[17]= Apply a function both to each row and to the entire result: In[18]:= Click for copyable input Out[18]= Apply a function to every element in every row: In[19]:= Click for copyable input Out[19]= Apply functions to each column independently: In[20]:= Click for copyable input Out[20]= Construct a new table by specifying operators that will compute each column: In[21]:= Click for copyable input Out[21]= Use the same technique to rename columns: In[22]:= Click for copyable input Out[22]= Select specific rows based on a criterion: In[23]:= Click for copyable input Out[23]= Take the contents of a column after selecting the rows: In[24]:= Click for copyable input Out[24]= Take a subset of the available columns after selecting the rows: In[25]:= Click for copyable input Out[25]= Take the first row satisfying a criterion: In[26]:= Click for copyable input Out[26]= Take a value from this row: In[27]:= Click for copyable input Out[27]= Sort the rows by a criterion: In[28]:= Click for copyable input Out[28]= Take the rows that give the maximal value of a scoring function: In[29]:= Click for copyable input Out[29]= Give the top 3 rows according to a scoring function: In[30]:= Click for copyable input Out[30]= Delete rows that duplicate a criterion: In[31]:= Click for copyable input Out[31]= In[32]:= Click for copyable input Out[32]= Compose an ascending and a descending operator to aggregate values of a column after filtering the rows: In[33]:= Click for copyable input Out[33]= Do the same thing by applying Total after the query: In[34]:= Click for copyable input Out[34]= Introduced in 2014 (10.0) Translate this page: 




__label__pos
0.982964
Use in-file Javascript with AngularJS and Apache Tiles I have been learning AngularJs and currently have an application that uses Apache Tiles. Prior to adding AngularJs to the application, I had a working piece of code inside my footer tile that calculated the current year that looks like this: footer.html <script type="text/javascript"> var year = new Date().getFullYear(); </script> <tr ng-Controller="AppController"> <td>Created <script>document.write(year)</script> </td> </tr> controller.js var controllers = {}; controllers.AppController = ['$scope', function ($scope) { $scope.currentYear = new Date().getFullYear(); }]; proxy.controller(controllers); app.js var proxy = angular.module('proxy',['ngRoute']) .config(function($routeProvider) { $routeProvider.when('/index',{ templateUrl: 'search.jsp', controller: 'AppController' }); }); The footer now only shows "Created" on the index.html page. Is there a way with angular that I can successfully calculate the year? Why does the JS in this file stop working when AngularJs is added to the application? Answers: Answer Since you're using AngularJS, you can write the code like this: <script type="text/javascript"> angular.module('app', []).controller('YearController', ['$scope', function ($scope) { $scope.currentYear = new Date().getFullYear(); }]); </script> <table ng-app="app"> <tr ng-controller="YearController"> <td> Created {{currentYear}} </td> </tr> </table> Edit: This is how it would look like if it was in it's own separate HTML and JavaScript files. index.html: <!DOCTYPE html > <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.2/angular.js"></script> <script src="app.js"></script> </head> <body ng-app="app"> <div ng-include="'footer.html'"></div> </body> </html> footer.html: <table> <tr ng-controller="YearController"> <td> Created {{currentYear}} </td> </tr> </table> app.js (better to have it's own separate file): var app = angular.module('app', []); var controllers = {}; controllers.YearController = ['$scope', function ($scope) { $scope.currentYear = new Date().getFullYear(); }]; app.controller(controllers); Tags Recent Questions Top Questions Home Tags Terms of Service Privacy Policy DMCA Contact Us ©2020 All rights reserved.
__label__pos
0.913794
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required. Sign up Here's how it works: 1. Anybody can ask a question 2. Anybody can answer 3. The best answers are voted up and rise to the top The dunce cap results from a triangle with edge word $aaa^{-1}$. At the edge, a small neighborhood is homeomorphic to three half-disks glued together along their diameters. How do you prove this is not homeomorphic to a single disk? share|cite|improve this question 2   Why was this downvoted? – J. M. Dec 4 '11 at 5:50      I'm thinking maybe the trick is that (if I'm not mistaken) removing a set homeomorphic to the circle from a disk separates it into no more than two pieces, but can separate the the three glued half-disks into three pieces. Is this a good direction? – dfeuer Dec 4 '11 at 19:26      If that works, you should be able to do it with a segment instead, which might be easier. A similar idea would be to remove a circle from the interior: with the three glued half-disks that can leave a connected set, but by the Jordan curve theorem it has to split a disk. – Brian M. Scott Dec 4 '11 at 20:31      No, the circle (as I thought of it anyway) doesn't work. Interior within what space? – dfeuer Dec 5 '11 at 4:54 1   The interior of the closed nbhd consisting of three closed half-disks glued together. You can embed the circle so that it snakes into each of the ‘pages’, meeting the ‘spine’ three times, and has a path-connected complement. – Brian M. Scott Dec 5 '11 at 16:30 If you have two homotopic maps $f,g: S^1 \to X$, then $X \cup_f D^2$ is homotopy equivalent to $X \cup_g D^2$. You can use this to show that the dunce cap is homotopy equivalent to $D^2$, and thus contractible. Since no closed surface is contractible (using classification of surfaces), the dunce cap is not a surface. $D^2$ is the closed unit disk. By $X \cup_f D^2$, I mean gluing $D^2$ via the map $f: S^1 = \partial D^2 \to X$. This is the quotient space of $X \sqcup D^2$ identifying each point of $\partial D^2$ with its image under $f$ in $X$. So in our specific case, $D^2$ is homeomorphic to $S^1$ glued to $D^2$ under the identity map $S^1 \to S^1$. On the other hand, we have that the dunce cap is constructed by gluing $D^2$ to $S^1$ under the map $g: S^1 \to S^1$ given by $$ g(e^{i\theta}) = \begin{cases} exp(4 i \theta) & 0 \leq \theta \leq \pi/2\\ exp(4 i (2 \theta - \pi)) & \pi/2 \leq \theta \leq 3\pi/2\\ exp(8 i(\pi - \theta)) & 3\pi/2 \leq \theta \leq 2\pi \end{cases}$$ It is not hard to show that $g$ is homotopic to to the identity map, and so (using the result I mentioned above), $D^2$ is homotopy equivalent to the dunce cap. So the dunce cap must be contractible. Edit: I have now realized that the above answers the question in the title, which is not the question posed by the OP. To see that the dunce cap is not homeomorphic to $D^2$, you can simply note that the dunce cap is a disk glued along its boundary (albeit in a strange way), and thus has no 2-dimensional boundary, while $D^2$ does. share|cite|improve this answer      I haven't yet studied algebraic topology, though I do know what homotopic means. Could you explain what you mean by \cup_f and \cup_g? Is D^2 the open or closed unit disk? – dfeuer Dec 7 '11 at 18:22      @dfeuer: I have updated to answer your questions. – Brandon Carter Dec 7 '11 at 18:48      To whomever downvoted, please explain your downvote. – Brandon Carter Dec 7 '11 at 22:05      @BrandonCarter: I casted the downvote, because I feel this proof is ugly and may be wrong. I do not see the need to ask others explain downvoting. Sorry this may be provocative from the perspective that you believe your proof is right, and I totally understood that. – Kerry Dec 7 '11 at 22:48 1   @Changwei: I know that the above proof is correct, especially since it is given as a sequence of exercises in Armstrong's Basic Topology. In general, explaining your downvote helps to improve the quality of answers. I afforded you the courtesy of not downvoting your answer, despite the contractibility of the dunce cap being well-known (and thus incorrectness of your answer). That is a courtesy that I have since rescinded. – Brandon Carter Dec 7 '11 at 22:58 The question is essentially answered in the way that it is posed. No point of a disc has a neighbourhood homeomorphic to three half discs glued along their diameters. The question has been changed since I wrote this reply. In the talk about the topological dunce hat, I have described a simple method of contracting it. share|cite|improve this answer Your Answer   discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged or ask your own question.
__label__pos
0.873834
11 $\begingroup$ I've read somewhere that the reason we square the differences instead of taking absolute values when calculating variance is that variance defined in the usual way, with squares in the nominator, plays a unique role in Central Limit Theorem. Well, then what exactly is the role of variance in CLT? I was unable to find more about this, or understand it properly. We could also ask what makes us think that variance is a measure of how far a set of numbers is spread out. I could define other quantities, similar to variance, and convince you they measure the spread of numbers. For this to happen, you would have to state what exactly is meant by spread of numbers, what behaviour you expect from measure of spread etc. There's no formal definition of spread, thus we may treat variance as the definition. However, for some reason variance is considered 'the best' measure of spread. $\endgroup$ 3 • $\begingroup$ I specifically attempted to answer this question in my response at stats.stackexchange.com/a/3904/919. $\endgroup$ – whuber Commented Sep 1, 2015 at 14:01 • 1 $\begingroup$ Now I remember I've seen your answer before, but the problem is I can't really find the word 'variance' in your answer. Which part exactly explains the problem? Maybe I should read it again. $\endgroup$ Commented Sep 1, 2015 at 15:14 • 3 $\begingroup$ Look for "SD," which is equivalent to variance, and to the term "scale factor." The (rather deep) point here is that the variance itself is not a unique choice: for any given distribution, you may choose (almost) any measure of spread you like! Assuming that measure converges to the spread of the underlying distribution, what really matters is that when you standardize the sum (or mean) of $n$ iid samples from that distribution, you must rescale its spread by a factor that asymptotically is $\sqrt{n}$. In so doing you will achieve a limiting Normal distribution. $\endgroup$ – whuber Commented Sep 1, 2015 at 15:22 4 Answers 4 11 $\begingroup$ The classical statement of the Central Limit Theorem (CLT) considers a sequence of independent, identically distributed random variables $X_1, X_2, \ldots, X_n, \ldots$ with common distribution $F$. This sequence models the situation we confront when designing a sampling program or experiment: if we can obtain $n$ independent observations of the same underlying phenomenon, then the finite collection $X_1, X_2, \ldots, X_n$ models the anticipated data. Allowing the sequence to be infinite is a convenient way to contemplate arbitrarily large sample sizes. Various laws of large numbers assert that the mean $$m(X_1, X_2, \ldots, X_n) = \frac{1}{n}(X_1 + X_2 + \cdots + X_n)$$ will closely approach the expectation of $F$, $\mu(F)$, with high probability, provided $F$ actually has an expectation. (Not all distributions do.) This implies the deviation $m(X_1, X_2, \ldots, X_n) - \mu(F)$ (which, as a function of these $n$ random variables, is also a random variable) will tend to get smaller as $n$ increases. The CLT adds to this in a much more specific way: it states (under some conditions, which I will discuss below) that if we rescale this deviation by $\sqrt{n}$, it will have a distribution function $F_n$ that approaches some zero-mean Normal distribution function as $n$ grows large. (My answer at https://stats.stackexchange.com/a/3904 attempts to explain why this is and why the factor of $\sqrt{n}$ is the right one to use.) This is not a standard statement of the CLT. Let's connect it with the usual one. That limiting zero-mean Normal distribution will be completely determined by a second parameter, which is usually chosen to be a measure of its spread (naturally!), such as its variance or standard deviation. Let $\sigma^2$ be its variance. Surely it must have some relationship to a similar property of $F$. To discover what this might be, let $F$ have a variance $\tau^2$--which might be infinite, by the way. Regardless, because the $X_i$ are independent, we easily compute the variance of the means: $$\eqalign{ \text{Var}(m(X_1, X_2, \ldots, X_n)) &= \text{Var}(\frac{1}{n}(X_1 + X_2 + \cdots + X_n)) \\ &= \left(\frac{1}{n}\right)^2(\text{Var}(X_1) + \text{Var}(X_2) + \cdots + \text{Var}(X_n)) \\ &= \left(\frac{1}{n}\right)^2(\tau^2 + \tau^2 + \cdots + \tau^2) \\ &= \frac{\tau^2}{n}. }$$ Consequently, the variance of the standardized residuals equals $\tau^2/n \times (\sqrt{n})^2 = \tau^2$: it is constant. The variance of the limiting Normal distribution, then, must be $\tau^2$ itself. (This immediately shows that the theorem can hold only when $\tau^2$ is finite: that is the additional assumption I glossed over earlier.) (If we had chosen any other measure of spread of $F$ we could still succeed in connecting it to $\sigma^2$, but we would not have found that the corresponding measure of spread of the standardized mean deviation is constant for all $n$, which is a beautiful--albeit inessential--simplification.) If we had wished, we could have standardized the mean deviations all along by dividing them by $\tau$ as well as multiplying them by $\sqrt{n}$. That would have ensured the limiting distribution is standard Normal, with unit variance. Whether you elect to standardize by $\tau$ in this way or not is really a matter of taste: it's the same theorem and the same conclusion in the end. What mattered was the multiplication by $\sqrt{n}$. Note that you could multiply the deviations by some factor other than $\sqrt{n}$. You could use $\sqrt{n} + \exp(-n)$, or $n^{1/2 + 1/n}$, or anything else that asymptotically behaves just like $\sqrt{n}$. Any other asymptotic form would, in the limit, reduce $\sigma^2$ to $0$ or blow it up to $\infty$. This observation refines our appreciation of the CLT by showing the extent to which it is flexible concerning how the standardization is performed. We might want to state the CLT, then, in the following way. Provided the deviation between the mean of a sequence of IID variables (with common distribution $F$) and the underlying expectation is scaled asymptotically by $\sqrt{n}$, this scaled deviation will have a zero-mean Normal limiting distribution whose variance is that of $F$. Although variances are involved in the statement, they appear only because they are needed to characterize the limiting Normal distribution and relate its spread to that of $F$. This is only an incidental aspect. It has nothing to do with variance being "best" in any sense. The crux of the matter is the asymptotic rescaling by $\sqrt{n}$. $\endgroup$ 0 6 $\begingroup$ Variance is NOT essential to Central Limit Theorems. It is essential to the the garden variety beginner's i.i.d., Central Limit Theorem, the one most folks know and love, use and abuse. There is not "the" Central Limit Theorem, there are many Central Limit Theorems: The garden variety beginner's i.i.d. Central Limit Theorem. Even here, judicious choice of norming constant (so an advanced variant of the beginner's CLT) can allow Central Limit Theorems to be proved for certain random variables having infinite variance (see Feller Vol. II http://www.amazon.com/Introduction-Probability-Theory-Applications-Edition/dp/0471257095 p. 260). The triangular array Lindeberg-Feller Central Limit Theorem. http://sites.stat.psu.edu/~dhunter/asymp/lectures/p93to100.pdf https://en.wikipedia.org/wiki/Central_limit_theorem . The wild world of anything goes everything in sight dependent Central Limit Theorems for which variance need not even exist. I once proved a Central Limit Theorem for which not only variance didn't exist, but neither did the mean, and in fact not even a 1 - epsilon moment for epsilon arbitrarily small positive. That was a hairy proof, because it "barely" converged, and did so very slowly. Asymptotically it converged to a Normal, in reality, a sample size of millions of terms would be needed for the Normal to be a good approximation. $\endgroup$ 2 • $\begingroup$ Is the CLT you proved accessible somewhere on the web? It sounds very interesting, and I would like to read it. $\endgroup$ Commented Sep 19, 2015 at 17:22 • 2 $\begingroup$ It was a homework assignment in a theoretical probability course almost 35 years ago, lost to the times of sand. Well, it might be in one of my boxes somewhere, but I'm not likely to dig it up any time soon. I was barely smart enough to prove it (with many hours of hard slogging), not nearly smart enough to have formulated it. There are infinitely many different Central Limit Theorems, norming is the key. $\endgroup$ Commented Sep 19, 2015 at 17:46 1 $\begingroup$ What is the best measure of spread depends on the situation. Variance is a measure of spread which is a parameter of the normal distribution. So if you models your data with a nornal distribition, the (arithmetic) mean and the empirical variance is the best estimators (they are "sufficient") of the parameters of that normal distribution. That also gives the link to the central limit theorem, since that is about a normal limit, that is, the limit is a normal distribution. So if yoy have enough observations that the central limit theorem is relevant, again you can use the normal distribution, and the empirical variance is the natural description of variability, because it is tied to the normal distribution. Without this link to the normal distribution, there is no sense in which the varoiance is best or even a natual descriptor of variability. $\endgroup$ 1 • $\begingroup$ It is unclear why the theory of "best" estimators (in any sense of "best") should have any connection with the central limit theorem. If one were to use a non-quadratic loss function, for instance, then mean and variance might not be "best" estimators of a normal distribution's parameters--instead, the median and IQR might be best. $\endgroup$ – whuber Commented Sep 1, 2015 at 14:03 1 $\begingroup$ Addressing the second question only: I guess that variance has been the dispersion measure of choice for most of the statistician mainly for historical reasons and then because of inertia for most of non statistician practitioners. Although I cannot cite by heart a specific reference with some rigorous definition of spread, I can offer heuristic for its mathematical characterization: central moments (i.e., $ E[(X-\mu)^k]$) are very useful for weighing deviations from the distribution's center and their probabilities/frequencies, but only if $k$ is integer and even. Why? Because that way deviations below the center (negative) will sum up with deviations above the center (positive), instead of partially canceling them, like average does, for instance. As you can think, absolute central moments (i.e., $E(|X-\mu|^k)$) can also do that job and, more, for any $k>0$ (ok, both moments are equal if $k$ is even). So a large amount of small deviations (both positive and negative) with few large deviations are characteristics of little dispersion, which will yield a relatively small even central moment. Lots of large deviations will yield a relatively large even central moment. Remember when I said about the historical reasons above? Before computational power became cheap and available, one needed to rely only on mathematical, analytical skills to deal with the development of statistical theories. Problems involving central moments were easier to tackle than ones involving absolute central moments. For instance, optimization problems involving central moments (e.g., least squares) require only calculus, while optimization involving absolute central moments with $k$ odd (for $k=1$ you get a simplex problem), which cannot be solved with calculus alone. $\endgroup$ Your Answer By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy. Not the answer you're looking for? Browse other questions tagged or ask your own question.
__label__pos
0.909893
cron task to restart Hi all, I want to write a cron task to restart nuxeo each week. For that I have write a script called by the cron task. When I execute the script myself, it works fine… But, when the script is executed by the cron task, all services (postgres, apache and shibboleth) are correctly restarted but not nuxeo. It's stopped but not restarted. Do you have any idea ? The cron task is executed as root user : # Arret Apache /Doc/apps/apache2/bin/apachectl stop # Arret Shibboleth (il y a p.e mieux ?) pkill -x shibd # Arret Postgres /etc/init.d/postgresql-9.5 stop # Arret Nuxeo export JAVA_HOME=/Doc/apps/jdk1.8.0_73/ export LPATH=`/bin/cat /Doc/apps/PATH` export PATH=${LPATH}:${JAVA_HOME}/bin:${PATH} export NUXEO_CONF=/Doc/apps/ulr-config-nuxeo-71/nuxeo.conf /Doc/apps/nuxeo-cap-7.10-tomcat/bin/nuxeoctl stop # Demarrage Postgres export PGDATA=/Doc/Postgresql/9.5/data /etc/init.d/postgresql-9.5 start # Demarrage Nuxeo export LD_LIBRARY_PATH=/Doc/apps/shibboleth-sp/lib:/Doc/apps/apache2/lib:$LD_LIBRARY_PATH /Doc/apps/nuxeo-cap-7.10-tomcat/bin/nuxeoctl start # Lancement de shibboleth-sp /Doc/apps/shibboleth-sp/sbin/shibd -fc /Doc/apps/shibboleth-sp/etc/shibboleth/shibboleth2.xml # Lancement Apache /Doc/apps/apache2/bin/apachectl start 0 votes 0 answers 1670 views ANSWER
__label__pos
0.652342
This project has moved and is read-only. For the latest updates, please go here. 4 Vote Slash not properly parsed in attribute names description When parsing the following string: <img\onerror="alert()" src="ok"> HAP understands: <img nerror="alert()" src="ok"> while broser do undersantd <img onerror="alert()" src="ok"> Is it possible to change the parser to match more closely browser behavior? comments
__label__pos
0.744472
[FFmpeg-trac] #5222(undetermined:new): ffmpeg crashing for large “-filter_complex_script” inputs FFmpeg trac at avcodec.org Sun Feb 7 21:29:58 CET 2016 #5222: ffmpeg crashing for large “-filter_complex_script” inputs -------------------------------------+------------------------------------- Reporter: jsniff | Type: defect Status: new | Priority: important Component: | Version: undetermined | unspecified Keywords: ffmpeg, | Blocked By: video, crash | Reproduced by developer: 0 Blocking: | Analyzed by developer: 0 | -------------------------------------+------------------------------------- We're experiencing an issue where ffmpeg seg faults for very large "-filter_complex_script" input files (roughly 3MB). The input file consists of a very large number of drawbox filters. The same processing pipeline works fine for smaller files, but seems to have an issue as the file size increases. Is there a hard limit to how large this file can be? If so, is there a "magic number" somewhere that we can increase and re- compile from source? Does anyone have any other thoughts or advice? Thanks in advance! -- Ticket URL: <https://trac.ffmpeg.org/ticket/5222> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker More information about the FFmpeg-trac mailing list
__label__pos
0.906824
Skip to Content 0 SCP IS - Rolling updates Dec 12, 2017 at 08:47 AM 46 avatar image Hi All, My query is on the Rolling software upgrades in SCP IS (HCI). Can anyone help with the following : 1. How are the upgrades handled in a Production System? 2. Do we get a notification from SAP before before the upgrades are done in a tenant? What is the window period? 3. Does it go through Dev-QA-Production cycle? 4. Is there any standard documentation available which highlights the process I have gone through the following blogs : https://blogs.sap.com/2015/01/13/rolling-software-updates-of-hci-pi/ https://blogs.sap.com/2015/01/13/failover-and-scalability-of-hci-pi/ Regards, Ramya Iyer 10 |10000 characters needed characters left characters exceeded * Please Login or Register to Answer, Follow or Comment. 2 Answers Carlos Weissheimer Dec 13, 2017 at 04:52 PM 0 Hello, Please refer the documentation below: https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/06474e8ede674f2094bfe6250fe1afa1.html Best Regards, Carlos Weissheimer Share 10 |10000 characters needed characters left characters exceeded Morten Wittrock Dec 14, 2017 at 02:01 PM 0 Hi Ramya Basically, the updates are pushed to you, usually (but not necessarily always) on a monthly basis. You do not have the option of postponing or skipping an update. You might want to look into the regression test service that SAP offers for Cloud Integration. With the regression test service, you can choose a number of integration flows, and provide SAP with sample input and output documents. SAP will then proceed to run your integration flow in an upgraded internal test environment. If the regression test fails (i.e. given the provided input, the output does not match the output provided by the customer), SAP will not push the update to the live environment. Keep in mind that this is an additional, paid service; it is not part of the subscription. Regards, Morten Share 10 |10000 characters needed characters left characters exceeded
__label__pos
0.652789
 Python: Check whether two lists are circularly identical - w3resource w3resource Python: Check whether two lists are circularly identical Python List: Exercise - 26 with Solution Write a python program to check whether two lists are circularly identical. Python: Check whether two lists are circularly identical Sample Solution:- Python Code: list1 = [10, 10, 0, 0, 10] list2 = [10, 10, 10, 0, 0] list3 = [1, 10, 10, 0, 0] print('Compare list1 and list2') print(' '.join(map(str, list2)) in ' '.join(map(str, list1 * 2))) print('Compare list1 and list3') print(' '.join(map(str, list3)) in ' '.join(map(str, list1 * 2))) Sample Output: Compare list1 and list2 True Compare list1 and list3 False Flowchart: Flowchart: Check whether two lists are circularly identical Visualize Python code execution: The following tool visualize what the computer is doing step-by-step as it executes the said program: Python Code Editor: Have another way to solve this solution? Contribute your code (and comments) through Disqus. Previous: Write a Python program to select an item randomly from a list. Next: Write a Python program to find the second smallest number in a list. What is the difficulty level of this exercise?  Inviting useful, relevant, well-written and unique guest posts
__label__pos
0.978686
How to change Language-fortran package colors? Hi! I’m using the language-fortran package 2.1.7. How could I change the color of syntax highlighting? There are colors that are a bit visually annoying. Thanks for your help. There’s a crucial difference between the grammar (provided by language-fortran in this case) and the color theme. The former defines the syntax, e.g. which is a variable, keyword, function name. But it’s the theme that colors that, e.g. make all variables red, function names blue. That said, you need to find a different color theme. Thanks idelberg for your response. I could not find any options to set the color theme in settings of language-fortran. Would you please tell me where I might set it? The theme is for everything (well, there’s a UI and a Syntax theme), and can be changed in the Settings ➔ Theme tab. Thanks! I found my favorite theme! It’s perfect.
__label__pos
0.939221
Ask your own question, for FREE! Mathematics OpenStudy (anonymous): Breann solved the system of equations below. What mistake did she make in her work? 2x + y = 5 x − 2y = 10 y = 5 − 2x x − 2(5 − 2x) = 10 x − 10 + 4x = 10 5x − 10 = 10 5x = 20 x = 4 2(4) + y = 5 y = −3 She should have substituted 5 + 2x She combined like terms incorrectly, it should have been 4x instead of 5x She subtracted 10 from both sides instead of adding 10 to both sides She made no mistake OpenStudy (turingtest): I see no mistakes OpenStudy (anonymous): agreed OpenStudy (anonymous): Sorry, that is no answer. The real answer here is that you should plug the values of x and y in the original equations and see if the two equations satisfy. If they do, then there is no mistake. That is the ONLY way to confirm there is no mistake. OpenStudy (anonymous): So, plug in x = 4 and y = -3 in the original two equations. Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours! Join our real-time social learning platform and learn together with your friends! Latest Questions jojomojo: what is the best paraphrase of the first stanza the olympic swimmer 6 minutes ago 0 Replies 0 Medals oweifjwoijf: history help (only for lolitapapponettii) 56 minutes ago 6 Replies 0 Medals bruhman7624: don't do anything with this im just doing random stuff 50 minutes ago 8 Replies 1 Medal bruhman7624: who said e=mc squared? 1 hour ago 1 Reply 0 Medals olivia14: Can someone summarize this for me? 44 minutes ago 3 Replies 0 Medals unknown66: 3x-10 1 hour ago 5 Replies 0 Medals Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours! Join our real-time social learning platform and learn together with your friends!
__label__pos
0.703576
Masatoshi Nishiguchi Software Engineer Simple custom grid system css I just wanted to create a simple reusable CSS grid system without using Bootstrap. Using Flexbox, I was able to accomplish it quite easily. NOTE: The code is not tested. Stylesheet This example is written in SCSS. @mixin column($percentage-width) { flex: 0 0 ($percentage-width); max-width: ($percentage-width); /* IE11 */ } // This is equivalent of Bootstrap row. .row { display: flex; flex-wrap: wrap; } // Basic configuration of columns. .col { h1, h2, h3, h4, p { // Add ellipsis in case of text overflowing. width: 100%; overflow: hidden; text-overflow: ellipsis; } // The offset spacer. &.offset { height: 0; } } // Columns in various widths. .col.col-1-3 { @include column(100% / 3 * 1); } .col.col-2-3 { @include column(100% / 3 * 2); } .col.col-1-4 { @include column(100% / 4 * 1); } .col.col-2-4 { @include column(100% / 4 * 2); } .col.col-3-4 { @include column(100% / 4 * 3); } .col.col-1-5 { @include column(100% / 5 * 1); } .col.col-2-5 { @include column(100% / 5 * 2); } .col.col-3-5 { @include column(100% / 5 * 3); } .col.col-4-5 { @include column(100% / 5 * 4); } // For smaller devices, stretch all the columns to 100%. @media (max-width: 768px) { .col { flex: 0 0 100% !important; max-width: 100% !important; /* IE11 */ } } Usage This example is written with Rails and the Slim template engine. .row .col.col-1-3 .user-info h1 = gravatar_for @user = @user.name .col.col-2-3 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. .row .col.col-1-5.offset .col.col-3-5 h1 Sign up = simple_form_for(@user) do |f| = render 'shared/error_messages' = f.input :name, error: false = f.input :email, error: false = f.input :password, error: false = f.input :password_confirmation, error: false, label: false, \ placeholder: "password confirmation" = f.submit "Create my account", class: "btn" Reference
__label__pos
0.999323
Clio + SimpleTexting Integrations In a matter of minutes and without a single line of code, Zapier allows you to automatically send info between Clio and SimpleTexting. How Clio + SimpleTexting Integrations Work 1. Step 1: Authenticate Clio + SimpleTexting. (30 seconds) 2. Step 2: Pick one of the apps as a trigger, which will kick off your automation. (15 seconds) 3. Step 3: Choose a resulting action from the other app. (15 seconds) 4. Step 4: Select the data you want to send from one app to the other. (2 minutes) 5. That’s it! More time to work on other things. Connect Clio + SimpleTexting
__label__pos
0.983208
Questions on the construction and manipulation of sparse arrays in Mathematica, with functions like SparseArray[] and Band[]. learn more… | top users | synonyms 3 votes 0answers 87 views Efficient storage of Kronecker sum of circulant matrices+diagonal matrix I have a square matrix of the form $$M=D+\overset{N}{\underset{n=1}\bigoplus}R_n,$$ where $R_n$ are circulant matrices, $D$ is a diagonal matrix and $\oplus$ is Kronecker sum. Its size is quite big, ... 3 votes 1answer 116 views Opposite function to Normal Is there any function opposite to Normal? For example, let as say that I have an SparseMatrix A, then, let as say that for convenience for a certain operation like Packing, I convert it into an Array ... 4 votes 2answers 218 views Upsampling matrix by inserting zeros inbetween elements I want to essentially take an image with $n \times n$ pixels and expand it into a sparse array, spacing out the pixels by a factor $2$ or $3$. Each pixel in the input image occupies one of the corners ... 9 votes 2answers 217 views Additive SparseArray Assembly The goal is to assemble a SparseArray in an additive fashion. Let us assume we have a large List of indices (some will be ... 1 vote 3answers 109 views ArrayRules for a ragged list Let there be a sample list as , l = {a, {{b, c}}, {d, e}, {f}, {{g, {y}, u, h}, {{{{k, j}}}}},k, {{{{q}, {w}, {r}, {x}}}}}; ArrayRules[l] ArrayRules::rect: ... 2 votes 1answer 211 views How to create a SparseArray satisfying multiple conditions on Parts and Elements of a Matrix? I have a matrix m1 of size $3 \times 19$. Rows $1$, $2$ and $3$ represent $3$ different groups, and columns represent $4$ different blocks: block1 - columns $1$, ... 4 votes 3answers 407 views SparseArray row operations Given a large (very) sparse matrix, A, how can I efficiently "operate" on only the nonzeros in a given row? For example: For each row in A, generate a list of column indices that have a magnitude ... 3 votes 0answers 97 views Det and MatrixRank freezes on SparseArray with nonzero default value Bug introduced in 7.0 or earlier and fixed in 9.0.1 or earlier Why does the following simple code never come to an end (at least with version 8) ... 4 votes 1answer 136 views Assigning Sequence to Part of a SparseArray (bug?) Part ▪ You can make an assignment like t[[spec]]=value to modify any part or sequence of parts in an expression. ▪ If ... 0 votes 1answer 249 views Is it in general faster to get the eigenvectors and eigenvalues of a dense array rather than a sparse array? I always thought that things in general go faster when working with sparse array but, I got this: Eigenvalues::arhm: Because finding 144 out of the 144 ... 5 votes 1answer 97 views How to relate memory usage with occupied positions of SparseArrays? What is the relation of memory usage of a SparseArray and the number of its occupied positions? Let's say you build a 100.000.000 by 10 element SparseArray. And fill the two position 1/1 and ... 1 vote 0answers 43 views How to estimate system recource usage of a SparseArray? [duplicate] Build a 100.000.000 by 10 element SparsArray. Fill position 1/1 and 100.000.000/10 with a value 999.999.999.999.999. ... 2 votes 1answer 213 views How to combine SparseArray and If Because I am dealing with huge matrixes, my computer can not handle it, because of the memory. But, in my matrix, a very small percentage of the elements are non-zero. So I should use SparseArray as ... 1 vote 1answer 333 views How to store a SparseArray? [duplicate] How to Export/Write a SparseArray? How to Import/Read a SparseArray? Is it always stored as a normal array? How can it be stored in a dense form? Is a numerical SparseArray different to Export/Import ... 2 votes 3answers 421 views Dynamically filling matrix with a[[n,m]] = 1/a[[m,n]] I'm building a square matrix, with 1s on the diagonal and elements in U the inverse of elements in L, which are random integers drawn from the sequence 1, ..., 9. Given the nature of the problem I ... 6 votes 0answers 180 views Calculating the rank of a huge sparse array By virtue of the suggestion in my previous question, I constructed the sparse matrix whose size is $518400 \times 86400$, mostly filled with $0$ and $\pm 1$. Now I want to calculate its rank. Since ... 15 votes 6answers 714 views Matrix Rotation If I have a matrix of any size, say $\begin{pmatrix} 72 & 32 & 64 \\ 18 & 8 & 16 \\ 63 & 28 & 56 \\ \end{pmatrix}$ $\begin{pmatrix} 72 & 32 \\ 18 & 8 \\ 63 ... 5 votes 1answer 188 views Why is Flattening a CoefficientArray so slow? I have a vector of $n$ degree $n$ polynomials in $(x,y,z)$, each of whose coefficients is an inhomogenous linear expression in $3 n^2$ variables. I want to write down the linear equations in these $3 ... 3 votes 1answer 512 views How to get the determinant and inverse of a large sparse symmetric matrix? For example, the following is a $12\times 12$ symmetric matrix. Det and Inverse take too much time and don't even work on my ... 9 votes 2answers 366 views Speed up 4D matrix/array generation I have to fill a 4D array, whose entries are $\mathrm{sinc}\left[j(a-b)^2+j(c-d)^2-\phi\right]$ for a fixed value of $\phi$ (normally -15) and a fixed value of $j$ (normally about 0.00005). The way ... 5 votes 1answer 215 views Summing tensors in mathematica How do I perform the following summation in mathematica? \begin{equation} \Sigma_{m=1}^5 e_{ijklm}A^{mn} \end{equation} I have the $e_{ijklm}$ tensor of rank 5 in 5 dimension as a array and $A^{mn}$ ... 1 vote 1answer 754 views Import Excel sheet into 3D array? I have an excel spreadsheet that I would like to plot in a 3D graph using mathematica. The X and Y values are the location of the cell, and the Z value is the number of the scale. How can I import ... 6 votes 1answer 326 views How to create a large sparse block matrix I need to generate a very large sparse block matrix, with blocks consisting only of ones along the diagonal. I have tried several ways of doing this, but I seem to always run out of memory. The ... 15 votes 1answer 344 views Adding three integer sparse matrices is very slow. Adding only two is fast Bug introduced in 9.0.0 and fixed in 10.0.0 Adding more than two sparse matrices in one step in Mathematica 9 is very slow (in fact I couldn't even wait for it to finish). Here's an example. ... 5 votes 2answers 356 views How to interpret the FullForm of a SparseArray? SparseArrays are atomic objects, but they do have a FullForm which reveals information about them. What is the meaning of the ... 11 votes 1answer 2k views How to work around Mathematica hanging when showing a large SparseArray? Bug introduced in 9.0 and fixed in 9.0.1 In Mathematica 9, if I display any large SparseArray object in the default way (which looks something like ... 5 votes 1answer 221 views What's wrong with this code to create a matrix? Here is my code: ... 10 votes 1answer 735 views Sparse convolution of sparse arrays The documentation for ListConvolve mentions that "ListConvolve works with sparse arrays", which is true. The result, however is never sparse, eg: ... 9 votes 2answers 488 views Using ReplaceAll on SparseArray I'm using SparseArray in a notebook in which I am doing complex conjugation manually, i.e. writing $\sqrt{-1}$ as i and applying ... 10 votes 2answers 561 views Speeding up construction of simple tridiagonal matrix I have the following code to construct a tridiagonal matrix: ... 3 votes 1answer 256 views Efficiently importing XPM matrix data into Mathematica The XPM file format is an image file format. Although it is primarily intended for icon pixmaps, it can also be used to store matrix data. For example, the GROMACS chemical simulation package uses ... 8 votes 1answer 1k views Exporting a Large Multidimensional Sparse Array I'm trying to export a sparse array from Mathematica to share with collaborators who primarily use Matlab. The sparse array in question is 4 dimensional, (72 x 93 x 94 x 172) with ~4M non-zero ... 3 votes 3answers 400 views Support for Compressed Sparse Column sparse matrix representation Is there native support for Compressed Sparse Column (CSC) format for sparse matrices, like importing and manipulating them? 22 votes 2answers 1k views Using the Krylov method for Solve: Speeding up a SparseArray calculation I'm trying to implement this Total Variation Regularized Numerical Differentiation (TVDiff) code in MMA (which I found through this SO answer): essentially I want to differentiate noisy data. The full ... 8 votes 2answers 723 views Efficient by-element updates to SparseArrays I have a very large SparseArray called A. What is the most efficient way to update say element ... 16 votes 3answers 976 views Efficient way to combine SparseArray objects? I have several SparseArray objects, say sa11, sa12, sa21, sa22, which I would like to combine into the equivalent of {{sa11, sa12}, {sa21, sa22}}. As an example, I ...
__label__pos
0.784108
Android Question Why does IncludeTitle make app act differently? doogal Member Licensed User Why does an app act differently when IncludeTitle is turned off. When this is true the app runs perfectly. I am getting the following error: An error has occured in sub: java.lang.NullPointerException. I now want to turn the application title off and its giving me a fit. The EditText looks different and when I type in the EditText(search box) it says object not initialized when it is.   eps Expert Licensed User Check the logs, if you can't find anything meaningful in there generate the code with trace and see if it gives you a meaningful one that you can track down. ETA : Is this on a device or AVD? Is it generated the same way? i.e. Debug Rapid, Debug Legacy, etc..?   Upvote 0 doogal Member Licensed User I found the line that is throwing the error: bar.Initialize("bar") (Debug Legacy) it stops here every time. I tried on both device and AVD. Device gives the An error has occured in sub: java.lang.NullPointerException and AVD gives Sorry! The application has stopped unexpectedly. Please try again. This is with release mode. This works when application title is true, but now that I want to turn it off its broken.   Upvote 0 Top
__label__pos
0.980259
Understanding SQL Ranking Functions: ROW_NUMBER, RANK, and DENSE_RANK In the realm of SQL databases, ranking functions are indispensable tools for categorizing and sequencing data. Whether you’re a data analyst, business intelligence specialist, or a developer, you may find yourself in scenarios that require ranking data based on certain conditions. Among these functions, ROW_NUMBER, RANK, and DENSE_RANK stand out due to their functionality and wide application. This article dives deep into these three key SQL ranking functions, delineating their differences and demonstrating how to use them effectively. TOC Understanding Ranking Functions in SQL Ranking functions in SQL are special kinds of window functions that assign a unique rank or number to each row within a dataset, usually relative to some criteria specified in the function call. These functions can be particularly useful in tasks such as identifying top performers, analyzing trends, and segmenting data. General Syntax Before delving into the specifics of each function, let’s take a brief look at their general syntax. Typically, these functions use the following structure: SELECT function_name() OVER (ORDER BY column_name) FROM table_name; ROW_NUMBER ROW_NUMBER is a ranking function that assigns a unique integer to each row within the result set based on the ORDER BY clause. The numbering starts from 1 and increases by one for each subsequent row, irrespective of whether the values in the sorted column are identical or not. Usage Here is how to use the ROW_NUMBER function: SELECT ROW_NUMBER() OVER (ORDER BY column_name) AS Row, column_name FROM table_name; Example Consider a table named ‘Employees’ with the following data: EmployeeIDNameSalary 1John45000 2Emily52000 3Michael45000 Table1: Employees Table When you use ROW_NUMBER with this data, each row gets a unique number regardless of duplicate salary values. RANK Unlike ROW_NUMBER, the RANK function provides the same rank for rows with identical values. It leaves gaps between the ranks when it encounters duplicate values. Usage Here’s how you can use the RANK function: SELECT RANK() OVER (ORDER BY column_name) AS Rank, column_name FROM table_name; Example Using the RANK function on the ‘Employees’ table, rows with the same ‘Salary’ value would get the same rank, and the next row would be assigned the rank number that is incremented by the number of tied ranks. DENSE_RANK DENSE_RANK is similar to RANK, but it does not leave any gaps between rank values when duplicate values are found. Usage Here’s the syntax for DENSE_RANK: SELECT DENSE_RANK() OVER (ORDER BY column_name) AS DenseRank, column_name FROM table_name; Example Applying DENSE_RANK to the ‘Employees’ table will assign the same rank for identical ‘Salary’ values, but unlike RANK, it will not leave any gaps. Comparative Analysis Understanding the nuanced differences between ROW_NUMBER, RANK, and DENSE_RANK can be pivotal for efficient data manipulation. FunctionUnique RankGaps ROW_NUMBERYesNo RANKNoYes DENSE_RANKNoNo Table2: Comparative Analysis Conclusion SQL ranking functions are vital tools for data analysis and manipulation. In this article, we have dissected the use-cases, syntax, and intricacies of ROW_NUMBER, RANK, and DENSE_RANK. While ROW_NUMBER assigns a unique integer value to each row, RANK and DENSE_RANK offer more nuanced ranking capabilities that account for duplicate values. Deciding which one to use ultimately depends on your specific needs and the nature of your dataset. TOC
__label__pos
0.998131
关于cg中的修饰符关键字in out inout的区别, 网上的大致描述如下: 参数传递是指:函数调用实参值初始化函数形参的过程。在 C\C++中,根据形参值的改变是否会导致实参值的改变,参数传递分为“值传递(pass-by-value) ” 和“引用传递(pass-by-reference) ”。按值传递时,函数不会访问当前调用的实参,函数体处理的是实参的拷贝,也就是形参,所以形参值的改变不会影响实参值;引用传递时,函数接收的是实参的存放地址,函数体中改变的是实参的值。 C\C++ 采取指针机制构建引用传递,所以通常引用传递也称为“指针传递”。Cg 语言中参数传递方式同样分为“值传递”和“引用传递”,但指针机制并不被 GPU 硬件所支持,所以 Cg 语言采用不同的语法修辞符来区别“值传递”和“引用传递”。这些修辞符分别为: in: 修辞一个形参只是用于输入,进入函数体时被初始化,且该形参值的改变不会影响实参值,这是典型的值传递方式。 out: 修辞一个形参只是用于输出的,进入函数体时并没有被初始化,这种类型的形参一般是一个函数的运行结果; inout: 修辞一个形参既用于输入也用于输出,这是典型的引用传递。 于是写了一段测试程序, 只在红色通道上输出uv的u值 #pragma vertex vert #pragma fragment frag struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; return o; } fixed4 frag (v2f i) : SV_Target { return fixed4(i.uv.x,0,0,1); } 在unity里运行可以看到的效果如下: 现在代码作如下修改, float test(in float x) { x = clamp(x * 2,0,1); return x; } fixed4 frag (v2f i) : SV_Target { i.uv.x = test(i.uv.x); return fixed4(i.uv.x,0,0,1); } 运行结果: test() 函数去掉关键字修饰符in, 发现运行效果跟上图一致。 这说明in 是pass with value。 参数是拷贝过去的, 在实际操作的过程中in可以不写。 这时我们把test里的in改为out 发现编译器报错, error内容如下: variable 'x' used without having been completely initialized 报错提示x没有初始化,于是我们再次修改为test函数如下: void test(out float x) { x=0.2; x = clamp(x * 2,0,1); } fixed4 frag (v2f i) : SV_Target { test(i.uv.x); return fixed4(i.uv.x,0,0,1); } error消除,此时test需要给x一个初始化的值,而且test此时并没有返回值,运行的结果也传递给外部。运行效果如下, 接着测试inout,此时去掉test的x的初始值,作如下修改: void test(inout float x) { x = clamp(x * 2,0,1); } 运行结果如下图: 说明inout就是引用,即pass with reference。
__label__pos
0.975187
www.pug-cs.ru JOB DESCRIPTION OF A DATABASE ADMINISTRATOR erp application developer job description apply for jobs in dubai airport manpower gov om job application word processor job in modesto job in private bank 2013 pr week job uk craigslist chicago pr jobs Job description of a database administrator Job Description. Monitoring system performance and identifying problems that arise. Responding in a timely manner to user-reported errors. Protecting the database against threats or unauthorized access. Ensuring that the database is adequately backed up and able to be recovered in the event of memory loss. Reporting on metrics regarding usage. WebJun 22,  · Universally, these professionals help store and manage data, but their duties and responsibilities may extend to several other areas, such as: Extracting and/or . WebImplements and monitors database access and configurations. Being a Database Administrator I resolves database performance and capacity issues. Performs . Database Administrators Job Description Job Description of a Database Administrator A database administrator analyzes data by interacting with computer software and hardware to process information. WebSep 17,  · Database administrators (DBAs) have a variety of duties and tasks, such as the following: Responsibility for the evaluation of database software purchases, . Database Administrator job profile Database Administrator (DBA) are generally responsible for the performance, integrity and security of databases. They are. A database developer/database administrator specializes in designing and developing database programs and systems, maintaining and updating them regularly. They. Aug 16,  · What is a DBA? Short for database administrator, a DBA designs, implements, administers, and monitors data management systems and ensures design, consistency, quality, and security. According to SFIA 8, database administration involves the installing, configuring, monitoring, maintaining, and improving the performance of databases and data stores. Database Administration Manager manages the administration of an organization's database. Analyzes the organization's database needs and develops a long-term strategy for data storage. Being a Database Administration Manager establishes policies and procedures related to data security and integrity and monitors and limits database access as needed. Database administrator job description. Candidates for the database administration role need a strong information technology foundation in database structure, configuration, installation and practice. Employers seek individuals with knowledge and experience in major relational database languages and applications, such as Microsoft SQL Server. Code, monitor and tune database objects for optimal performance. Perform capacity planning, usage forecasting and in-depth technical review. Provide support for. A Database Administrator, or Database Manager, is responsible for managing computer systems that store and organise data for companies. Their duties include creating and maintaining a relationship with customers, securing data and identifying areas for improvement with the infrastructure. Database Administrator duties and responsibilities. Build your own Database Administrator job description using our guide on the top Database Administrator skills, education, experience and more. Post your Database Administrator job today. Job Description. Monitoring system performance and identifying problems that arise. Responding in a timely manner to user-reported errors. Protecting the database against threats or unauthorized access. Ensuring that the database is adequately backed up and able to be recovered in the event of memory loss. Reporting on metrics regarding usage. Mar 01,  · Database administrators must also possess some general, less-quantifiable strengths, and skills, often referred to as "soft skills." Communication, organization, and problem-solving prove useful in almost any position. Companies making data-driven decisions particularly appreciate candidates with analytics and business acumen. The Application Database Administrator is to be responsible for all aspects of the usage of databases in the logical realm. Some of these responsibilities. WebImplements and monitors database access and configurations. Being a Database Administrator I resolves database performance and capacity issues. Performs . Apr 25,  · Database administrators need a bachelor’s degree in computer or information science and for the most part, prior work experience is required. Their median salary is $87, dollars. Full-time work with regular hours exceeding 40 per work is the norm. Database Administrator Job Description for Resume – Responsibilities. Top 20 Database Administrator Interview Questions and Answers for 2022 Oct 02,  · It is the data administrator's responsibility to implement and execute data mining projects and makes reports to provide understanding into sales, marketing, and purchasing opportunities and business trends. The role would also include updating information to the company's database and official company website. A database administrator uses software to store and organize data, such as financial information and customer shipping records. They make sure that data is. Oct 02,  · A senior database administrator is in charge of maintaining and managing a database, ensuring its efficiency and security. Their responsibilities revolve around monitoring the performance of databases, identifying any problems or inconsistencies, performing corrective measures, and devising security measures to keep data safe from any cyber. WebJun 22,  · Universally, these professionals help store and manage data, but their duties and responsibilities may extend to several other areas, such as: Extracting and/or . WebA database administrator maintains the databases that store those data and oversees database updates, security, storage, and troubleshooting. A database administrator . Being a database administrator or database manager is a rewarding, challenging career path. It also means handling significant responsibility as the. They are responsible for the storing, organizing, presenting, and usage and analysis of the company's database management software. They strive to meet the. Job Openings. Develop a Job description. Pay Equity. Also referred to as: DBA - Experienced, DBA II. Requirements and Responsibilities. Database Administrator II manages and maintains the company database of medium to high complexity. Optimizes database configuration and access. Being a Database Administrator II resolves database performance. Database administrators are responsible for the storage, organization, and management of electronic data. Their job description entails developing and maintaining the computer . A database administrator organizes everything from sensitive data like financial records, purchase histories, and customer information, to inventory and sales. As the Database Administrator, you will contribute to the design, implementation and maintenance of stable, scalable, optimised, resilient, documented and. Install and maintain the performance of database servers. · Develop processes for optimizing database security. · Set and maintain database standards. · Manage. A database administrator's (DBA) primary job is to ensure that data is available, protected from loss and corruption, and easily accessible as needed. Being a Database Administrator IV resolves database performance and capacity issues. Performs database recovery and back-up. Additionally, Database. painting jobs in philadelphia pa|jobs for geologists in germany Job Description: HealthPartners is currently hiring for a Microsoft SQL Database Administrator. We are a nonprofit integrated care delivery and financing system based in Bloomington, MN. . Duties · Identify user needs to create and administer databases · Design and build new databases · Ensure that organizational data are secure · Back up and restore. Being a Database Administrator IV resolves database performance and capacity issues. Performs database recovery and back-up. Additionally, Database Administrator IV advises users on access to multiple databases and helps solving data confliction and inappropriate usage. May require a bachelor's degree or its equivalent. Maintain reliability, stability and data integrity of the databases. Provide support in the administration, backup, integrity and security of various SQL. A database administrator (DBA) is the information technician responsible for directing and performing all activities related to maintaining a successful. Database Administrator Job Summary You'll be tasked with designing and implementing various methods, technologies and processes to store, share, analyze and. Effective database management requires a keen attention to detail, a strong customer service orientation and the ability to work as part of a team. Typical duties of a database administrator Managing, monitoring and maintaining company databases Making requested changes, updates and modifications to database structure and data. Jun 22,  · What does a Database Administrator do? Database Administrators manage and maintain software databases, such as library catalogues, user accounts, census information, statistical surveys and client records. They also provide secure access to databases and set up backup solutions to prevent data loss in case the system breaks down. A database administrator maintains the databases that store those data and oversees database updates, security, storage, and troubleshooting. A database administrator organizes everything from sensitive data like financial records, purchase histories, and customer information, to inventory and sales statistics. Duties and responsibilities of a Database Administrator You are responsible for the performance, integrity and security of a database and your job includes. Implements and monitors database access and configurations. Being a Database Administrator I resolves database performance and capacity issues. Performs database recovery and back . Duties and Responsibilities: Performs physical database administration (DBA) tasks in Oracle. Also performs basic DBA tasks in SQL Server and DB2 environments. Database Administrator Duties and Responsibilities · Monitor databases for proper performance · Install upgrades and maintain systems · Manage storage for all. Oct 02,  · A lead database administrator or DBA serves as a primary technologist in an organization or company. Lead database administrators are technical experts in terms of database and middleware technology design, tuning, configuration, troubleshooting, and building. They use specialized software for data storage and organization. Database administrators design, write and take care of computer database systems so that the right person can get the right information at the right time. They. Database administrators, often called DBAs, make sure that data analysts and other users can easily use databases to find the information they need and that. Сopyright 2011-2022
__label__pos
0.574644
How to Explain C++ in brief?  In Technologies 0 165 Views In C++, the keyword (++) is actually an increment operator and is used in many programming languages which means increment by one. Interesting? Well, then why not learn more about it? Here you go… C++ language gets its origin from C languageC++ can be denoted as follows: C= C+1 ; which means, If c= mother, Then c++=child As we all know that child always inherit features from her mother and develop their new features as well. So, we can say that c and c++ are not distinct languages and c++ has features of c and has its own features. If we want to get success in life, we must stick to our roots in the same way c++ is most popular language because its root is c language. Dr. Bjarne Stroustrup at AT & T’s Bell labs added additional features to the C Language in 1980 and developed a new language called C++. Let us take an example of Aquatic animals (animals live in water) e.g. fish, octopus Aquatic Animals (class) Fish, octopus (objects) So, we can say that a Class is a set of similar kind of objects and object is an instance of class or object is an identifiable unit having some behavior and distinctiveness. C++ is an object based Programming language. C++ uses some powerful features like: • Polymorphism • Inheritance • Encapsulation OOPs Features Some influential features of OOPs (Object Oriented programming language) are: 1. Based on the data 2. Programs are made by using objects which represent real-world objects. 3. Both function and data are encapsulated. 4. Protection of data is done by using Data hiding. 5. New data and function can be added easily. 6. One object communicates with other by using the function. 7. The bottom-up approach is used during program design. C++ character sets Character set in c++ is the building block to form some basic program elements for instance identifier, variables, array etc. Letters: Lowercase letters a-z, Uppercase letters A-Z Digits: 0-9 Special characters like | { ^ % } – { [ ] & _ . ?~: ‘‘(blank) / \* + “= < # ( These special characters are used at different locations according to requirement. Keywords These are reserved words which have some predefined meaning to the compiler. Some commonly used keywords are void register typedef Char float Long While If struct break else short const for Size of return do switch case extern double continue goto static auto Variables The memory of the computer is divided into small blocks of space. These blocks are large enough to hold an instance of some type of data. These blocks of space are called memory location. Variable is actually a name given to its memory location so that the user does not require to remember the address of the location. Variable have characters. The variable name should be unique within a program. To declare a variable, one must provide the following: 1. name 2. type 3. value Naming variables 1. A variable name can short as a single letter. 2. The variable name must begin with the letter of the alphabet or underscore (_). 3. After specifying the first letter or underscore it can contain numbers, letters, and additional underscore. 4. Reserved words should not be used as reserved words. 5. Black spaces are not allowed between variables names. e.g. roll_no = valid Salary=valid aug98_score = valid Count=invalid (reserved word) Your Age = invalid (no space is allowed) 78aug_score=invalid (first letter must be alphabet) Compiler interprets uppercase and lowercase letter differently so take care of that e.g. sales, Sales, saLes, SALES these all variables are different. In c, you can declare variables in the beginning of the block of code, but in C++ you can declare it anywhere. Constants These are data values that never change their values during program execution. C++ provides 4 types of constant: 1. Integer constants = Whole Number without any fractional part. 2. Floating point constant = Real number that has fractional part these are written in one of the two forms fractional form or Exponent form 3. Character constant = Contain one or more character enclosed in single quotes. 4. String constant = Contain number of character enclosed in double quotes, string constant is automatically added with null character “\0”. Input/output (I/O) in C++ In C++ cin and cout objects are used for input and output. The cout object sends data to the standard output device. Format of cout is something different from that of regular C++ commands Cout<<data [<<data] Here, data can be constant, variable, expressions or combination of all three. Operator << is used redirecting output to screen and called bitwise shift operator or put to the operator. The header file iostream.h is used for bitwise shift operator. You can use cin operator to get input from the keyboard. The header file iostream.h is used for cin operator. Format of cin operator is as follows Cin[>>value]; Example : int N; char ch; cout<<”Enter any number”; cin>>N; cout<<”Enter your choice”; cin>>ch; Escape Sequence Escape Sequences in C++ are used to display special characters in a string. These characters are not displayed in the output. Escape Sequences in C++ are used to modify the string. E.g. Escape sequences Meaning \’ Single Quote \” Double Quotes \? Question Mark \n New Line \t Horizontal Tab \v Vertical Tab \a Alarm \b Backspace \f New page Basic structure of C++ Program C++ program is constructed in the following manner: Header Section Contain name,author,revision number Include Section • Contain #include statement • Constant and type section • Global variable section • Function section • User defined functions • main() section If the program is structured in above format then it has following advantage • easy to read • easy to modify • easy to format Skeleton outline of simple c++ Program #include < iostream.h> (Preprocessor directive goes here) Int main() { < —-Block ———-Program goes here } Here main() function is the point where all c++ programs start their execution. Its content always executed first whether it is in the beginning, middle, or end of the code.main followed by ()(Parenthesis) that optionally can include arguments within them. return 0; return instruction finishes the main function and return the code that the instruction is followed by in this case it is it is 0. Concluding Words Once you have good experience with a lower level language, you will have a better understanding of how higher-level platforms work. Over the long term, this will help make you a better developer in C#, Java etc. And, it can be helpful in web application development. I hope my article helps in understanding basic concepts of C++.  In case of any other queries, you can surely post your valuable comments in the comments section below… RECOMMENDED POSTS Start typing and press Enter to search
__label__pos
0.987431
Write an equation in standard form for the line described synonym Now that I know that I need to use the vertex formula, I can get to work. To determine the formula for this line, the statistician enters these three results for the past 20 years into a regression software application. You need a minimum of four points on the calibration curve. The concentrations of the unknowns are automatically calculated and displayed column K. Then make an XY scatter graphputting concentration on the X horizontal axis and signal on the Y vertical axis. This example demonstrates why we ask for the leading coefficient of x to be "non-negative" instead of asking for it to be "positive". Mathematically, fit an equation to the calibration data, and solve the equation for concentration as a function of signal. These error estimates can be particularly poor when the number of points in a calibration curve is small; the accuracy of the estimates increases if the number of data points increases, but of course preparing a large number of standard solutions is time consuming and expensive. We know that a ball is being shot from a cannon. The acrobats formed a pyramid. You can also follow this two-step process that works for any form of the equation: Biology a group of organisms within a species that differ from similar groups by trivial differences, as of colour However, both the pre- and post-calibration curves fit the quadratic calibration equations very well, as indicated by the residuals plot and the coefficients of determination R 2 listed below the graphs. How do you use a calibration curve to predict the concentration of an unknown sample? How do you find x-intercepts? If you get a " NUM! iCoachMath When an unknown sample is measured, the signal from the unknown is converted into concentration using the calibration curve. In a simple regression with one independent variable, that coefficient is the slope of the line of best fit. When an analytical method is applied to complex real-world samples, for example the determination of drugs in blood serum, measurement error can occur due to interferences. The sample set could be each of these three data sets for the past 20 years. How do you find the x and y intercept? If the wavelength has a poor stray light rating or if the resolution is poor spectral bandpass is too bigthe calibration curve may be effected adversely. What is the importance of the x-intercept? Need Help Solving Those Dreaded Word Problems Involving Quadratic Equations? Ice began to form on the window. Now you have to figure out what the problem even means before trying to solve it. To fashion, train, or develop by instruction, discipline, or precept: The following two circular permutations on four letters are considered to be the same. The ice formed in patches across the window. Shape can imply either two-dimensional outline or three-dimensional definition that indicates both outline and bulk or mass: Not all lines have an x-intercept. An x-intercept is a point at which some function crosses the x-axis, which is the horizontal axis. The eight "unknown" samples that were measured for this test yellow table were actually the same sample measured repeatedly - a standard of concentration 1. Clouds will form in the afternoon. These standard deviation calculations are estimates of the variability of slopes and intercepts you are likely to get if you repeated the calibration over and over multiple times under the same conditions, assuming that the deviations from the straight line are due to random variability and not systematic error caused by non-linearity. Random errors like this could be due either to random volumetric errors small errors in volumes used to prepare the standard solution by diluting from the stack solution or in adding reagents or they may be due to random signal reading errors of the instrument, or to both. Enter the concentrations of the standards and their instrument readings e. Click here for a fill-in-the-blank OpenOffice spreadsheet that does this for you. Profile denotes the outline of something viewed against a background and especially the outline of the human face in side view: Working from a graph: To come into being by taking form; arise: That will only happen if you 1 are a perfect experimenter, 2 have a perfect instrument, and 3 choose the perfect curve-fit equation for your data. However, this method is theoretically not optimum, as demonstrated for the quadratic case Monte-Carlo simulation in the spreadsheet NormalVsReversedQuadFit2. Since the ball reaches a maximum height of There are many other things that we could find out about this ball! If you would like to use this method of calibration for your own data, download in Excel or OpenOffice Calc format.Worksheets for Analytical Calibration Curves the ease of preparing and diluting accurate and homogeneous mixtures of samples and standards in solution form. In the calibration curve method, a series of external standard solutions is prepared and measured. Sensitivity is defined as the slope of the standard (calibration) curve. Standard Form Write the standard form of the equation of each lin e. 1) y = −x + 5 2) y = 1 4 x + 2 3) y = 5 2 x − 1 4) y = −4x − 3 Write the standard form of the equation of the line through the given point with the given slope. 13) through: (0, 0), slope = 1 3. Availability, reliability, maintainability, and capability are components of the effectiveness equation. The effectiveness equation is a figure of merit which is helpful for deciding which component(s) detract from. Worksheet on standard form equation (pdf with answer key on this page's topic) Overview of different forms of a line's equation There are many different ways that you can express the equation of a line. Oct 21,  · Write the equation of a line given a slope and a point the line runs through - Duration: Ex 2: Find the Equation of a Line in Standard Form Given Two Points - Duration: Writing a function from a graph always requires you to keep a few key things in mind. Write a function from a graph with help from a professional private tutor . Download Write an equation in standard form for the line described synonym Rated 0/5 based on 79 review
__label__pos
0.996803
Results 1 to 1 of 1 Thread: find expression for an angle 1. #1 Junior Member Joined Apr 2012 From planet earth Posts 31 Thanks 1 find expression for one line segment Attachment 25106 Link to image: In this geometric setup, I'm trying to find an expression for A dependent on $\displaystyle \phi$, given that $\displaystyle R$ and $\displaystyle \theta$ are known. My take on this is to write the two expressions for the two sides $\displaystyle DL$ and $\displaystyle DR$ 1) $\displaystyle DL^2 = A^2 + R^2 - 2 A R \cos\left(\frac{1}{2}\pi - \phi\right)$ 2) $\displaystyle DR^2 = A^2 + R^2 - 2 A R \cos\left(\frac{1}{2}\pi + \phi\right) = A^2 + R^2 + 2 A R \cos\left(\frac{1}{2}\pi - \phi\right) $ and an expression for $\displaystyle DS = 2A$ 3) $\displaystyle DS^2 = DL^2 + DR^2 - 2 DL \cdot DR \cos\left(\theta\right)$ Then it seems that I could achieve my goal by eliminating $\displaystyle DL$ and $\displaystyle DR$ in the equation for $\displaystyle DS$. Summation of 1) and 2) gives 4) $\displaystyle DL^2 + DR^2= 2A^2 + 2R^2$ and multiplication of 1) and 2) gives 5) $\displaystyle DL^2\cdot DR^2 = \left(A^2 + R^2 - 2 A R \cos\left(\frac{1}{2}\pi - \phi\right)\right)\left(A^2 + R^2 + 2 A R \cos\left(\frac{1}{2}\pi - \phi\right) \right)$ $\displaystyle = \left(A^2 + R^2 \right)^2 - 4 A^2 R^2 \cos^2\left(\frac{1}{2}\pi - \phi\right)$ Inserting 4) into 3) and squaring provides 6) $\displaystyle DL^2 \cdot DR^2 = \frac{(R^2 - A^2)^2}{\cos^2\left(\theta\right)} $ Equating 5) and 6) gives an equation dependent on only $\displaystyle A$ and $\displaystyle \phi$ 7) $\displaystyle \left(A^2 + R^2 \right)^2 - 4 A^2 R^2 \cos^2\left(\frac{1}{2}\pi - \phi\right) = \frac{(R^2 - A^2)^2}{\cos^2\left(\theta\right)}$ Rearranging 8) $\displaystyle \cos^2\left(\theta\right)\left(A^4 + R^4 + 2 A^2R^2\right) - 4 A^2 R^2 \cos^2\left(\frac{1}{2}\pi - \phi\right)\cos^2\left(\theta\right) = A^4 + R^4 - 2 A^2R^2$ 9) $\displaystyle A^4(1-\cos^2\left(\theta\right)) - A^2(2 R^2 + 2 R^2\cos^2\left(\theta\right) - 4 R^2 \cos^2\left(\frac{1}{2}\pi - \phi\right)\cos^2\left(\theta\right)) + R^4(1-\cos^2\left(\theta\right)) = 0 $ 10) $\displaystyle A^4 - A^2 \frac{2 R^2(1 + \cos^2\left(\theta\right) - 2 \cos^2\left(\frac{1}{2}\pi - \phi\right)\cos^2\left(\theta\right)^2)}{1-\cos^2\left(\theta\right)} + R^4 = 0 $ I have a hard time believing this expression to be true because of the following reasoning: For $\displaystyle \phi=0$ then $\displaystyle A = R\tan\left(\frac{1}{2}\theta\right)$ As $\displaystyle \phi$ is increased I would assume that $\displaystyle A$ should also increase (relative to $\displaystyle R\tan\left(\frac{1}{2}\theta\right)$). However, for the numerical values that I have used to test the expression in 10) I find that $\displaystyle A$ decreases. Looking back, I can't find out where I go wrong. Last edited by niaren; Oct 8th 2012 at 06:32 AM. Reason: Found possible error in derivation Follow Math Help Forum on Facebook and Google+ Similar Math Help Forum Discussions 1. Replies: 1 Last Post: Apr 4th 2011, 11:36 AM 2. Replies: 1 Last Post: Feb 4th 2010, 11:07 PM 3. Replies: 7 Last Post: Nov 27th 2009, 06:35 PM 4. Simplify the Expression (Double-Angle or Half-Angle) Posted in the Trigonometry Forum Replies: 1 Last Post: Nov 3rd 2009, 03:38 PM 5. Replies: 3 Last Post: Apr 16th 2009, 08:45 AM Search Tags /mathhelpforum @mathhelpforum
__label__pos
0.999969
C Basic Syntax So far, we have already seen the basic syntax of C program in the previous Hello World program. Every piece of C code maintains the basic syntax probably. Let’s break down the basic syntax of C program that helps you to avoid syntax error while writing code in C. Every programming language has its own basic syntax. The basic syntax is the base of the building block of source code of a programming language. Like all other programming languages, C follows some basic syntax and based on the C compiler design. c basic syntax If you avoid a single basic syntax rule, then the compiler won’t compile your source code. Because making a syntax mistake does not make any sense to the compiler. In this lesson, we will learn the most basic syntax of the C programming language. It will make you aware of appropriating the basic syntax while writing source code in the C program. The length of this lesson may be long. Because we will discuss in details Basic C Program Structure In general, in a C program source code, most basic components are header files, the main function with the return type, code for execution in the main function, other function and self-defined function after the main function. The raw structure below. header files1 return_type3 main( function parameters)2  { code for execution;4 return parameter;5 } other function/ self-defined function goes here;6 The above raw syntax is not clear, right? Ok, let’s use the raw syntax to implement real C syntax. #include <stdio.h>  int main(void) { int x = 10, y = 20, total; total = x + y; printf("Total is: %d", total); return 0; } Output: programming Basic Syntax Now compare the c program with the above. Let’s discuss all of the basic syntaxes now: Header files1 C header files are the library functions defined in the specific module with a specified name. For example, in the above example, we used the header file “stdio.h”. It is the header file for basic input/output function like printf used in the example above. The “stdio.h” file also defines the main() function of a c program. That means, if you want to use the main function and printf function for displaying output then you must use the “stdio.h” header file. But the main function is an essential part of a C program for executing. So including the “stdio.h” header file is a must. There is some other header file also exists in C like “math.h”, “limits.h”, “signal.h”, etc. Every header file has some predefined function. When we need a specific function we basically include the corresponding header file, The syntax for including header files in C: #include <header_file_name> Example: #include <stdio.h> #include <math.h> #include <limits.h> Note: A single source file can contain multiple header files like the above. Header files must be placed at the top of the code. The main function2 Every C program must have the main function for final execution. Even all the other codes outside of the main function finally called by the main function and also executes by the main function. The syntax of the main function in C program: int main() { /* All the codes here part of the main function */ return 0; } The above syntax is the definition of the main function. Here int indicates the return type3, main() is the function definition, and the curly brac pair contains all the code of main function. Return type3 The return type of C is defined before implementing the main function Like int main(), void main(), int main(void), float main(), etc. Here the int, void, float is the return type. It means, what kind of data will return the main function. Basically in the C program, when we use int main() then the main function returns the integer value. And for the absence of function parameter, at the end of the main function we use return 0. So keep in mind that when you will use int return type then you must write the return 0; statement before the end of main function. void main() indicates hat by default the main function has no return type and function parameter. If you have no function parameter in your main function then you can use void return type for your main function but in this case, return 0 statement not required. Because by default it does not return any value. Semicolons in C; Semicolon after every statement is very important in C programming. In C program, every statement ends with a semicolon ( ; ). We will learn more about statement is a later lesson. In case if you avoid a semicolon after ending a statement, the compiler won’t understand the endpoint of the statement. And that’s why the compiler gets back with an error. This kinds of error called syntax error. Whitespaces in C In C programming all the whitespaces are ignored by the C compiler expect spaces in a string. In C programming, whitespace means an empty line, tab, single spaces, newline, etc. These all are ignored by the C compiler. But the only exception is the whitespaces in a string is not ignored by the compiler. We will learn more about whitespaces in later lessons. « Previous Next »
__label__pos
0.930675
Jurze Jurze - 3 months ago 35 Java Question Processing: Write HTML file from arduino input I'm trying to make a plant monitor using an Arduino and processing. Processing writes an html file based on the sensor input by the Arduino. WinSCP is monitoring the file created for changes and directly uploads trough FTP when the file has changed. The Arduino is sending the following to processing via serial: 45 0 31 40 x Using the following code in processing I write an html page with this data: import processing.serial.*; Serial myPort; String dataReading = ""; int lol = 0; String string0 = "<h1>Jurze Plants <img src=\"https://html-online.com/editor/tinymce/plugins/emoticons/img/smiley-laughing.gif\" alt=\"laughing\" /></h1>"; String string1 = "Moisture Level: "; String string2 = " %<br> Motorstate: "; String string3 = "<br> Temperature: "; String string4 = " &deg;C<br> Humidity: "; String string5 = "%<br>"; void setup() { size(500, 500); myPort = new Serial(this, "COM4", 9600); myPort.bufferUntil('x'); } void draw() { } String [] dataOutput = {}; void serialEvent(Serial myPort) { dataReading = myPort.readString(); if (dataReading!=null) { dataOutput = split(dataReading, '\n'); String [] tempfile = {string0,string1,dataOutput[1],string2,dataOutput[2],string3,dataOutput[3],string4,dataOutput[4],string5 }; println("saving to html file..."); saveStrings("data/index.html",tempfile); } } The html code I get the first time is : <h1>Jurze Plants <img src="https://html-online.com/editor/tinymce/plugins/emoticons/img/smiley-laughing.gif" alt="laughing" /></h1> Moisture Level: 46 %<br> Motorstate: 0 <br> Temperature:31.00 &deg;C <br> Humidity: 35.00% <br> Though, after it gets the data from the Arduino for the second time it looks like this: <h1>Jurze Plants <img src="https://html-online.com/editor/tinymce/plugins/emoticons/img/smiley-laughing.gif" alt="laughing" /></h1> Moisture Level: %<br> Motorstate: 46 <br> Temperature:0 &deg;C <br> Humidity: 31.00% <br> I guess there is something wrong with the array? Any help would be highly appreciated! :D Answer Time to debug your code! (We can't really do this for you, since we don't have your Arduino.) Step 1: In your serialEvent() function, use the println() function to print out the value of dataReading. Is the value what you expect? Step 2: Print out the value of dataOutput. Is that what you expect? Print out each index. Are they all what you expect? Check for extra spaces and control characters. Step 3: Are the indexes what you expect them to be? I see you're starting with index 1 instead of index 0. Is that what you meant to do? The point is, you have to print out the values of every variable to make sure they're what you expect. When you find the variable with the wrong value, you can trace back through your code to figure out exactly what's happening.
__label__pos
0.958442
Java实现二叉树三种遍历算法(递归以及非递归) 一杯JAVA浓 做棵大树 4年前 (2017-12-10) 1553次浏览 0个评论 首先需要定义一个二叉树的类 //首先定义<a href="https://beatree.cn/tag/%e4%ba%8c%e5%8f%89%e6%a0%91" title="查看更多关于二叉树的文章" target="_blank">二叉树</a>类 package mm.test.tree; public class BinaryTree { char data; //根节点 BinaryTree leftChild; //左孩子 BinaryTree rightChild; //右孩子 public BinaryTree() { } public void visit() { System.out.println(this.data); } public BinaryTree(char data) { this.data = data; this.leftChild = null; this.rightChild = null; } public BinaryTree getLeftChild() { return leftChild; } public void setLeftChild(BinaryTree leftChild) { this.leftChild = leftChild; } public BinaryTree getRightChild() { return rightChild; } public void setRightChild(BinaryTree rightChild) { this.rightChild = rightChild; } public char getData() { return data; } public void setData(char data) { this.data = data; } } 先序遍历思想:根左右。首先遍历根节点,然后遍历左子树和右子树。  package mm.test.tree; import java.util.Stack; public class VisitBinaryTree { //先序遍历非递归算法 private void preOrder(BinaryTree root) { if(root!=null) { Stack stack = new Stack(); for (BinaryTree node = root; !stack.empty() || node != null;) { //当遍历至节点位空的时候出栈 if(node == null) { node = stack.pop(); } node.visit(); //遍历右孩子存入栈内 if(node.getRightChild()!=null) { stack.push(node.getRightChild()); } //遍历左子树节点 node = node.getLeftChild(); } } } //先序遍历递归算法 public void preOrderRecursion(BinaryTree root) { if(root!=null) { root.visit(); preOrderRecursion(root.getLeftChild()); preOrderRecursion(root.getRightChild()); } } } 测试代码: public static void main(String args[]) { BinaryTree node = new BinaryTree('A'); BinaryTree root = node; BinaryTree nodeL1; BinaryTree nodeL; BinaryTree nodeR; node.setLeftChild(new BinaryTree('B')); node.setRightChild(new BinaryTree('C')); nodeL1 = node.getLeftChild(); nodeL1.setLeftChild(new BinaryTree('D')); nodeL1.setRightChild(new BinaryTree('E')); nodeL = nodeL1.getLeftChild(); nodeL.setLeftChild(new BinaryTree('F')); node = node.getRightChild(); node.setLeftChild(new BinaryTree('G')); node.setRightChild(new BinaryTree('H')); nodeR = node.getLeftChild(); nodeR.setLeftChild(new BinaryTree('I')); nodeR.setRightChild(new BinaryTree('J')); VisitBinaryTree vt= new VisitBinaryTree(); //先序遍历递归和非递归测试 vt.preOrder(root); vt.preOrderRecursion(root); } 中序遍历算法: //中序遍历的非递归算法 public void inOrder(BinaryTree root) { if(root!=null) { Stack stack = new Stack(); for (BinaryTree node = root; !stack.empty() || node != null; ) { //寻找最左的左子树节点,并将遍历的左节点进栈 while(node!=null) { stack.push(node); node = node.getLeftChild(); } if(!stack.empty()) { node = stack.pop(); //出栈 node.visit(); //读取节点值 node = node.getRightChild(); } } } } //中序遍历的递归算法 public void inOrderRecursion (BinaryTree root) { if(root!=null) { inOrderRecursion(root.getLeftChild()); root.visit(); inOrderRecursion(root.getRightChild()); } } 测试代码: public static void main(String args[]) { BinaryTree node = new BinaryTree('A'); BinaryTree root = node; BinaryTree nodeL1; BinaryTree nodeL; BinaryTree nodeR; node.setLeftChild(new BinaryTree('B')); node.setRightChild(new BinaryTree('C')); nodeL1 = node.getLeftChild(); nodeL1.setLeftChild(new BinaryTree('D')); nodeL1.setRightChild(new BinaryTree('E')); nodeL = nodeL1.getLeftChild(); nodeL.setLeftChild(new BinaryTree('F')); node = node.getRightChild(); node.setLeftChild(new BinaryTree('G')); node.setRightChild(new BinaryTree('H')); nodeR = node.getLeftChild(); nodeR.setLeftChild(new BinaryTree('I')); nodeR.setRightChild(new BinaryTree('J')); VisitBinaryTree vt= new VisitBinaryTree(); //中序遍历递归和非递归测试 vt.inOrder(root); vt.inOrderRecursion(root); } 后序遍历: //后序遍历非递归算法 private void postOrder(BinaryTree root) { if(root!=null) { Stack stack = new Stack(); for (BinaryTree node = root; !stack.empty() || node != null;) { while(root!=null) { stack.push(root); root = root.getLeftChild(); } while(!stack.empty() && root == stack.peek().getRightChild()) { root = stack.pop(); root.visit(); } if (stack.empty()) { return; } else { root = stack.peek().getRightChild(); } } } } //后序遍历递归算法 private void postOrderRecursion(BinaryTree root) { if(root!=null) { postOrderRecursion(root.getLeftChild()); postOrderRecursion(root.getRightChild()); root.visit(); } } 测试方法: public static void main(String args[]) { BinaryTree node = new BinaryTree('A'); BinaryTree root = node; BinaryTree nodeL1; BinaryTree nodeL; BinaryTree nodeR; node.setLeftChild(new BinaryTree('B')); node.setRightChild(new BinaryTree('C')); nodeL1 = node.getLeftChild(); nodeL1.setLeftChild(new BinaryTree('D')); nodeL1.setRightChild(new BinaryTree('E')); nodeL = nodeL1.getLeftChild(); nodeL.setLeftChild(new BinaryTree('F')); node = node.getRightChild(); node.setLeftChild(new BinaryTree('G')); node.setRightChild(new BinaryTree('H')); nodeR = node.getLeftChild(); nodeR.setLeftChild(new BinaryTree('I')); nodeR.setRightChild(new BinaryTree('J')); VisitBinaryTree vt= new VisitBinaryTree(); //后序遍历递归和非递归测试 vt.postOrder(root); vt.postOrderRecursion(root); }   做棵大树 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Java 实现二叉树三种遍历算法(递归以及非递归) 喜欢 (0) [欢迎投币] 分享 (0) 关于作者: 一个整天无所事事的,有时候忽然热血的孩子 发表我的评论 取消评论 表情 贴图 加粗 删除线 居中 斜体 签到 Hi,您需要填写昵称和邮箱! • 昵称 (必填) • 邮箱 (必填) • 网址
__label__pos
0.999775
     Logo Search packages:       Sourcecode: canto version File versions feed.py # -*- coding: utf-8 -*- #Canto - ncurses RSS reader # Copyright (C) 2008 Jack Miller <[email protected]> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. from const import VERSION_TUPLE import story import tag import cPickle import fcntl # Feed() controls a single feed and implements all of the update functionality # on top of Tag() (which is the generic class for lists of items). Feed() is # also the lowest granule for custom renderers because the renderers are # most likely using information specific to the XML, rather than information # specific to an arbitrary list. # Each feed has a self.ufp item that contains a verbatim copy of the data # returned by the feedparser. # Each feed will also only write its status back to disk on tick() and only if # has_changed() has been called by one of the Story() items Feed() contains. class Feed(list): def __init__(self, cfg, dirpath, URL, tags, rate, keep, \ renderer, filter, username, password): # Configuration set settings self.tags = tags self.base_set = 0 self.URL = URL self.renderer = renderer self.rate = rate self.time = 1 self.keep = keep self.username = username self.password = password # Hard filter if filter: self.filter = lambda x: filter(self, x) else: self.filter = None # Other necessities self.path = dirpath self.cfg = cfg self.changed = 0 self.ufp = None def update(self): lockflags = fcntl.LOCK_SH if self.base_set: lockflags |= fcntl.LOCK_NB try: f = open(self.path, "r") try: fcntl.flock(f.fileno(), lockflags) self.ufp = cPickle.load(f) except: return 0 finally: fcntl.flock(f.fileno(), fcntl.LOCK_UN) f.close() except: return 0 # If this data pre-dates 0.6.0 (the last disk format update) # toss a key error. if "canto_version" not in self.ufp or\ self.ufp["canto_version"][1] < 6: raise KeyError if not self.base_set: self.base_set = 1 if "feed" in self.ufp and "title" in self.ufp["feed"]: replace = lambda x: x or self.ufp["feed"]["title"] self.tags = [ replace(x) for x in self.tags] else: # Using URL for tag, no guarantees self.tags = [self.URL] + self.tags self.extend(self.ufp["entries"]) return 1 def extend(self, entries): newlist = [] for entry in entries: # If out todisk() lock failed, then it's possible # we have unwritten changes, so we need to move over # the canto_state, rather than just using the already # written one. selected = 0 if entry in self: i = self.index(entry) if self.changed and entry["canto_state"] !=\ self[i]["canto_state"]: entry["canto_state"] = self[i]["canto_state"] self.has_changed() selected = self[i].sel # If tags were added in the configuration, c-f won't # notice (doesn't care about tags), so we check and # append as needed. for tag in self.tags: if tag not in entry["canto_state"]: entry["canto_state"].append(tag) s = story.Story(entry, self, self.renderer) s.sel = selected newlist.append(s) del self[:] list.extend(self, filter(self.filter, newlist)) def has_changed(self): self.changed = 1 def todisk(self): f = open(self.path, "r+") try: fcntl.flock(f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) f.seek(0, 0) f.truncate() cPickle.dump(self.ufp, f) f.flush() except: return 0 finally: fcntl.flock(f.fileno(), fcntl.LOCK_UN) f.close() self.changed = 0 return 1 def tick(self): if self.changed: self.todisk() self.time -= 1 if self.time <= 0: if not self.update() or len(self) == 0 : self.time = 1 else: self.time = self.rate Generated by  Doxygen 1.6.0   Back to index
__label__pos
0.954389
0 I was asked to prepare an overview of an existing IT architechture and provide a document that consists of weaknesses analysis and suggestions on how each of the weak spots can be improved. How to make this document simple to read, not overloaded and specific at the same time? Is there a template I can use for this kind of documentation? Also, should I provide a description of how a specific segment in the system currently works before I put explanation about what should be changed? Thank you 1 1 Answer 1 1 1. This depends on what the target audience is for your propositions. More details to more technically-oriented people, less details for the people who controls budgeting. 2. Architecture is always a high-level thing. So if you analyse the weaknesses on architectural level there is no need to get into details. 3. You should rather concentrate on the value of the changes you propose. What risks are covered, what are the costs, what might happen if the thing will remain as is. 4. Use info-graphics approach 5. Provide the summary page at the end Not the answer you're looking for? Browse other questions tagged or ask your own question.
__label__pos
0.999707
Microsoft Attack Simulator - Landing Pages on Mobile Devices Copper Contributor Hi All,    I have a question with regards to the Phish Landing pages used in Attack Simulation not rendering correctly when opened in mobile devices (PFA).    These pages work perfectly fine on desktop and render perfectly. But during our testing when we opened the same landing page on mobile devices of smaller - medium screens, the webpage is basically broken. I cannot even pinch and move the webpage in any direction.   Is there a fix to this from MS? Or anyone within the community?  Thanks!   Note: This is the default landing page provided within MDAST and was not modified whatsoever.    Mobile-Phish-Landing-01.pngMobile-Phish-Landing-02.png       2 Replies I successfully discovered a workaround to address this particular challenge.   When setting up email notifications for users who fall victim to phishing campaigns, I observed that the underlying code for email notifications had improved padding and width within the body.   Copied this code and pasted it under the phishing landing page wizard and later added teh necessary content, Tips section with email view etc.,   This seems to have fixed the incorrect rendering issues.  @mohammedHaif  If you are referring to landing pages on mobile devices within the context of Microsoft Attack Simulator, it's crucial to ensure that your simulated phishing campaigns are effective across various platforms, including mobile devices. Many users access their emails and other communication tools on mobile devices, so testing the security awareness and resilience of employees on these devices is essential. To create landing pages that are compatible with mobile devices, you should consider the following: 1. Responsive Design: Ensure that your landing pages are designed responsively, adapting to different screen sizes and orientations. This ensures a seamless experience for users accessing the page on mobile devices. 2. Mobile-Friendly Content: Keep your content concise and easy to read on smaller screens. Avoid clutter and prioritize the most critical information to maintain user engagement. 3. Testing Across Devices: Before launching any simulated phishing campaigns, thoroughly test your landing pages on various mobile devices to identify and address any compatibility issues. 4. Browser Compatibility: Ensure compatibility with common mobile browsers such as Chrome, Safari, and Firefox. Test your landing pages across different browsers to catch any rendering issues. 5. Touch-Friendly Interactions: Consider the touch interface of mobile devices. Ensure that any interactive elements, such as buttons or forms, are easy to use and responsive to touch gestures. 6. Performance Optimization: Optimize your landing pages for fast loading times on mobile networks. Users on mobile devices may have slower internet connections, so minimizing page load times is crucial for engagement. 7. Security Measures: If your landing pages involve login screens or other sensitive information, ensure that the security measures are robust and compatible with mobile security standards.
__label__pos
0.816915
1 /* 2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 27 package java.util.logging; 28 29 import java.io.UnsupportedEncodingException; 30 import java.security.AccessController; 31 import java.security.PrivilegedAction; 32 33 /** 34 * A <tt>Handler</tt> object takes log messages from a <tt>Logger</tt> and 35 * exports them. It might for example, write them to a console 36 * or write them to a file, or send them to a network logging service, 37 * or forward them to an OS log, or whatever. 38 * <p> 39 * A <tt>Handler</tt> can be disabled by doing a <tt>setLevel(Level.OFF)</tt> 40 * and can be re-enabled by doing a <tt>setLevel</tt> with an appropriate level. 41 * <p> 42 * <tt>Handler</tt> classes typically use <tt>LogManager</tt> properties to set 43 * default values for the <tt>Handler</tt>'s <tt>Filter</tt>, <tt>Formatter</tt>, 44 * and <tt>Level</tt>. See the specific documentation for each concrete 45 * <tt>Handler</tt> class. 46 * 47 * 48 * @since 1.4 49 */ 50 51 public abstract class Handler { 52 private static final int offValue = Level.OFF.intValue(); 53 private final LogManager manager = LogManager.getLogManager(); 54 55 // We're using volatile here to avoid synchronizing getters, which 56 // would prevent other threads from calling isLoggable() 57 // while publish() is executing. 58 // On the other hand, setters will be synchronized to exclude concurrent 59 // execution with more complex methods, such as StreamHandler.publish(). 60 // We wouldn't want 'level' to be changed by another thread in the middle 61 // of the execution of a 'publish' call. 62 private volatile Filter filter; 63 private volatile Formatter formatter; 64 private volatile Level logLevel = Level.ALL; 65 private volatile ErrorManager errorManager = new ErrorManager(); 66 private volatile String encoding; 67 68 /** 69 * Default constructor. The resulting <tt>Handler</tt> has a log 70 * level of <tt>Level.ALL</tt>, no <tt>Formatter</tt>, and no 71 * <tt>Filter</tt>. A default <tt>ErrorManager</tt> instance is installed 72 * as the <tt>ErrorManager</tt>. 73 */ 74 protected Handler() { 75 } 76 77 /** 78 * Publish a <tt>LogRecord</tt>. 79 * <p> 80 * The logging request was made initially to a <tt>Logger</tt> object, 81 * which initialized the <tt>LogRecord</tt> and forwarded it here. 82 * <p> 83 * The <tt>Handler</tt> is responsible for formatting the message, when and 84 * if necessary. The formatting should include localization. 85 * 86 * @param record description of the log event. A null record is 87 * silently ignored and is not published 88 */ 89 public abstract void publish(LogRecord record); 90 91 /** 92 * Flush any buffered output. 93 */ 94 public abstract void flush(); 95 96 /** 97 * Close the <tt>Handler</tt> and free all associated resources. 98 * <p> 99 * The close method will perform a <tt>flush</tt> and then close the 100 * <tt>Handler</tt>. After close has been called this <tt>Handler</tt> 101 * should no longer be used. Method calls may either be silently 102 * ignored or may throw runtime exceptions. 103 * 104 * @exception SecurityException if a security manager exists and if 105 * the caller does not have <tt>LoggingPermission("control")</tt>. 106 */ 107 public abstract void close() throws SecurityException; 108 109 /** 110 * Set a <tt>Formatter</tt>. This <tt>Formatter</tt> will be used 111 * to format <tt>LogRecords</tt> for this <tt>Handler</tt>. 112 * <p> 113 * Some <tt>Handlers</tt> may not use <tt>Formatters</tt>, in 114 * which case the <tt>Formatter</tt> will be remembered, but not used. 115 * <p> 116 * @param newFormatter the <tt>Formatter</tt> to use (may not be null) 117 * @exception SecurityException if a security manager exists and if 118 * the caller does not have <tt>LoggingPermission("control")</tt>. 119 */ 120 public synchronized void setFormatter(Formatter newFormatter) throws SecurityException { 121 checkPermission(); 122 // Check for a null pointer: 123 newFormatter.getClass(); 124 formatter = newFormatter; 125 } 126 127 /** 128 * Return the <tt>Formatter</tt> for this <tt>Handler</tt>. 129 * @return the <tt>Formatter</tt> (may be null). 130 */ 131 public Formatter getFormatter() { 132 return formatter; 133 } 134 135 /** 136 * Set the character encoding used by this <tt>Handler</tt>. 137 * <p> 138 * The encoding should be set before any <tt>LogRecords</tt> are written 139 * to the <tt>Handler</tt>. 140 * 141 * @param encoding The name of a supported character encoding. 142 * May be null, to indicate the default platform encoding. 143 * @exception SecurityException if a security manager exists and if 144 * the caller does not have <tt>LoggingPermission("control")</tt>. 145 * @exception UnsupportedEncodingException if the named encoding is 146 * not supported. 147 */ 148 public synchronized void setEncoding(String encoding) 149 throws SecurityException, java.io.UnsupportedEncodingException { 150 checkPermission(); 151 if (encoding != null) { 152 try { 153 if(!java.nio.charset.Charset.isSupported(encoding)) { 154 throw new UnsupportedEncodingException(encoding); 155 } 156 } catch (java.nio.charset.IllegalCharsetNameException e) { 157 throw new UnsupportedEncodingException(encoding); 158 } 159 } 160 this.encoding = encoding; 161 } 162 163 /** 164 * Return the character encoding for this <tt>Handler</tt>. 165 * 166 * @return The encoding name. May be null, which indicates the 167 * default encoding should be used. 168 */ 169 public String getEncoding() { 170 return encoding; 171 } 172 173 /** 174 * Set a <tt>Filter</tt> to control output on this <tt>Handler</tt>. 175 * <P> 176 * For each call of <tt>publish</tt> the <tt>Handler</tt> will call 177 * this <tt>Filter</tt> (if it is non-null) to check if the 178 * <tt>LogRecord</tt> should be published or discarded. 179 * 180 * @param newFilter a <tt>Filter</tt> object (may be null) 181 * @exception SecurityException if a security manager exists and if 182 * the caller does not have <tt>LoggingPermission("control")</tt>. 183 */ 184 public synchronized void setFilter(Filter newFilter) throws SecurityException { 185 checkPermission(); 186 filter = newFilter; 187 } 188 189 /** 190 * Get the current <tt>Filter</tt> for this <tt>Handler</tt>. 191 * 192 * @return a <tt>Filter</tt> object (may be null) 193 */ 194 public Filter getFilter() { 195 return filter; 196 } 197 198 /** 199 * Define an ErrorManager for this Handler. 200 * <p> 201 * The ErrorManager's "error" method will be invoked if any 202 * errors occur while using this Handler. 203 * 204 * @param em the new ErrorManager 205 * @exception SecurityException if a security manager exists and if 206 * the caller does not have <tt>LoggingPermission("control")</tt>. 207 */ 208 public synchronized void setErrorManager(ErrorManager em) { 209 checkPermission(); 210 if (em == null) { 211 throw new NullPointerException(); 212 } 213 errorManager = em; 214 } 215 216 /** 217 * Retrieves the ErrorManager for this Handler. 218 * 219 * @return the ErrorManager for this Handler 220 * @exception SecurityException if a security manager exists and if 221 * the caller does not have <tt>LoggingPermission("control")</tt>. 222 */ 223 public ErrorManager getErrorManager() { 224 checkPermission(); 225 return errorManager; 226 } 227 228 /** 229 * Protected convenience method to report an error to this Handler's 230 * ErrorManager. Note that this method retrieves and uses the ErrorManager 231 * without doing a security check. It can therefore be used in 232 * environments where the caller may be non-privileged. 233 * 234 * @param msg a descriptive string (may be null) 235 * @param ex an exception (may be null) 236 * @param code an error code defined in ErrorManager 237 */ 238 protected void reportError(String msg, Exception ex, int code) { 239 try { 240 errorManager.error(msg, ex, code); 241 } catch (Exception ex2) { 242 System.err.println("Handler.reportError caught:"); 243 ex2.printStackTrace(); 244 } 245 } 246 247 /** 248 * Set the log level specifying which message levels will be 249 * logged by this <tt>Handler</tt>. Message levels lower than this 250 * value will be discarded. 251 * <p> 252 * The intention is to allow developers to turn on voluminous 253 * logging, but to limit the messages that are sent to certain 254 * <tt>Handlers</tt>. 255 * 256 * @param newLevel the new value for the log level 257 * @exception SecurityException if a security manager exists and if 258 * the caller does not have <tt>LoggingPermission("control")</tt>. 259 */ 260 public synchronized void setLevel(Level newLevel) throws SecurityException { 261 if (newLevel == null) { 262 throw new NullPointerException(); 263 } 264 checkPermission(); 265 logLevel = newLevel; 266 } 267 268 /** 269 * Get the log level specifying which messages will be 270 * logged by this <tt>Handler</tt>. Message levels lower 271 * than this level will be discarded. 272 * @return the level of messages being logged. 273 */ 274 public Level getLevel() { 275 return logLevel; 276 } 277 278 /** 279 * Check if this <tt>Handler</tt> would actually log a given <tt>LogRecord</tt>. 280 * <p> 281 * This method checks if the <tt>LogRecord</tt> has an appropriate 282 * <tt>Level</tt> and whether it satisfies any <tt>Filter</tt>. It also 283 * may make other <tt>Handler</tt> specific checks that might prevent a 284 * handler from logging the <tt>LogRecord</tt>. It will return false if 285 * the <tt>LogRecord</tt> is null. 286 * <p> 287 * @param record a <tt>LogRecord</tt> 288 * @return true if the <tt>LogRecord</tt> would be logged. 289 * 290 */ 291 public boolean isLoggable(LogRecord record) { 292 final int levelValue = getLevel().intValue(); 293 if (record.getLevel().intValue() < levelValue || levelValue == offValue) { 294 return false; 295 } 296 final Filter filter = getFilter(); 297 if (filter == null) { 298 return true; 299 } 300 return filter.isLoggable(record); 301 } 302 303 // Package-private support method for security checks. 304 // We check that the caller has appropriate security privileges 305 // to update Handler state and if not throw a SecurityException. 306 void checkPermission() throws SecurityException { 307 manager.checkPermission(); 308 } 309 310 // Package-private support for executing actions with additional 311 // LoggingPermission("control", null) permission. 312 interface PrivilegedVoidAction extends PrivilegedAction<Void> { 313 default Void run() { runVoid(); return null; } 314 void runVoid(); 315 } 316 317 void doWithControlPermission(PrivilegedVoidAction action) { 318 AccessController.doPrivileged(action, null, LogManager.controlPermission); 319 } 320 } --- EOF ---
__label__pos
0.956016
Welcome, guest | Sign In | My Account | Store | Cart A routine much like os.walk() that iterates over the directories and files of a remote FTP storage. Python, 103 lines 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 """ ftpwalk -- Walk a hierarchy of files using FTP (Adapted from os.walk()). """ def ftpwalk(ftp, top, topdown=True, onerror=None): """ Generator that yields tuples of (root, dirs, nondirs). """ # Make the FTP object's current directory to the top dir. ftp.cwd(top) # We may not have read permission for top, in which case we can't # get a list of the files the directory contains. os.path.walk # always suppressed the exception then, rather than blow up for a # minor reason when (say) a thousand readable directories are still # left to visit. That logic is copied here. try: dirs, nondirs = _ftp_listdir(ftp) except os.error, err: if onerror is not None: onerror(err) return if topdown: yield top, dirs, nondirs for entry in dirs: dname = entry[0] path = posixjoin(top, dname) if entry[-1] is None: # not a link for x in ftpwalk(ftp, path, topdown, onerror): yield x if not topdown: yield top, dirs, nondirs _calmonths = dict( (x, i+1) for i, x in enumerate(('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) ) def _ftp_listdir(ftp): """ List the contents of the FTP opbject's cwd and return two tuples of (filename, size, mtime, mode, link) one for subdirectories, and one for non-directories (normal files and other stuff). If the path is a symbolic link, 'link' is set to the target of the link (note that both files and directories can be symbolic links). Note: we only parse Linux/UNIX style listings; this could easily be extended. """ dirs, nondirs = [], [] listing = [] ftp.retrlines('LIST', listing.append) for line in listing: # Parse, assuming a UNIX listing words = line.split(None, 8) if len(words) < 6: print >> sys.stderr, 'Warning: Error reading short line', line continue # Get the filename. filename = words[-1].lstrip() if filename in ('.', '..'): continue # Get the link target, if the file is a symlink. extra = None i = filename.find(" -> ") if i >= 0: # words[0] had better start with 'l'... extra = filename[i+4:] filename = filename[:i] # Get the file size. size = int(words[4]) # Get the date. year = datetime.today().year month = _calmonths[words[5]] day = int(words[6]) mo = re.match('(\d+):(\d+)', words[7]) if mo: hour, min = map(int, mo.groups()) else: mo = re.match('(\d\d\d\d)', words[7]) if mo: year = int(mo.group(1)) hour, min = 0, 0 else: raise ValueError("Could not parse time/year in line: '%s'" % line) dt = datetime(year, month, day, hour, min) mtime = time.mktime(dt.timetuple()) # Get the type and mode. mode = words[0] entry = (filename, size, mtime, mode, extra) if mode[0] == 'd': dirs.append(entry) else: nondirs.append(entry) return dirs, nondirs I needed to implement a simple version of rsync to replicate remote files on a local filesyste on Windows, where my only allowed dependency was to be able to run Python with its stdlibs. I wrote this os.walk() equivalent to fetch my files from a Linux FTP server. 2 comments Grant Paton-Simpson 16 years, 3 months ago  # | flag posixjoin() should be os.path.join() plus need import statements. Thanks for the code - really helped me. Two things 1) can we use os.path.join() instead of posixjoin()? 2) it might help to list the import statements - import os from datetime import datetime import re import time Jice Clavier 16 years, 2 months ago  # | flag How can I use these functions. Hi, I'm trying to use these functions that would help me very much but I can't see how to use them. When I call the function : ftpwalk(ftpcnx, rootdir) nothing seems to happen. And it is so quick I don't think anything happen at all. Thanks for your help Created by Martin Blais on Mon, 18 Dec 2006 (PSF) Python recipes (4591) Martin Blais's recipes (6) Required Modules • (none specified) Other Information and Tasks  
__label__pos
0.673762
Top SOA Using Business Entities and Explicit State Knowledge d In a previous post, I mentioned the use of directed graphs as the payload. I discussed this in relation to alternative entry points beyond SOAP (HTTP or JMS) for services. Let's take the direct graph of business objects and consider some ideas from my post on explicit state and process knowledge. The operational context of the business objects in a service usually comes from information in the header or the actual API call. Most Service implementations use the SOAP Header to carry the relevant information related to the processes to execute as well as return error conditions. In general, the business objects do not have explicit state information or process context encapsulated within them. This is provided externally. There is heavy reliance on the API/Service call for generating the proper contextual knowledge. So the directed graph would be very much a Value Object - simple data containers. This is interesting. To use an API/Service call effectively requires understanding not just what the inputs and outputs are but a great deal of surrounding contextual information. I can call placeOrder(Items) all I want, but if that business process requires I be a registered customer these calls will fail if I haven't already registered. In some cases, this situation is obviated by standardized transactions, such as health care transactions that are regulated, or transactions which do not require deep business process contextual information, e.g. Google Maps. In many business applications and integrations these conditions are not present - meaning there are no standardized transactions and there is a need for fairly deep contextual information. This need relates to the end-points for the solution to be effective. Here is an example. A specialized third party vendor ported their application from a client-server to a three (+) tier web application model. One of the big marketing claims made for the new system was the exposing the data layer via web services. When documentation was supplied the list of services looked like: getMember(parms), getMember1(parms1), getMember2(parms2), … The original APIs had simply been given a web services façade. Each method required different input and had different output. How would anyone know which method to use for a particular purpose? Why, use one in a particular context and another in a different context? It is interesting they used this as an advertising opportunity because it exposed how poorly and haphazard the application was constructed. Even in cases not so dramatic this issue is significant. If I want to use a particular call, what do I need to know in terms of prerequisite expectation(s) as well as the obvious usage requirements (inputs and outputs)? Looking at this from a more abstract level, this is exactly the same issue each of us has faced learning a new language or development tool, e.g. Java, C, Eclipse, etc. What are the method calls on a Vector? What interfaces does it implement? Do I want to return an Enumeration, List, etc for a particular call? Obviously, learning a language is a much lower level activity and the hope with the Service approach is that the level of consideration rises to more of a business level and certainly less technical. Just keep in mind, that in my opinion, the contextual issue is still prevalent and must be coped with to effectively use a Service (or API). In a recent Service/SOA design I completed, one of the key things I decided was to move much of the contextual information into the business object (remember the directed graph). The business object contained a context wrapper containing business and technical contextual information about where the object originated, what process it was intending to use, digest information related to other processes it had passed through, etc. The SOAP header information contained high level calls as well as the infrastructure means to communicate a failure at the protocol mediation layer (an exception at the protocol level before the objects are marshaled out of the SOAP). The business components of the service (remember highly decoupled from the service infrastructure layers) consumed the business object and used the context to determine which specific actions to perform. This type of implementation is easily implemented using a object oriented behavioral patterns or by use of one of the popular containers that implement Inversion of Control (Spring, Pico Container, NetKernel). The requested action was part of the data of the object and it was discovered via requesting the object's business and technical context. Based on that information actions were attached to object and executed. Additionally, the results were returned in the object (submit the object get the object back with new data, updated data, etc). Lastly, the object's context was also updated with information indicating success as well as the ability to carry detailed exceptions/failures so that a particular type of exception could be used by an external application to vary it's behavior (the business rules generated clear exceptions indicating which rules failed). The SOAP Header was only used for general indication of processing failures except as noted above (where the failure occurs in the mediation layer). In this fashion, the Enterprise is able to use a common set of business objects with a known contextual interface for every Service. The "business component core" became a standard framework, which was used and deployed for every service. Applications produced the object and context directly or the integration layer did the transformations (for both request and response) to the objects and contextual information. Development of Service functionality became strictly a matter of building operational software that was attached to the business objects at runtime. Also, the integration layer contained a set of standardized information, e.g. reusable business objects connected in graph forms. I have laid out this idea and design in some detail for several reasons. Firstly, it is a means for standardizing data and interfaces for applications and integration services and may be beneficial to your Enterprise. Also, I am exploring ideas to address the issue of understanding contextual information between applications before an API/Service call can work. Recently, there was a post on this site discussing AJAX and Services. I have thought about that quite a bit in terms of what is it that people are hoping to achieve via use of AJAX. Services that can consume a standard business object with an embedded business and technical context is an important starting point to addressing the issue of contextual communication between applications. I have really enjoyed this effort working through the maze. I hope you do too. Related Tags: d About the Author Be the first to comment Sign In to Post a Comment Sorry! Something went wrong on our end. Please try again later.
__label__pos
0.646553
O'Reilly logo CSS: The Definitive Guide, 3rd Edition by Eric A. Meyer Stay ahead with the world's most comprehensive technology and business learning platform. With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more. Start Free Trial No credit card required Chapter 4. Values and Units In this chapter, we’ll tackle the elements that are the basis for almost everything you can do with CSS: the units that affect the colors, distances, and sizes of a whole host of properties. Without units, you couldn’t declare that a paragraph should be purple, or that an image should have 10 pixels of blank space around it, or that a heading’s text should be a certain size. By understanding the concepts put forth here, you’ll be able to learn and use the rest of CSS much more quickly. Numbers There are two types of numbers in CSS: integers (“whole” numbers) and reals fractional numbers). These number types serve primarily as the basis for other value types, but, in a few instances, raw numbers can be used as a value for a property. In CSS2.1, a real number is defined as an integer that is optionally followed by a decimal and fractional numbers. Therefore, the following are all valid number values: 15.5, -270.00004, and 5. Both integers and reals may be either positive or negative, although properties can (and often do) restrict the range of numbers they will accept. Percentages A percentage value is a calculated real number followed by a percentage sign (%). Percentage values are nearly always relative to another value, which can be anything, including the value of another property of the same element, a value inherited from the parent element, or a value of an ancestor element. Any property that accepts percentage values will define any restrictions on the range of allowed percentage values, and will also define the degree to which the percentage is relatively calculated. Color One of the first questions every starting web author asks is, “How do I set colors on my page?” Under HTML, you have two choices: you could use one of a small number of colors with names, such as red or purple, or employ a vaguely cryptic method using hexadecimal codes. Both of these methods for describing colors remain in CSS, along with some other—and, I think, more intuitive—methods. Named Colors Assuming that you’re content to pick from a small, basic set of colors, the easiest method is simply to use the name of the color you want. CSS calls these color choices, logically enough, named colors. Contrary to what some browser makers might have you believe, you have a limited palette of valid named-color keywords. For example, you’re not going to be able to choose “mother-of-pearl” because it isn’t a defined color. As of CSS2.1, the CSS specification defines 17 color names. These are the 16 colors defined in HTML 4.01 plus orange: aqua olive black orange blue purple fuchsia red gray silver green teal lime white maroon yellow navy So, let’s say you want all first-level headings to be maroon. The best declaration would be: h1 {color: maroon;} Simple and straightforward, isn’t it? Figure 4-1 shows a few more examples: h1 {color: gray;} h2 {color: silver;} h3 {color: black;} Naming colors Figure 4-1. Naming colors Of course, you’ve probably seen (and maybe even used) color names other than the ones listed earlier. For example, if you specify: h1 {color: lightgreen;} It’s likely that all of your h1 elements will indeed turn light green, despite lightgreen not being on the list of named colors in CSS2.1. It works because most web browsers recognize as many as 140 color names, including the standard 17. These extra colors are defined in the CSS3 Color specification, which is not covered in this book. The 17 standard colors (as of this writing) are likely to be more reliable than the longer list of 140 or so colors because the color values for these 17 are defined by CSS2.1. The extended list of 140 colors given in CSS3 is based on the standard X11 RGB values that have been in use for decades, so they are likely to be very well supported. Fortunately, there are more detailed and precise ways to specify colors in CSS. The advantage is that, with these methods, you can specify any color in the color spectrum, not just 17 (or 140) named colors. Colors by RGB Computers create colors by combining different levels of red, green, and blue, a combination that is often referred to as RGB color. In fact, if you were to open up an old CRT computer monitor and dig far enough into the projection tube, you would discover three “guns.” (I don’t recommend trying to find the guns, though, if you’re worried about voiding the monitor’s warranty.) These guns shoot out electron beams at varying intensities at each point on the screen. Then, the brightness of each beam combines at those points on your screen, forming all of the colors you see. Each point is known as a pixel, which is a term we’ll return to later in this chapter. Even though most monitors these days don’t use electron guns, their color output is still based on RGB mixtures. Given the way colors are created on a monitor, it makes sense that you should have direct access to those colors, determining your own mixture of the three for maximum control. That solution is complex, but possible, and the payoffs are worth it because there are very few limits on which colors you can produce. There are four ways to affect color in this manner. Functional RGB colors There are two color value types that use functional RGB notation as opposed to hexadecimal notation. The generic syntax for this type of color value is rgb(color), where color is expressed using a triplet of either percentages or integers. The percentage values can be in the range 0%100%, and the integers can be in the range 0255. Thus, to specify white and black, respectively, using percentage notation, the values would be: rgb(100%,100%,100%) rgb(0%,0%,0%) Using the integer-triplet notation, the same colors would be represented as: rgb(255,255,255) rgb(0,0,0) Assume you want your h1 elements to be a shade of red that lies between the values for red and maroon. red is equivalent to rgb(100%,0%,0%), whereas maroon is equal to (50%,0%,0%). To get a color between those two, you might try this: h1 {color: rgb(75%,0%,0%);} This makes the red component of the color lighter than maroon, but darker than red. If, on the other hand, you want to create a pale red color, you would raise the green and blue levels: h1 {color: rgb(75%,50%,50%);} The closest equivalent color using integer-triplet notation is: h1 {color: rgb(191,127,127);} The easiest way to visualize how these values correspond to color is to create a table of gray values. Besides, grayscale printing is all we can afford for this book, so that’s what we’ll do in Figure 4-2: p.one {color: rgb(0%,0%,0%);} p.two {color: rgb(20%,20%,20%);} p.three {color: rgb(40%,40%,40%);} p.four {color: rgb(60%,60%,60%);} p.five {color: rgb(80%,80%,80%);} p.six {color: rgb(0,0,0);} p.seven {color: rgb(51,51,51);} p.eight {color: rgb(102,102,102);} p.nine {color: rgb(153,153,153);} p.ten {color: rgb(204,204,204);} Text set in shades of gray Figure 4-2. Text set in shades of gray Of course, since we’re dealing in shades of gray, all three RGB values are the same in each statement. If any one of them were different from the others, then a color would start to emerge. If, for example, rgb(50%,50%,50%) were modified to be rgb(50%,50%,60%), the result would be a medium-dark color with just a hint of blue. It is possible to use fractional numbers in percentage notation. You might, for some reason, want to specify that a color be exactly 25.5 percent red, 40 percent green, and 98.6 percent blue: h2 {color: rgb(25.5%,40%,98.6%);} A user agent that ignores the decimal points (and some do) should round the value to the nearest integer, resulting in a declared value of rgb(26%,40%,99%). In integer triplets, of course, you are limited to integers. Values that fall outside the allowed range for each notation are “clipped” to the nearest range edge, meaning that a value that is greater than 100% or less than 0% will default to those allowed extremes. Thus, the following declarations would be treated as if they were the values indicated in the comments: P.one {color: rgb(300%,4200%,110%);} /* 100%,100%,100% */ P.two {color: rgb(0%,-40%,-5000%);} /* 0%,0%,0% */ p.three {color: rgb(42,444,-13);} /* 42,255,0 */ Conversion between percentages and integers may seem arbitrary, but there’s no need to guess at the integer you want—there’s a simple formula for calculating them. If you know the percentages for each of the RGB levels you want, then you need only apply them to the number 255 to get the resulting values. Let’s say you have a color of 25 percent red, 37.5 percent green, and 60 percent blue. Multiply each of these percentages by 255, and you get 63.75, 95.625, and 153. Round these values to the nearest integers, and voilà: rgb(64,96,153). Of course, if you already know the percentage values, there isn’t much point in converting them into integers. Integer notation is more useful for people who use programs such as Photoshop, which can display integer values in the “Info” dialog, or for those who are so familiar with the technical details of color generation that they normally think in values of 0–255. Then again, such people are probably more familiar with thinking in hexadecimal notation, which is our next topic. Hexadecimal RGB colors CSS allows you to define a color using the same hexadecimal color notation so familiar to HTML web authors: h1 {color: #FF0000;} /* set H1s to red */ h2 {color: #903BC0;} /* set H2s to a dusky purple */ h3 {color: #000000;} /* set H3s to black */ h4 {color: #808080;} /* set H4s to medium gray */ Computers have been using “hex notation” for quite some time now, and programmers are typically either trained in its use or pick it up through experience. Their familiarity with hexadecimal notation likely led to its use in setting colors in old-school HTML. The practice was simply carried over to CSS. Here’s how it works: by stringing together three hexadecimal numbers in the range 00 through FF, you can set a color. The generic syntax for this notation is #RRGGBB. Note that there are no spaces, commas, or other separators between the three numbers. Hexadecimal notation is mathematically equivalent to the integer-pair notation discussed in the previous section. For example, rgb(255,255,255) is precisely equivalent to #FFFFFF, and rgb(51,102,128) is the same as #336680. Feel free to use whichever notation you prefer—it will be rendered identically by most user agents. If you have a calculator that converts between decimal and hexadecimal, making the jump from one to the other should be pretty simple. For hexadecimal numbers that are composed of three matched pairs of digits, CSS permits a shortened notation. The generic syntax of this notation is #RGB: h1 {color: #000;} /* set H1s to black */ h2 {color: #666;} /* set H2s to dark gray */ h3 {color: #FFF;} /* set H3s to white */ As you can see from the markup, there are only three digits in each color value. However, since hexadecimal numbers between 00 and FF need two digits each, and you have only three total digits, how does this method work? The answer is that the browser takes each digit and replicates it. Therefore, #F00 is equivalent to #FF0000, #6FA would be the same as #66FFAA, and #FFF would come out #FFFFFF, which is the same as white. Obviously, not every color can be represented in this manner. Medium gray, for example, would be written in standard hexadecimal notation as #808080. This cannot be expressed in shorthand; the closest equivalent would be #888, which is the same as #888888. Bringing the colors together Table 4-1 presents an overview of some of the colors we’ve discussed. These color keywords might not be recognized by browsers and, therefore, they should be defined with either RGB or hex-pair values (just to be safe). In addition, there are some shortened hexadecimal values that do not appear at all. In these cases, the longer (six-digit) values cannot be shortened because they do not replicate. For example, the value #880 expands to #888800, not #808000 (otherwise known as olive). Therefore, there is no shortened version of #808000, and the appropriate entry in the table is blank. Table 4-1. Color equivalents Color Percentage Numeric Hexadecimal Short hex red rgb(100%,0%,0%) rgb(255,0,0) #FF0000 #F00 orange rgb(100%,40%,0%) rgb(255,102,0) #FF6600 #F60 yellow rgb(100%,100%,0%) rgb(255,255,0) #FFFF00 #FF0 green rgb(0%,50%,0%) rgb(0,128,0) #008000   blue rgb(0%,0%,100%) rgb(0,0,255) #0000FF #00F aqua rgb(0%,100%,100%) rgb(0,255,255) #00FFFF #0FF black rgb(0%,0%,0%) rgb(0,0,0) #000000 #000 fuchsia rgb(100%,0%,100%) rgb(255,0,255) #FF00FF #F0F gray rgb(50%,50%,50%) rgb(128,128,128) #808080   lime rgb(0%,100%,0%) rgb(0,255,0) #00FF00 #0F0 maroon rgb(50%,0%,0%) rgb(128,0,0) #800000   navy rgb(0%,0%,50%) rgb(0,0,128) #000080   olive rgb(50%,50%,0%) rgb(128,128,0) #808000   purple rgb(50%,0%,50%) rgb(128,0,128) #800080   silver rgb(75%,75%,75%) rgb(192,192,192) #C0C0C0   teal rgb(0%,50%,50%) rgb(0,128,128) #008080   white rgb(100%,100%,100%) rgb(255,255,255) #FFFFFF #FFF Web-safe colors The “web-safe” colors are those colors that generally avoid dithering on 256-color computer systems. Web-safe colors can be expressed in multiples of the RGB values 20% and 51, and the corresponding hex-pair value 33. Also, 0% or 0 is a safe value. So, if you use RGB percentages, make all three values either 0% or a number divisible by 20—for example, rgb(40%,100%,80%) or rgb(60%,0%,0%). If you use RGB values on the 0–255 scale, the values should be either 0 or divisible by 51, as in rgb(0,204,153) or rgb(255,0,102). With hexadecimal notation, any triplet that uses the values 00, 33, 66, 99, CC, and FF is considered to be web-safe. Examples are #669933, #00CC66, and #FF00FF. This means the shorthand hex values that are web-safe are 0, 3, 6, 9, C, and F; therefore, #693, #0C6, and #F0F are examples of web-safe colors. Length Units Many CSS properties, such as margins, depend on length measurements to properly display various page elements. It’s no surprise, then, that there are a number of ways to measure length in CSS. All length units can be expressed as either positive or negative numbers followed by a label (although some properties will accept only positive numbers). You can also use real numbers—that is, numbers with decimal fractions, such as 10.5 or 4.561. All length units are followed by a two-letter abbreviation that represents the actual unit of length being specified, such as in (inches) or pt (points). The only exception to this rule is a length of 0 (zero), which need not be followed by a unit. These length units are divided into two types: absolute length units and relative length units. Absolute Length Units We’ll start with absolute units because they’re easiest to understand, despite the fact that they’re almost unusable in web design. The five types of absolute units are as follows: Inches (in) As you might expect, this notation refers to the inches you’d find on a ruler in the United States. (The fact that this unit is in the specification, even though almost the entire world uses the metric system, is an interesting insight into the pervasiveness of U.S. interests on the Internet—but let’s not get into virtual sociopolitical theory right now.) Centimeters (cm) Refers to the centimeters that you’d find on rulers the world over. There are 2.54 centimeters to an inch, and one centimeter equals 0.394 inches. Millimeters (mm) For those Americans who are metric-challenged, there are 10 millimeters to a centimeter, so an inch equals 25.4 millimeters, and a millimeter equals 0.0394 inches. Points (pt) Points are standard typographical measurements that have been used by printers and typesetters for decades and by word-processing programs for many years. Traditionally, there are 72 points to an inch (points were defined before widespread use of the metric system). Therefore, the capital letters of text set to 12 points should be one-sixth of an inch tall. For example, p {font-size: 18pt;} is equivalent to p {font-size: 0.25in;}. Picas (pc) Picas are another typographical term. A pica is equivalent to 12 points, which means there are 6 picas to an inch. As just shown, the capital letters of text set to 1 pica should be one-sixth of an inch tall. For example, p {font-size: 1.5pc;} would set text to the same size as the example declarations found in the definition of points. Of course, these units are really useful only if the browser knows all the details of the monitor on which your page is displayed, the printer you’re using, or whatever other user agent might apply. On a web browser, display is affected by the size of the monitor and the resolution to which the monitor is set—and there isn’t much that you, as the author, can do about these factors. You can only hope that, if nothing else, the measurements will be consistent in relation to each other—that is, that a setting of 1.0in will be twice as large as 0.5in, as shown in Figure 4-3. Setting absolute-length left margins Figure 4-3. Setting absolute-length left margins Working with absolute lengths If a monitor’s resolution is set to 1,024 pixels wide by 768 pixels tall, its screen size is exactly 14.22 inches wide by 10.67 inches tall, and it is filled entirely by the display area, then each pixel will be 1/72 of an inch wide and tall. As you might guess, this scenario is a very, very rare occurrence (have you ever seen a monitor with those dimensions?). So, on most monitors, the actual number of pixels per inch (ppi) is higher than 72—sometimes much higher, up to 120 ppi and beyond. As a Windows user, you might be able to set your display driver to make the display of elements correspond correctly to real-world measurements. To try, click Start → Settings → Control Panel. In the Control Panel, double-click Display. Click the Settings tab, and click Advanced to reveal a dialog box (which may differ on each PC). You should see a section labeled Font Size; select Other, and then hold a ruler up to the screen and move the slider until the onscreen ruler matches the physical ruler. Click OK until you’re free of dialog boxes, and you’re set. If you’re a Mac Classic user, there’s no place to set this information in the operating system—the Mac Classic OS (that is, any version previous to OS X) makes an assumption about the relationship between on-screen pixels and absolute measurements by declaring your monitor to have 72 pixels to the inch. This assumption is totally wrong, but it’s built into the operating system, and therefore pretty much unavoidable. As a result, on many Classic Mac-based web browsers, any point value will be equivalent to the same length in pixels: 24pt text will be 24 pixels tall, and 8pt text will be 8 pixels tall. This is, unfortunately, slightly too small to be legible. Figure 4-4 illustrates the problem. Teensy text makes for difficult reading Figure 4-4. Teensy text makes for difficult reading In OS X, the built-in assumed ppi value is closer to Windows: 96ppi. This doesn’t make it any more correct, but it’s at least consistent with Windows machines. The Classic Mac display problem is an excellent example of why points should be strenuously avoided when designing for the Web. Ems, percentages, and even pixels are all preferable to points where browser display is concerned. Tip Beginning with Internet Explorer 5 for Macintosh and Gecko-based browsers such as Netscape 6+, the browser itself contains a preference setting for setting ppi values. You can pick the standard Macintosh ratio of 72ppi, the common Windows ratio of 96ppi, or a value that matches your monitor’s ppi ratio. This last option works similarly to the Windows setting just described, where you use a sliding scale to compare to a ruler and thus get an exact match between your monitor and physical-world distances. Despite all we’ve seen, let’s make the highly suspect assumption that your computer knows enough about its display system to accurately reproduce real-world measurements. In that case, you could make sure every paragraph has a top margin of half an inch by declaring p {margin-top: 0.5in;}. Regardless of font size or any other circumstances, a paragraph will have a half-inch top margin. Absolute units are much more useful in defining style sheets for printed documents, where measuring things in terms of inches, points, and picas is common. As you’ve seen, attempting to use absolute measurements in web design is perilous at best, so let’s turn to some more useful units of measure. Relative Length Units Relative units are so called because they are measured in relation to other things. The actual (or absolute) distance they measure can change due to factors beyond their control, such as screen resolution, the width of the viewing area, the user’s preference settings, and a whole host of other things. In addition, for some relative units, their size is almost always relative to the element that uses them and will thus change from element to element. There are three relative length units: em, ex, and px. The first two stand for “em-height” and “x-height,” which are common typographical measurements; however, in CSS, they have meanings you might not expect if you are familiar with typography. The last type of length is px, which stands for “pixels.” A pixel is one of the dots you can see on your computer’s monitor if you look closely enough. This value is defined as relative because it depends on the resolution of the display device, a subject we’ll soon cover. em and ex units First, however, let’s consider em and ex. In CSS, one “em” is defined to be the value of font-size for a given font. If the font-size of an element is 14 pixels, then for that element, 1em is equal to 14 pixels. Obviously, this value can change from element to element. For example, let’s say you have an h1 with a font size of 24 pixels, an h2 element with a font size of 18 pixels, and a paragraph with a font size of 12 pixels. If you set the left margin of all three at 1em, they will have left margins of 24 pixels, 18 pixels, and 12 pixels, respectively: h1 {font-size: 24px;} h2 {font-size: 18px;} p {font-size: 12px;} h1, h2, p {margin-left: 1em;} small {font-size: 0.8em;} <h1>Left margin = <small>24 pixels</small></h1> <h2>Left margin = <small>18 pixels</small></h2> <p>Left margin = <small>12 pixels</small></p> When setting the size of the font, on the other hand, the value of em is relative to the font size of the parent element, as illustrated by Figure 4-5. Using em for margins and font sizing Figure 4-5. Using em for margins and font sizing ex, on the other hand, refers to the height of a lowercase x in the font being used. Therefore, if you have two paragraphs in which the text is 24 points in size, but each paragraph uses a different font, then the value of ex could be different for each paragraph. This is because different fonts have different heights for x, as you can see in Figure 4-6. Even though the examples use 24-point text—and therefore, each example’s em value is 24 points—the x-height for each is different. Varying x-heights Figure 4-6. Varying x-heights Practical issues with em and ex Of course, everything I’ve just explained is completely theoretical. I’ve outlined what is supposed to happen, but in practice, many user agents get their value for ex by taking the value of em and dividing it in half. Why? Apparently, most fonts don’t have the value of their ex height built-in, and it’s a very difficult thing to compute. Since most fonts have lowercase letters that are about half as tall as uppercase letters, it’s a convenient fiction to assume that 1ex is equivalent to 0.5em. A few browsers, including Internet Explorer 5 for Mac, actually attempt to determine the x-height of a given font by internally rendering a lowercase x and counting pixels to determine its height compared to that of the font-size value used to create the character. This is not a perfect method, but it’s much better than simply making 1ex equal to 0.5em. We CSS practitioners can hope that, as time goes on, more user agents will start using real values for ex and the half-em shortcut will fade into the past. Pixel lengths On the face of things, pixels are straightforward. If you look at a monitor closely enough, you can see that it’s broken up into a grid of tiny little boxes. Each box is a pixel. If you define an element to be a certain number of pixels tall and wide, as in the following markup: <p> The following image is 20 pixels tall and wide: <img src="test.gif" style="width: 20px; height: 20px;" alt="" /> </p> then it follows that the element will be that many monitor elements tall and wide, as shown in Figure 4-7. Using pixel lengths Figure 4-7. Using pixel lengths Unfortunately, there is a potential drawback to using pixels. If you set font sizes in pixels, then users of Internet Explorer for Windows previous to IE7 cannot resize the text using the Text Size menu in their browser. This can be a problem if your text is too small for a user to comfortably read. If you use more flexible measurements, such as em, the user can resize text. (If you’re exceedingly protective of your design, you might call that a drawback, of course.) On the other hand, pixel measurements are perfect for expressing the size of images, which are already a certain number of pixels tall and wide. In fact, the only time you would not want pixels to express image size is if you want them scaled along with the size of the text. This is an admirable and occasionally useful approach, and one that would really make sense if you were using vector-based images instead of pixel-based images. (With the adoption of Scalable Vector Graphics, look for more on this in the future.) Pixel theory So why are pixels defined as relative lengths? I’ve explained that the tiny boxes of color in a monitor are pixels. However, how many of those boxes equals one inch? This may seem like a non sequitur, but bear with me for a moment. In its discussion of pixels, the CSS specification recommends that in cases where a display type is significantly different than 96ppi, user agents should scale pixel measurements to a “reference pixel.” CSS2 recommended 90ppi as the reference pixel, but CSS2.1 recommends 96ppi—a measurement common to Windows machines and adopted by modern Macintosh browsers such as Safari. In general, if you declare something like font-size: 18px, a web browser will almost certainly use actual pixels on your monitor—after all, they’re already there—but with other display devices, like printers, the user agent will have to rescale pixel lengths to something more sensible. In other words, the printing code has to figure out how many dots there are in a pixel, and to do so, it may use the 96ppi reference pixel. Warning One example of problems with pixel measurements can be found in an early CSS1 implementation. In Internet Explorer 3.x, when a document was printed, IE3 assumed that 18px was the same as 18 dots, which on a 600dpi printer works out to be 18/600, or 3/100, of an inch—or, if you prefer, .03in. That’s pretty small text! Because of this potential for rescaling, pixels are defined as a relative unit of measurement, even though, in web design, they behave much like absolute units. What to do? Given all the issues involved, the best measurements to use are probably the relative measurements, most especially em, and also px when appropriate. Because ex is, in most currently used browsers, basically a fractional measurement of em, it’s not all that useful for the time being. If more user agents support real x-height measurements, ex might come into its own. In general, ems are more flexible because they scale with font sizes, so elements and element separation will stay more consistent. Other element aspects may be more amenable to the use of pixels, such as borders or the positioning of elements. It all depends on the situation. For example, in designs that traditionally use spacer GIFs to separate pieces of a design, pixel-length margins will produce an identical effect. Converting that separation distance to ems would allow the design to grow or shrink as the text size changes—which might or might not be a good thing. URLs If you’ve written web pages, you’re obviously familiar with URLs (or, in CSS2.1, URIs). Whenever you need to refer to one—as in the @import statement, which is used when importing an external style sheet—the general format is: url(protocol://server/pathname) This example defines what is known as an absolute URL. By absolute, I mean a URL that will work no matter where (or rather, in what page) it’s found, because it defines an absolute location in web space. Let’s say that you have a server called www.waffles.org. On that server, there is a directory called pix, and in this directory is an image waffle22.gif. In this case, the absolute URL of that image would be: http://www.waffles.org/pix/waffle22.gif This URL is valid no matter where it is found, whether the page that contains it is located on the server www.waffles.org or web.pancakes.com. The other type of URL is a relative URL, so named because it specifies a location that is relative to the document that uses it. If you’re referring to a relative location, such as a file in the same directory as your web page, then the general format is: url(pathname) This works only if the image is on the same server as the page that contains the URL. For argument’s sake, assume that you have a web page located at http://www.waffles.org/syrup.html and that you want the image waffle22.gif to appear on this page. In that case, the URL would be: pix/waffle22.gif This path works because the web browser knows that it should start with the place it found the web document and then add the relative URL. In this case, the pathname pix/waffle22.gif added to the server name http://www.waffles.org equals http://www.waffles.org/pix/waffle22.gif. You can almost always use an absolute URL in place of a relative URL; it doesn’t matter which you use, as long as it defines a valid location. In CSS, relative URLs are relative to the style sheet itself, not to the HTML document that uses the style sheet. For example, you may have an external style sheet that imports another style sheet. If you use a relative URL to import the second style sheet, it must be relative to the first style sheet. As an example, consider an HTML document at http://www.waffles.org/toppings/tips.html, which has a link to the style sheet http://www.waffles.org/styles/basic.css: <link rel="stylesheet" type="text/css" href="http://www.waffles.org/styles/basic.css"> Inside the file basic.css is an @import statement referring to another style sheet: @import url(special/toppings.css); This @import will cause the browser to look for the style sheet at http://www.waffles.org/styles/special/toppings.css, not at http://www.waffles.org/toppings/special/toppings.css. If you have a style sheet at the latter location, then the @import in basic.css should read: @import url(http://www.waffles.org/toppings/special/toppings.css); Warning Netscape Navigator 4 interprets relative URLs in relation to the HTML document, not the style sheet. If you have a lot of NN4.x visitors or want to make sure NN4.x can find all of your style sheets and background images, it’s generally easiest to make all of your URLs absolute, since Navigator handles those correctly. Note that there cannot be a space between the url and the opening parenthesis: body {background: url(http://www.pix.web/picture1.jpg);} /* correct */ body {background: url (images/picture2.jpg);} /* INCORRECT */ If the space isn’t omitted, the entire declaration will be invalidated and thus ignored. Keywords For those times when a value needs to be described with a word of some kind, there are keywords. A very common example is the keyword none, which is distinct from 0 (zero). Thus, to remove the underline from links in an HTML document, you would write: a:link, a:visited {text-decoration: none;} Similarly, if you want to force underlines on the links, then you would use the keyword underline. If a property accepts keywords, then its keywords will be defined only for the scope of that property. If two properties use the same word as a keyword, the behavior of the keyword for one property will not be shared with the other. As an example, normal, as defined for letter-spacing, means something very different than the normal defined for font-style. inherit There is one keyword that is shared by all properties in CSS2.1: inherit. inherit makes the value of a property the same as the value of its parent element. In most cases, you don’t need to specify inheritance, since most properties inherit naturally; however, inherit can still be very useful. For example, consider the following styles and markup: #toolbar {background: blue; color: white;} <div id="toolbar"> <a href="one.html">One</a> | <a href="two.html">Two</a> | <a href="three.html">Three</a> </div> The div itself will have a blue background and a white foreground, but the links will be styled according to the browser’s preference settings. They’ll most likely end up as blue text on a blue background, with white vertical bars between them. You could write a rule that explicitly sets the links in the “toolbar” to be white, but you can make things a little more robust by using inherit. You simply add the following rule to the style sheet: #toolbar a {color: inherit;} This will cause the links to use the inherited value of color in place of the user agent’s default styles. Ordinarily, directly assigned styles override inherited styles, but inherit can reverse that behavior. CSS2 Units In addition to what we’ve covered in CSS2.1, CSS2 contains a few extra units, all of which are concerned with aural style sheets (employed by those browsers that are capable of speech). These units were not included in CSS2.1, but since they may be part of future versions of CSS, we’ll briefly discuss them here: Angle values Used to define the position from which a given sound should originate. There are three types of angles: degrees (deg), grads (grad), and radians (rad). For example, a right angle could be declared as 90deg, 100grad, or 1.57rad; in each case, the values are translated into degrees in the range 0 through 360. This is also true of negative values, which are allowed. The measurement -90deg is the same as 270deg. Time values Used to specify delays between speaking elements. They can be expressed as either milliseconds (ms) or seconds (s). Thus, 100ms and 0.1s are equivalent. Time values cannot be negative, as CSS is designed to avoid paradoxes. Frequency values Used to declare a given frequency for the sounds that speaking browsers can produce. Frequency values can be expressed as hertz (Hz) or megahertz (MHz) and cannot be negative. The values’ labels are case-insensitive, so 10MHz and 10Mhz are equivalent. The only user agent known to support any of these values at this writing is Emacspeak, an aural style sheets implementation. See Chapter 14 for details on aural styles. In addition to these values, there is also an old friend with a new name. A URI is a Uniform Resource Identifier, which is sort of another name for a Uniform Resource Locator (URL). Both the CSS2 and CSS2.1 specifications require that URIs be declared with the form url(...), so there is no practical change. Summary Units and values cover a wide spectrum of areas, from length units to special keywords that describe effects (such as underline) to color units to the location of files (such as images). For the most part, units are the one area that user agents get almost totally correct, but it’s those few little bugs and quirks that can get you. Navigator 4.x’s failure to interpret relative URLs correctly, for example, has bedeviled many authors and led to an overreliance on absolute URLs. Colors are another area where user agents almost always do well, except for a few little quirks here and there. The vagaries of length units, however, far from being bugs, are an interesting problem for any author to tackle. These units all have their advantages and drawbacks, depending upon the circumstances in which they’re used. We’ve already seen some of these circumstances, and their nuances will be discussed in the rest of the book, beginning with the CSS properties that describe ways to alter how text is displayed. With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more. Start Free Trial No credit card required
__label__pos
0.832238
A apresentação está carregando. Por favor, espere A apresentação está carregando. Por favor, espere D IAGRAMA DE C LASSES George Gomes Cabral. D IAGRAMA DE C LASSES Em POO, os problemas de programação são pensados em termos de objetos, nada de funções, Apresentações semelhantes Apresentação em tema: "D IAGRAMA DE C LASSES George Gomes Cabral. D IAGRAMA DE C LASSES Em POO, os problemas de programação são pensados em termos de objetos, nada de funções,"— Transcrição da apresentação: 1 D IAGRAMA DE C LASSES George Gomes Cabral 2 D IAGRAMA DE C LASSES Em POO, os problemas de programação são pensados em termos de objetos, nada de funções, rotinas. Desta forma quando é colocado o problema de desenvolver um sistema para locadoras, por exemplo, devemos pensar como dividir o problema em objetos. Para este caso podemos ter os seguintes objetos: Clientes, CDs e Fitas,etc. "Um objeto é um termo que usamos para representar uma entidade do mundo real" (Fazemos isto através de um exercício de abstração.) 3 D IAGRAMA DE C LASSES Podemos descrever o cachorro Bilú em termos de seus atributos físicos: é pequeno, sua cor principal é castanha, olhos pretos, orelhas pequenas e caídas, rabo pequeno, patas brancas. Podemos também descrever algumas ações que ele faz (temos aqui os métodos) : balança o rabo, foge e se deita se o mando sair debaixo da mesa, late quando ouve um barulho ou vê um cão ou gato, atende e corre quando o chamamos pelo seu nome. 4 D IAGRAMA DE C LASSE Temos aqui a representação do cachorro Bilú:  Propriedades : [Cor do corpo : castanha cor dos olhos : preto altura: 18 cm comprimento: 38 cm largura : 24 cm]  Métodos : [balançar o rabo, latir, deitar, sentar ]. 5 D IAGRAMA DE C LASSES Uma classe representa um conjunto de objetos que possuem comportamentos e características comuns. Uma classe descreve como certos tipos de objetos se parecem do ponto de vista da programação, pois quando definimos uma classe precisamos definir duas coisas:  Propriedades - Informações específicas relacionadas a uma classe de objeto. São as características dos objetos que as classes representam. Ex Cor, altura, tamanho, largura, etc...  Métodos : São ações que os objetos de uma classe podem realizar. Ex: Latir, correr, sentar, comer, etc. 6 D IAGRAMA DE C LASSES A representação de uma classe usa um retângulo dividido em três partes: 7 D IAGRAMAS DE C LASSES Os diagrama se classes ilustram atributos e operações de uma classe e as restrições como que os objetos podem ser conectados ; descrevem também os tipos de objetos no sistema e os relacionamentos entre estes objetos Para poder representar a visibilidade dos atributos e operações em uma classe utiliza-se as seguintes marcas e significados:  + público - visível em qualquer classe  # protegido - qualquer descendente pode usar  - privado - visível somente dentro da classe 8 D IAGRAMA DE C LASSES Relacionamentos entre classes:  Associações : Agregação e composição  Generalização (herança)  Dependências Herança:  Um dos princípios da OO, permite a reutilização. Uma classe pode ser definida a partir de outra já existente 9 D IAGRAMA DE C LASSES Forma RectânguloCírculoFormaComposta Relação é um… uma Forma pode ser um Círculo, um Rectângulo ou uma FormaComposta 10 D IAGRAMA DE C LASSES Uma associação é um vínculo que permite que objetos de uma ou mais classes se relacionem. Não há conceito de posse Os tempos de vida dos objetos ligados entre si são independentes. As associações podem ser:  unárias - quando a associação ocorre entre objetos de uma mesma classe.  binárias - quando a associação ocorre entre dois objetos de classes distintas. 11 D IAGRAMA DE C LASSES Língua natural "Qualquer empregado é chefiado por no máximo um chefe." UML EmpregadoChefe  Chefia * 0..1 empregados chefe 12 D IAGRAMA DE C LASSES Agregação  Uma agregação representa um todo que é composto de várias partes. Exemplo: um conselho é um agregado de membros, da mesma forma que uma reunião é um agregado de uma pauta e de participantes. A implementação deste relacionamento não é uma contenção, pois uma reunião não CONTÉM participantes. Assim sendo, as partes da agregação podem fazer outras coisas em outras partes da aplicação. 13 D IAGRAMA DE C LASSES Língua natural "Uma empresa possui um número arbitrário de veículos." UML EmpresaVeículo * - frota 0..1 14 D IAGRAMA DE C LASSES Composição  A composição, diferentemente da agregação, é um relacionamento de contenção. Um objeto (container) CONTÉM outros objetos (elementos). Esses elementos que estão contidos dentro de outro objeto dependem dele para existir. Um exemplo de container poderia ser uma nota fiscal, e seus elementos seriam seus itens. Não faz sentido existirem itens de nota fiscal sem existir uma nota fiscal onde tais itens estariam contidos. E 15 D IAGRAMA DE C LASSES Língua natural "Um humano é composto por uma cabeça e dois braços." UML Humano Braço Cabeça 1 2 16 D IAGRAMA DE C LASSES 17 E XERCÍCIO Carregar ppt "D IAGRAMA DE C LASSES George Gomes Cabral. D IAGRAMA DE C LASSES Em POO, os problemas de programação são pensados em termos de objetos, nada de funções," Apresentações semelhantes Anúncios Google
__label__pos
0.613766
lkml.org  [lkml]   [2016]   [Nov]   [28]   [last100]   RSS Feed Views: [wrap][no wrap]   [headers]  [forward]    Messages in this thread / From Date Subjectnet/dccp: use-after-free in dccp_invalid_packet Hi! I've got the following error report while running the syzkaller fuzzer. On commit d8e435f3ab6fea2ea324dce72b51dd7761747523 (Nov 26). dh->dccph_doff is being accessed (line 731) right after skb was freed (line 732) in net/dccp/ipv4.c. A reproducer is attached. ================================================================== BUG: KASAN: use-after-free in dccp_invalid_packet+0x788/0x800 Read of size 1 at addr ffff880066f0e7c8 by task a.out/3895 page:ffffea00019bc380 count:1 mapcount:0 mapping: (null) index:0x0 compound_mapcount: 0 flags: 0x100000000004080(slab|head) page dumped because: kasan: bad access detected CPU: 1 PID: 3895 Comm: a.out Not tainted 4.9.0-rc6+ #457 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 ffff88006cd07758 ffffffff81c73b14 ffff88006cd077e8 ffff880066f0e7c8 00000000000000fa 00000000000000fb ffff88006cd077d8 ffffffff81637962 ffff88006cd07810 ffffffff82cc9c90 ffffffff82cabf7c 0000000000000296 Call Trace: <IRQ> [ 27.672034] [<ffffffff81c73b14>] dump_stack+0xb3/0x10f [< inline >] describe_address mm/kasan/report.c:259 [<ffffffff81637962>] kasan_report_error+0x122/0x560 mm/kasan/report.c:365 [< inline >] kasan_report mm/kasan/report.c:387 [<ffffffff81637dde>] __asan_report_load1_noabort+0x3e/0x40 mm/kasan/report.c:405 [<ffffffff839e8158>] dccp_invalid_packet+0x788/0x800 net/dccp/ipv4.c:732 [<ffffffff839f4fc1>] dccp_v6_rcv+0x21/0x1720 net/dccp/ipv6.c:658 [<ffffffff83418f13>] ip6_input_finish+0x423/0x15f0 net/ipv6/ip6_input.c:279 [< inline >] NF_HOOK_THRESH ./include/linux/netfilter.h:232 [< inline >] NF_HOOK ./include/linux/netfilter.h:255 [<ffffffff8341a1ae>] ip6_input+0xce/0x340 net/ipv6/ip6_input.c:322 [< inline >] dst_input ./include/net/dst.h:507 [<ffffffff834185ae>] ip6_rcv_finish+0x23e/0x780 net/ipv6/ip6_input.c:69 [< inline >] NF_HOOK_THRESH ./include/linux/netfilter.h:232 [< inline >] NF_HOOK ./include/linux/netfilter.h:255 [<ffffffff8341b4bd>] ipv6_rcv+0x109d/0x1dc0 net/ipv6/ip6_input.c:203 [<ffffffff82d0805b>] __netif_receive_skb_core+0x187b/0x2a10 net/core/dev.c:4208 [<ffffffff82d0921a>] __netif_receive_skb+0x2a/0x170 net/core/dev.c:4246 [<ffffffff82d0bbed>] process_backlog+0xed/0x6e0 net/core/dev.c:4855 [< inline >] napi_poll net/core/dev.c:5156 [<ffffffff82d0b4cd>] net_rx_action+0x76d/0xda0 net/core/dev.c:5221 [<ffffffff840f59ef>] __do_softirq+0x23f/0x8e5 kernel/softirq.c:284 [<ffffffff840f3c1c>] do_softirq_own_stack+0x1c/0x30 arch/x86/entry/entry_64.S:904 <EOI> [ 27.672034] [<ffffffff81251370>] do_softirq.part.17+0x60/0xa0 [< inline >] do_softirq kernel/softirq.c:176 [<ffffffff81251466>] __local_bh_enable_ip+0xb6/0xc0 kernel/softirq.c:181 [< inline >] local_bh_enable ./include/linux/bottom_half.h:31 [< inline >] rcu_read_unlock_bh ./include/linux/rcupdate.h:967 [<ffffffff8340b6c0>] ip6_finish_output2+0xb70/0x1f30 net/ipv6/ip6_output.c:122 [<ffffffff834152b9>] ip6_finish_output+0x3c9/0x7e0 net/ipv6/ip6_output.c:139 [< inline >] NF_HOOK_COND ./include/linux/netfilter.h:246 [<ffffffff8341588d>] ip6_output+0x1bd/0x6b0 net/ipv6/ip6_output.c:153 [< inline >] dst_output ./include/net/dst.h:501 [<ffffffff8357a116>] ip6_local_out+0x96/0x170 net/ipv6/output_core.c:170 [<ffffffff83417b63>] ip6_send_skb+0xa3/0x340 net/ipv6/ip6_output.c:1712 [<ffffffff83417eb5>] ip6_push_pending_frames+0xb5/0xe0 net/ipv6/ip6_output.c:1732 [< inline >] rawv6_push_pending_frames net/ipv6/raw.c:607 [<ffffffff83489a9e>] rawv6_sendmsg+0x1c4e/0x2c20 net/ipv6/raw.c:920 [<ffffffff832a1057>] inet_sendmsg+0x317/0x4e0 net/ipv4/af_inet.c:734 [< inline >] sock_sendmsg_nosec net/socket.c:621 [<ffffffff82c9d76c>] sock_sendmsg+0xcc/0x110 net/socket.c:631 [<ffffffff82c9f1b7>] ___sys_sendmsg+0x2d7/0x8b0 net/socket.c:1954 [<ffffffff82ca1888>] __sys_sendmmsg+0x158/0x390 net/socket.c:2044 [< inline >] SYSC_sendmmsg net/socket.c:2075 [<ffffffff82ca1af5>] SyS_sendmmsg+0x35/0x60 net/socket.c:2070 [<ffffffff840f2c41>] entry_SYSCALL_64_fastpath+0x1f/0xc2 arch/x86/entry/entry_64.S:209 The buggy address belongs to the object at ffff880066f0e780 which belongs to the cache kmalloc-512 of size 512 The buggy address ffff880066f0e7c8 is located 72 bytes inside of 512-byte region [ffff880066f0e780, ffff880066f0e980) Freed by task 3895: [<ffffffff811aa1b6>] save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57 [<ffffffff81636a76>] save_stack+0x46/0xd0 mm/kasan/kasan.c:495 [< inline >] set_track mm/kasan/kasan.c:507 [<ffffffff816372d3>] kasan_slab_free+0x73/0xc0 mm/kasan/kasan.c:571 [< inline >] slab_free_hook mm/slub.c:1352 [< inline >] slab_free_freelist_hook mm/slub.c:1374 [< inline >] slab_free mm/slub.c:2951 [<ffffffff816337b8>] kfree+0xe8/0x2b0 mm/slub.c:3871 [<ffffffff82cb6748>] skb_free_head+0x78/0xb0 net/core/skbuff.c:580 [<ffffffff82cc50fb>] pskb_expand_head+0x28b/0x8f0 net/core/skbuff.c:1244 [<ffffffff82cc954c>] __pskb_pull_tail+0xcc/0x1190 net/core/skbuff.c:1613 [< inline >] pskb_may_pull ./include/linux/skbuff.h:1966 [<ffffffff839e80bb>] dccp_invalid_packet+0x6eb/0x800 net/dccp/ipv4.c:731 [<ffffffff839f4fc1>] dccp_v6_rcv+0x21/0x1720 net/dccp/ipv6.c:658 [<ffffffff83418f13>] ip6_input_finish+0x423/0x15f0 net/ipv6/ip6_input.c:279 [< inline >] NF_HOOK_THRESH ./include/linux/netfilter.h:232 [< inline >] NF_HOOK ./include/linux/netfilter.h:255 [<ffffffff8341a1ae>] ip6_input+0xce/0x340 net/ipv6/ip6_input.c:322 [< inline >] dst_input ./include/net/dst.h:507 [<ffffffff834185ae>] ip6_rcv_finish+0x23e/0x780 net/ipv6/ip6_input.c:69 [< inline >] NF_HOOK_THRESH ./include/linux/netfilter.h:232 [< inline >] NF_HOOK ./include/linux/netfilter.h:255 [<ffffffff8341b4bd>] ipv6_rcv+0x109d/0x1dc0 net/ipv6/ip6_input.c:203 [<ffffffff82d0805b>] __netif_receive_skb_core+0x187b/0x2a10 net/core/dev.c:4208 [<ffffffff82d0921a>] __netif_receive_skb+0x2a/0x170 net/core/dev.c:4246 [<ffffffff82d0bbed>] process_backlog+0xed/0x6e0 net/core/dev.c:4855 [< inline >] napi_poll net/core/dev.c:5156 [<ffffffff82d0b4cd>] net_rx_action+0x76d/0xda0 net/core/dev.c:5221 [<ffffffff840f59ef>] __do_softirq+0x23f/0x8e5 kernel/softirq.c:284 Allocated by task 3895: [<ffffffff811aa1b6>] save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:57 [<ffffffff81636a76>] save_stack+0x46/0xd0 mm/kasan/kasan.c:495 [< inline >] set_track mm/kasan/kasan.c:507 [<ffffffff81636ceb>] kasan_kmalloc+0xab/0xe0 mm/kasan/kasan.c:598 [<ffffffff81637252>] kasan_slab_alloc+0x12/0x20 mm/kasan/kasan.c:537 [< inline >] slab_post_alloc_hook mm/slab.h:417 [< inline >] slab_alloc_node mm/slub.c:2708 [<ffffffff81635fab>] __kmalloc_node_track_caller+0xcb/0x390 mm/slub.c:4270 [<ffffffff82cb7671>] __kmalloc_reserve.isra.35+0x41/0xe0 net/core/skbuff.c:138 [<ffffffff82cc4f8c>] pskb_expand_head+0x11c/0x8f0 net/core/skbuff.c:1212 [<ffffffff82cc954c>] __pskb_pull_tail+0xcc/0x1190 net/core/skbuff.c:1613 [< inline >] pskb_may_pull ./include/linux/skbuff.h:1966 [<ffffffff839e804b>] dccp_invalid_packet+0x67b/0x800 net/dccp/ipv4.c:708 [<ffffffff839f4fc1>] dccp_v6_rcv+0x21/0x1720 net/dccp/ipv6.c:658 [<ffffffff83418f13>] ip6_input_finish+0x423/0x15f0 net/ipv6/ip6_input.c:279 [< inline >] NF_HOOK_THRESH ./include/linux/netfilter.h:232 [< inline >] NF_HOOK ./include/linux/netfilter.h:255 [<ffffffff8341a1ae>] ip6_input+0xce/0x340 net/ipv6/ip6_input.c:322 [< inline >] dst_input ./include/net/dst.h:507 [<ffffffff834185ae>] ip6_rcv_finish+0x23e/0x780 net/ipv6/ip6_input.c:69 [< inline >] NF_HOOK_THRESH ./include/linux/netfilter.h:232 [< inline >] NF_HOOK ./include/linux/netfilter.h:255 [<ffffffff8341b4bd>] ipv6_rcv+0x109d/0x1dc0 net/ipv6/ip6_input.c:203 [<ffffffff82d0805b>] __netif_receive_skb_core+0x187b/0x2a10 net/core/dev.c:4208 [<ffffffff82d0921a>] __netif_receive_skb+0x2a/0x170 net/core/dev.c:4246 [<ffffffff82d0bbed>] process_backlog+0xed/0x6e0 net/core/dev.c:4855 [< inline >] napi_poll net/core/dev.c:5156 [<ffffffff82d0b4cd>] net_rx_action+0x76d/0xda0 net/core/dev.c:5221 [<ffffffff840f59ef>] __do_softirq+0x23f/0x8e5 kernel/softirq.c:284 Memory state around the buggy address: ffff880066f0e680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffff880066f0e700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc >ffff880066f0e780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff880066f0e800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff880066f0e880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== // autogenerated by syzkaller (http://github.com/google/syzkaller) #ifndef __NR_socket #define __NR_socket 41 #endif #ifndef __NR_sendmsg #define __NR_sendmsg 46 #endif #ifndef __NR_sendmmsg #define __NR_sendmmsg 307 #endif #ifndef __NR_syz_emit_ethernet #define __NR_syz_emit_ethernet 1000006 #endif #ifndef __NR_syz_fuse_mount #define __NR_syz_fuse_mount 1000004 #endif #ifndef __NR_syz_fuseblk_mount #define __NR_syz_fuseblk_mount 1000005 #endif #ifndef __NR_syz_open_dev #define __NR_syz_open_dev 1000002 #endif #ifndef __NR_syz_open_pts #define __NR_syz_open_pts 1000003 #endif #ifndef __NR_mmap #define __NR_mmap 9 #endif #ifndef __NR_connect #define __NR_connect 42 #endif #ifndef __NR_syz_test #define __NR_syz_test 1000001 #endif #define SYZ_SANDBOX_NONE 1 #define _GNU_SOURCE #include <sys/ioctl.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sys/wait.h> #include <linux/capability.h> #include <linux/if.h> #include <linux/if_tun.h> #include <linux/sched.h> #include <net/if_arp.h> #include <assert.h> #include <dirent.h> #include <errno.h> #include <fcntl.h> #include <grp.h> #include <pthread.h> #include <setjmp.h> #include <signal.h> #include <stdarg.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> const int kFailStatus = 67; const int kErrorStatus = 68; const int kRetryStatus = 69; __attribute__((noreturn)) void fail(const char* msg, ...) { int e = errno; fflush(stdout); va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); exit(kFailStatus); } __attribute__((noreturn)) void exitf(const char* msg, ...) { int e = errno; fflush(stdout); va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); exit(kRetryStatus); } static int flag_debug; void debug(const char* msg, ...) { if (!flag_debug) return; va_list args; va_start(args, msg); vfprintf(stdout, msg, args); va_end(args); fflush(stdout); } __thread int skip_segv; __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* uctx) { if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED)) _longjmp(segv_env, 1); exit(sig); } static void install_segv_handler() { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2) { if (a0 == 0xc || a0 == 0xb) { char buf[128]; sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2); return open(buf, O_RDWR, 0); } else { char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf)); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } static uintptr_t syz_open_pts(uintptr_t a0, uintptr_t a1) { int ptyno = 0; if (ioctl(a0, TIOCGPTN, &ptyno)) return -1; char buf[128]; sprintf(buf, "/dev/pts/%d", ptyno); return open(buf, a1, 0); } static uintptr_t syz_fuse_mount(uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5) { uint64_t target = a0; uint64_t mode = a1; uint64_t uid = a2; uint64_t gid = a3; uint64_t maxread = a4; uint64_t flags = a5; int fd = open("/dev/fuse", O_RDWR); if (fd == -1) return fd; char buf[1024]; sprintf(buf, "fd=%d,user_id=%ld,group_id=%ld,rootmode=0%o", fd, (long)uid, (long)gid, (unsigned)mode & ~3u); if (maxread != 0) sprintf(buf + strlen(buf), ",max_read=%ld", (long)maxread); if (mode & 1) strcat(buf, ",default_permissions"); if (mode & 2) strcat(buf, ",allow_other"); syscall(SYS_mount, "", target, "fuse", flags, buf); return fd; } static uintptr_t syz_fuseblk_mount(uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7) { uint64_t target = a0; uint64_t blkdev = a1; uint64_t mode = a2; uint64_t uid = a3; uint64_t gid = a4; uint64_t maxread = a5; uint64_t blksize = a6; uint64_t flags = a7; int fd = open("/dev/fuse", O_RDWR); if (fd == -1) return fd; if (syscall(SYS_mknodat, AT_FDCWD, blkdev, S_IFBLK, makedev(7, 199))) return fd; char buf[256]; sprintf(buf, "fd=%d,user_id=%ld,group_id=%ld,rootmode=0%o", fd, (long)uid, (long)gid, (unsigned)mode & ~3u); if (maxread != 0) sprintf(buf + strlen(buf), ",max_read=%ld", (long)maxread); if (blksize != 0) sprintf(buf + strlen(buf), ",blksize=%ld", (long)blksize); if (mode & 1) strcat(buf, ",default_permissions"); if (mode & 2) strcat(buf, ",allow_other"); syscall(SYS_mount, blkdev, target, "fuseblk", flags, buf); return fd; } static uintptr_t execute_syscall(int nr, uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7, uintptr_t a8) { switch (nr) { default: return syscall(nr, a0, a1, a2, a3, a4, a5); case __NR_syz_test: return 0; case __NR_syz_open_dev: return syz_open_dev(a0, a1, a2); case __NR_syz_open_pts: return syz_open_pts(a0, a1); case __NR_syz_fuse_mount: return syz_fuse_mount(a0, a1, a2, a3, a4, a5); case __NR_syz_fuseblk_mount: return syz_fuseblk_mount(a0, a1, a2, a3, a4, a5, a6, a7); } } static void setup_main_process() { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); install_segv_handler(); char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) fail("failed to mkdtemp"); if (chmod(tmpdir, 0777)) fail("failed to chmod"); if (chdir(tmpdir)) fail("failed to chdir"); } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); unshare(CLONE_NEWNS); unshare(CLONE_NEWIPC); unshare(CLONE_IO); } static int do_sandbox_none() { int pid = fork(); if (pid) return pid; sandbox_common(); loop(); exit(1); } static void remove_dir(const char* dir) { DIR* dp; struct dirent* ep; int iter = 0; int i; retry: dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exitf("opendir(%s) failed due to NOFILE, exiting"); } exitf("opendir(%s) failed", dir); } while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); struct stat st; if (lstat(filename, &st)) exitf("lstat(%s) failed", filename); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } for (i = 0;; i++) { debug("unlink(%s)\n", filename); if (unlink(filename) == 0) break; if (errno == EROFS) { debug("ignoring EROFS\n"); break; } if (errno != EBUSY || i > 100) exitf("unlink(%s) failed", filename); debug("umount(%s)\n", filename); if (umount2(filename, MNT_DETACH)) exitf("umount(%s) failed", filename); } } closedir(dp); for (i = 0;; i++) { debug("rmdir(%s)\n", dir); if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EROFS) { debug("ignoring EROFS\n"); break; } if (errno == EBUSY) { debug("umount(%s)\n", dir); if (umount2(dir, MNT_DETACH)) exitf("umount(%s) failed", dir); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exitf("rmdir(%s) failed", dir); } } static uint64_t current_time_ms() { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) fail("clock_gettime failed"); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } long r[39]; void loop() { memset(r, -1, sizeof(r)); r[0] = execute_syscall(__NR_mmap, 0x20000000ul, 0xe8b000ul, 0x3ul, 0x32ul, 0xfffffffffffffffful, 0x0ul, 0, 0, 0); r[1] = execute_syscall(__NR_socket, 0xaul, 0x80003ul, 0x21ul, 0, 0, 0, 0, 0, 0); NONFAILING(memcpy((void*)0x20e7dfe4, "\x0a\x00\x42\x42\xa0\xae\x78" "\x03\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x01\xc1\x97\xc4\x9e", 28)); r[3] = execute_syscall(__NR_connect, r[1], 0x20e7dfe4ul, 0x1cul, 0, 0, 0, 0, 0, 0); NONFAILING(*(uint64_t*)0x20e83000 = (uint64_t)0x20e80000); NONFAILING(*(uint32_t*)0x20e83008 = (uint32_t)0x0); NONFAILING(*(uint64_t*)0x20e83010 = (uint64_t)0x2061bfd0); NONFAILING(*(uint64_t*)0x20e83018 = (uint64_t)0x2); NONFAILING(*(uint64_t*)0x20e83020 = (uint64_t)0x20027000); NONFAILING(*(uint64_t*)0x20e83028 = (uint64_t)0x1); NONFAILING(*(uint32_t*)0x20e83030 = (uint32_t)0x4); NONFAILING(*(uint64_t*)0x2061bfd0 = (uint64_t)0x20e80f0d); NONFAILING(*(uint64_t*)0x2061bfd8 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x2061bfe0 = (uint64_t)0x20e83000); NONFAILING(*(uint64_t*)0x2061bfe8 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20027000 = (uint64_t)0x10); NONFAILING(*(uint32_t*)0x20027008 = (uint32_t)0x3); NONFAILING(*(uint32_t*)0x2002700c = (uint32_t)0x80); r[18] = execute_syscall(__NR_sendmsg, r[1], 0x20e83000ul, 0x8000ul, 0, 0, 0, 0, 0, 0); NONFAILING(*(uint64_t*)0x20e73000 = (uint64_t)0x0); NONFAILING(*(uint32_t*)0x20e73008 = (uint32_t)0x0); NONFAILING(*(uint64_t*)0x20e73010 = (uint64_t)0x20e80000); NONFAILING(*(uint64_t*)0x20e73018 = (uint64_t)0x5); NONFAILING(*(uint64_t*)0x20e73020 = (uint64_t)0x20e77000); NONFAILING(*(uint64_t*)0x20e73028 = (uint64_t)0x0); NONFAILING(*(uint32_t*)0x20e73030 = (uint32_t)0x0); NONFAILING(*(uint64_t*)0x20e80000 = (uint64_t)0x20e85f97); NONFAILING(*(uint64_t*)0x20e80008 = (uint64_t)0x69); NONFAILING(*(uint64_t*)0x20e80010 = (uint64_t)0x20e86f39); NONFAILING(*(uint64_t*)0x20e80018 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20e80020 = (uint64_t)0x20e87000); NONFAILING(*(uint64_t*)0x20e80028 = (uint64_t)0x0); NONFAILING(*(uint64_t*)0x20e80030 = (uint64_t)0x20e88f01); NONFAILING(*(uint64_t*)0x20e80038 = (uint64_t)0xff); NONFAILING(*(uint64_t*)0x20e80040 = (uint64_t)0x20e89f9f); NONFAILING(*(uint64_t*)0x20e80048 = (uint64_t)0x0); NONFAILING(memcpy( (void*)0x20e85f97, "\x39\xa4\x8d\x53\x4e\x54\x32\xc4\x2a\x71\xb9\xf1\xff\x1d\xd9\x47" "\x78\x37\xb6\x72\xba\x74\xc9\xc3\xf1\x5f\x46\x3e\x14\xbb\xb9\x59" "\xa3\x88\x40\x9c\x25\x1d\x5c\xf1\xa3\xca\x7e\xa6\x55\x44\x01\x01" "\x9d\xab\x07\x96\x46\xa8\xe9\xa5\x2e\x74\x45\x8a\x00\xee\x71\xe6" "\xab\x97\x46\xd2\x04\x32\xae\xb2\x68\x66\xcc\x0b\xf3\x0e\x7f\x8c" "\x8e\x5e\xd0\xd8\x98\x7e\x54\x15\xa8\x03\x15\x1a\xb9\x9a\xf2\xdf" "\x8e\x3b\xe2\xb8\xe7\xee\x46\xa5\x67", 105)); NONFAILING(memcpy( (void*)0x20e88f01, "\xfb\xba\xc0\xcf\x43\x0e\x9b\x34\x87\x5d\xa7\x7c\x88\x45\xe2\xd0" "\x52\xbd\xaa\x84\xc2\xcd\x2b\xf2\x89\x73\xcc\x7f\x08\x06\xd6\xe9" "\x88\xb7\x2d\xdb\x8a\xc4\x65\xb7\x08\x6b\x96\x9f\x7e\x13\xfe\x1c" "\x73\x42\x07\x7c\xac\xc7\x89\x8a\xd3\xad\x57\x5b\x22\x9c\x48\x65" "\x37\x86\x1f\xf0\xce\x2b\x22\xf1\x5c\x48\xaf\x63\x66\x34\x14\x19" "\xba\xab\xf0\x83\x71\x6f\x19\xea\xd9\x9d\x25\x2f\xe5\x3d\xb1\x5f" "\x98\xb5\x50\xc4\x6c\xd1\xe7\xe8\x77\x68\xdc\x4c\xbc\x94\x34\x53" "\x73\xbe\x9c\x48\x5d\x87\x20\x79\x0d\x95\x62\xc1\x60\xea\xe3\x92" "\x06\xed\x92\xd9\xb2\x76\xcb\xe6\x14\xd1\x72\xd1\x4e\x20\xed\x43" "\x81\x67\x82\xf9\x87\xd4\x82\xd7\x98\xcf\x7f\xe0\x7a\x97\x0c\xd1" "\xf7\x04\x11\x06\xef\x18\x44\xd0\xd3\x69\x04\x00\x42\x33\xc7\x40" "\xdd\xca\x8e\xa3\x32\x52\x9d\x54\x31\x57\xcd\x01\x66\x33\xd2\x97" "\xc6\xe6\xa6\x6c\x30\xf2\x8c\x80\xca\x75\xf1\x6b\x11\x71\xfd\x9b" "\x05\x94\xf1\x56\x87\x40\xee\xb1\x7f\x0a\xb2\x9c\x92\x1a\xb0\xbc" "\xb3\x18\x59\xb6\xb3\x84\x71\xdb\xff\x3e\x4c\x11\x4f\x7f\x04\x9f" "\xdf\x7f\x09\xb7\xe2\xf0\x6f\xa9\x35\x22\x93\x09\x81\x18\xd7", 255)); r[38] = execute_syscall(__NR_sendmmsg, r[1], 0x20e73000ul, 0x1ul, 0x4004ul, 0, 0, 0, 0, 0); } int main() { setup_main_process(); int pid = do_sandbox_none(); int status = 0; while (waitpid(pid, &status, __WALL) != pid) { } return 0; } \    \ /   Last update: 2016-11-28 14:22    [W:0.060 / U:0.308 seconds] ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site  
__label__pos
0.537503
Practice GMAT Problem Solving Question Return to the list of practice GMAT problem solving questions. rss In baseball, the batting average is defined as the ratio of a player’s hits to at bats. If a player had anywhere from 4 to 6 at bats in a recent game and had anywhere from 2 to 3 hits in the same game, the player’s actual batting average for that game could fall anywhere between Correct Answer: C 1. The ratio of a batting average is a fraction. As you decrease the numerator or increase the denominator, the fraction becomes smaller. Likewise, as you increase the numerator or decrease the denominator, the fraction becomes larger. 2. In the case of a batting average, the numerator is "hits" (H) while the denominator is "at bats" (B). Thus, the ratio we are looking at is: H/B, where 2<H<3 and 4<B<6. 3. To find the lowest value that the batting average could be, we want to assume the lowest numerator (hits of 2) and the highest denominator (at bats of 6): 2/6 = 0.333. 4. Likewise, to find the highest value that the batting average could be, we want to assume the highest numerator (hits of 3) and the lowest denominator (at bats of 4): 3/4 = 0.75. 5. Combining these answers yields the correct answer C: between 0.33 and 0.75. Return to the list of practice GMAT problem solving questions.
__label__pos
0.99511
How many 1/3 -cup serving are there in 4 cups?​ Students were asked to answer a question at academics and to declare what is most important for them to succeed. The one that response stood out from the rest was practice. Persons who surely are successful do not become successful by being born. They work hard and dedication their lives to succeeding. This is how you can reach your goals. following some question and answer examples that you could actually benefit from to enriches your knowledge and gain insight that will assist you to maintain your school studies. Question: How many 1/3 -cup serving are there in 4 cups?​ Answer: Based on the amount of servings required and the number of cups, the number of 1/3 cup servings is 12 cup servings There are 4 cups and from these cups, 1/3 cup servings will be taken. The number of 1/3 cups servings is therefore: = Number of cups / Quantity of servings = 4 ÷ 1/3 = 4 x 3/1 = 12/1 = 12 cup servings In conclusion, there will be 12 cup servings. From the answer and question examples above, hopefully, they can possibly assist the student handle the question they had been looking for and keep in mind of all sorts of things declared in the answer above. You could simply then have a discussion with your classmate and continue the school learning by studying the subject jointly. READ MORE  Which statement best illustrates an example of economic specialization? Leave a Reply Your email address will not be published.
__label__pos
0.979647
4 votes 1answer 167 views What does the command “$()” do in UNIX? What does the command $() do in UNIX? Could someone explain what is the significance of $ in the below examples; $(echo var=10) and eval $(echo var=10) 4 votes 3answers 2k views Split command output by linebreak? I have a command returning multiple lines. For further processing I need to process each single line of those lines. My current code works by modifying the IFS (Internal Field Separator): ...
__label__pos
1
Packaging Survey first results by Tarek Ziadé Around 570 people answered the survey, which is a great number I didn’t expect. Thanks again to Massimo for his help on this. I have a lot of work to read all the open question answers, and all the comments that goes with the “other” answer, but I wanted to publish the results of the closed questions before the summit. I don’t want to comment the results yet. I will after I have studied all answers, so it’ll be a little while 😉 Who are you ? Professional developer using Python exclusively. 283 Professional developer using Python unable to use Python “at work”. 34 Professional developer using Python sometimes. 196 Hobbyist using Python. 116 Where are you located ? USA 212 Western Europe 268 Eastern Europe 42 Asia 18 Africa 9 Other 70 If you are a web programmer, what is the framework you use the most ? Pylons 55 TG 2 14 TG 1 15 Django 184 Zope (including Plone) 137 Other 207 How do you organize your application code most of the time ? I put everything in one package 171 I create several packages and use a tool like zc.buildout or Paver to distribute the whole application 137 I create several packages and use a main package or script to launch the application 198 I use my own mechanism for aggregating packages into a single install. 67 For libraries you don’t distribute publicly, do you you create a setup.py script ? Yes 321 No 249 What is the main tool or combination of tools you are using to package and distribute your Python application ? None 80 setuptools 150 distutils 127 zc.buildout and distutils 10 zc.buildout and setuptools 107 Paver and setuptools 9 Paver and Distutils 3 Other 64 How do you install a package that does not provide a standalone installer (but provides a standard setup.py script) most of the time ? I use easy_install 241 I download it and manually run the python setup.py install command 139 I use pip 34 I move files around and create symlinks manually. 7 I use the packaging tool provided in my system (apt, yum, etc) 81 Other 33 How do you remove a package ? manually, by removing the directory and fixing the .pth files 275 I use one virtualenv per application, so the main python is never polluted, and only remove entire environments. 154 using the packaging tool (apt, yum, etc) 178 I don’t know / I fail at uninstallation 79 I change PYTHONPATH to include a directory of the packages used by my application, then remove just that directory 31 Other 10 How do you manage using more than one version of a library on a system ? I don’t use multiple versions of a library 217 I use virtualenv 203 I use Setuptools’ multi-version features 46 I build fresh Python interpreter from source for each project 16 I use zc.buildout 109 I set sys.path in my scripts 48 I set PYTHONPATH to select particular libraries 49 Other 23 Do you work with setuptools’ namespace packages ? Yes 178 No 344 Has PyPI become mandatory in your everyday work (if you use zc.buildout for example) ? Yes 228 No 294 If you previously answered Yes, did you set up an alternative solution (mirror, cache..) in case PyPI is down ? Yes 77 N/A 277 No 166 Do you register your packages on PyPI ? Yes 239 No 281 Do you upload your package on PyPI ? Yes 205 No 314 If you previously answered No, how do you distribute your packages ? One my own website, using simple links 139 One my own website, using a PyPI-like server 50 On a forge, like sourceforge N/A 251 Other 56 Advertisements
__label__pos
0.995584
Problem with decals When I fire a shot from my rifle it leaves a decal. Unfortunately, whenever it hits any corner, the decal instead of leaving a normal mark, stretches. How could I possibly fix this? It’s a bit of a pain, but I think you can fix it with a world aligned material: EDIT: I think notice, that vid is absolutely no use, so here's one that is:
__label__pos
0.996114
/[escript]/trunk/pyvisi/py_src/ellipsoid.py ViewVC logotype Contents of /trunk/pyvisi/py_src/ellipsoid.py Parent Directory Parent Directory | Revision Log Revision Log Revision 1037 - (show annotations) Fri Mar 16 05:00:32 2007 UTC (13 years, 7 months ago) by jongui File MIME type: text/x-python File size: 11444 byte(s) Added the updated files. 1 """ 2 @author: John NGUI 3 """ 4 5 import vtk 6 from mapper import DataSetMapper 7 from lookuptable import LookupTable 8 from actor import Actor3D 9 from constant import Viewport, Color, Lut, VizType, ColorMode 10 from sphere import Sphere 11 from normals import Normals 12 from glyph import TensorGlyph 13 from outline import Outline 14 from point import StructuredPoints 15 from probe import Probe 16 17 # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, 18 # StructuredPoints and Probe were inherited to allow access to their 19 # public methods from the driver. 20 class Ellipsoid(DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, 21 StructuredPoints, Probe): 22 """ 23 Class that shows a tensor field using ellipsoids. The ellipsoids can either 24 be colored or grey-scaled, depending on the lookup table used. 25 """ 26 27 # The SOUTH_WEST default viewport is used when there is only one viewport. 28 # This saves the user from specifying the viewport when there is only one. 29 # If no lut is specified, the color scheme will be used. 30 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, 31 lut = Lut.COLOR, outline = True): 32 """ 33 @type scene: L{Scene <scene.Scene>} object 34 @param scene: Scene in which objects are to be rendered on 35 @type data_collector: L{DataCollector <datacollector.DataCollector>} 36 object 37 @param data_collector: Deal with source of data for visualisation 38 @type viewport: L{Viewport <constant.Viewport>} constant 39 @param viewport: Viewport in which objects are to be rendered on 40 @type lut : L{Lut <constant.Lut>} constant 41 @param lut: Lookup table color scheme 42 @type outline: Boolean 43 @param outline: Places an outline around the domain surface 44 """ 45 46 # NOTE: Actor3D is inherited and there are two instances declared here. 47 # As a result, when methods from Actor3D is invoked from the driver, 48 # only the methods associated with the latest instance (which in this 49 # case is the Actor3D for the Ellipsoid) can be executed. Actor3D 50 # methods associated with Outline cannot be invoked from the driver. 51 # They can only be called within here, which is why Outline must be 52 # place before Ellipsoid as there is unlikely to be any changes 53 # made to the Outline's Actor3D. 54 55 # ----- Outline ----- 56 57 if(outline == True): 58 outline = Outline(data_collector._getOutput()) 59 DataSetMapper.__init__(self, outline._getOutput()) 60 61 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) 62 # Default outline color is black. 63 Actor3D.setColor(self, Color.BLACK) 64 65 # Default line width is 1. 66 Actor3D._setLineWidth(self, 1) 67 scene._addActor3D(viewport, Actor3D._getActor3D(self)) 68 69 # ----- Ellipsoid ----- 70 71 # NOTE: Lookup table color mapping (color or grey scale) MUST be set 72 # before DataSetMapper. If it is done after DataSetMapper, no effect 73 # will take place. 74 if(lut == Lut.COLOR): # Colored lookup table. 75 lookup_table = LookupTable() 76 lookup_table._setTableValue() 77 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. 78 lookup_table = LookupTable() 79 lookup_table._setLookupTableToGreyScale() 80 81 StructuredPoints.__init__(self, data_collector._getOutput()) 82 Probe.__init__(self, data_collector._getOutput(), 83 StructuredPoints._getStructuredPoints(self)) 84 85 Sphere.__init__(self) 86 TensorGlyph.__init__(self, Probe._getOutput(self), 87 Sphere._getOutput(self)) 88 Normals.__init__(self, TensorGlyph._getOutput(self)) 89 90 DataSetMapper.__init__(self, Normals._getOutput(self), 91 lookup_table._getLookupTable()) 92 DataSetMapper._setScalarRange(self, data_collector._getScalarRange()) 93 94 data_collector._paramForUpdatingMultipleSources(VizType.ELLIPSOID, 95 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self)) 96 97 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) 98 scene._addActor3D(viewport, Actor3D._getActor3D(self)) 99 100 101 ############################################################################### 102 103 104 from transform import Transform 105 from plane import Plane 106 from cutter import Cutter 107 108 # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, Transform, Plane, 109 # Cutter, StructuredPoints and Probe were inherited to allow access to 110 # their public methods from the driver. 111 class EllipsoidOnPlaneCut(DataSetMapper, Actor3D, Sphere, Normals, 112 TensorGlyph, Transform, Plane, Cutter, StructuredPoints, Probe): 113 """ 114 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>}, 115 except that it shows a tensor field using ellipsoids cut using a plane. 116 """ 117 118 # The SOUTH_WEST default viewport is used when there is only one viewport. 119 # This saves the user from specifying the viewport when there is only one. 120 # If no lut is specified, the color scheme will be used. 121 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, 122 lut = Lut.COLOR, outline = True): 123 """ 124 @type scene: L{Scene <scene.Scene>} object 125 @param scene: Scene in which objects are to be rendered on 126 @type data_collector: L{DataCollector <datacollector.DataCollector>} 127 object 128 @param data_collector: Deal with source of data for visualisation 129 @type viewport: L{Viewport <constant.Viewport>} constant 130 @param viewport: Viewport in which objects are to be rendered on 131 @type lut : L{Lut <constant.Lut>} constant 132 @param lut: Lookup table color scheme 133 @type outline: Boolean 134 @param outline: Places an outline around the domain surface 135 """ 136 137 # NOTE: Actor3D is inherited and there are two instances declared here. 138 # As a result, when methods from Actor3D is invoked from the driver, 139 # only the methods associated with the latest instance (which in this 140 # case is the Actor3D for the Ellipsoid) can be executed. Actor3D 141 # methods associated with Outline cannot be invoked from the driver. 142 # They can only be called within here, which is why Outline must be 143 # place before Ellipsoid as there is unlikely to be any changes 144 # made to the Outline's Actor3D. 145 146 # ----- Outline ----- 147 148 if(outline == True): 149 outline = Outline(data_collector._getOutput()) 150 DataSetMapper.__init__(self, outline._getOutput()) 151 152 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) 153 # Default outline color is black. 154 Actor3D.setColor(self, Color.BLACK) 155 156 # Default line width is 1. 157 Actor3D._setLineWidth(self, 1) 158 scene._addActor3D(viewport, Actor3D._getActor3D(self)) 159 160 # ----- Ellipsoid on a cut plane ----- 161 162 # NOTE: Lookup table color mapping (color or grey scale) MUST be set 163 # before DataSetMapper. If it is done after DataSetMapper, no effect 164 # will take place. 165 if(lut == Lut.COLOR): # Colored lookup table. 166 lookup_table = LookupTable() 167 lookup_table._setTableValue() 168 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. 169 lookup_table = LookupTable() 170 lookup_table._setLookupTableToGreyScale() 171 172 Transform.__init__(self) 173 Plane.__init__(self, Transform._getTransform(self)) 174 175 StructuredPoints.__init__(self, data_collector._getOutput()) 176 Probe.__init__(self, data_collector._getOutput(), 177 StructuredPoints._getStructuredPoints(self)) 178 179 Cutter.__init__(self, Probe._getOutput(self), 180 Plane._getPlane(self)) 181 Sphere.__init__(self) 182 183 TensorGlyph.__init__(self, Cutter._getOutput(self), 184 Sphere._getOutput(self)) 185 Normals.__init__(self, TensorGlyph._getOutput(self)) 186 187 DataSetMapper.__init__(self, Normals._getOutput(self), 188 lookup_table._getLookupTable()) 189 DataSetMapper._setScalarRange(self, data_collector._getScalarRange()) 190 191 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) 192 scene._addActor3D(viewport, Actor3D._getActor3D(self)) 193 194 195 ############################################################################### 196 197 198 from clipper import Clipper 199 200 # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, Transform, Plane, 201 # Clipper, StructuredPoints and Probe were inherited to allow access to 202 # their public methods from the driver. 203 class EllipsoidOnPlaneClip(DataSetMapper, Actor3D, Sphere, Normals, 204 TensorGlyph, Transform, Plane, Clipper, StructuredPoints, Probe): 205 """ 206 This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>}, 207 except that it shows a tensor field using ellipsoids clipped using a plane. 208 """ 209 210 # The SOUTH_WEST default viewport is used when there is only one viewport. 211 # This saves the user from specifying the viewport when there is only one. 212 # If no lut is specified, the color scheme will be used. 213 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, 214 lut = Lut.COLOR, outline = True): 215 """ 216 @type scene: L{Scene <scene.Scene>} object 217 @param scene: Scene in which objects are to be rendered on 218 @type data_collector: L{DataCollector <datacollector.DataCollector>} 219 object 220 @param data_collector: Deal with source of data for visualisation 221 @type viewport: L{Viewport <constant.Viewport>} constant 222 @param viewport: Viewport in which object are to be rendered on 223 @type lut : L{Lut <constant.Lut>} constant 224 @param lut: Lookup table color scheme 225 @type outline: Boolean 226 @param outline: Places an outline around the domain surface 227 """ 228 229 # NOTE: Actor3D is inherited and there are two instances declared here. 230 # As a result, when methods from Actor3D is invoked from the driver, 231 # only the methods associated with the latest instance (which in this 232 # case is the Actor3D for the Ellipsoid) can be executed. Actor3D 233 # methods associated with Outline cannot be invoked from the driver. 234 # They can only be called within here, which is why Outline must be 235 # place before Ellipsoid as there is unlikely to be any changes 236 # made to the Outline's Actor3D. 237 238 # ----- Outline ----- 239 240 if(outline == True): 241 outline = Outline(data_collector._getOutput()) 242 DataSetMapper.__init__(self, outline._getOutput()) 243 244 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) 245 # Default outline color is black. 246 Actor3D.setColor(self, Color.BLACK) 247 248 # Default line width is 1. 249 Actor3D._setLineWidth(self, 1) 250 scene._addActor3D(viewport, Actor3D._getActor3D(self)) 251 252 # ----- Ellipsoid on a clipped plane ----- 253 254 # NOTE: Lookup table color mapping (color or grey scale) MUST be set 255 # before DataSetMapper. If it is done after DataSetMapper, no effect 256 # will take place. 257 if(lut == Lut.COLOR): # Colored lookup table. 258 lookup_table = LookupTable() 259 lookup_table._setTableValue() 260 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. 261 lookup_table = LookupTable() 262 lookup_table._setLookupTableToGreyScale() 263 264 Transform.__init__(self) 265 Plane.__init__(self, Transform._getTransform(self)) 266 267 StructuredPoints.__init__(self, data_collector._getOutput()) 268 Probe.__init__(self, data_collector._getOutput(), 269 StructuredPoints._getStructuredPoints(self)) 270 271 # NOTE: TensorGlyph must come before Clipper. Otherwise the output 272 # will be incorrect. 273 Sphere.__init__(self) 274 TensorGlyph.__init__(self, Probe._getOutput(self), 275 Sphere._getOutput(self)) 276 277 Normals.__init__(self, TensorGlyph._getOutput(self)) 278 # NOTE: Clipper must come after TensorGlyph. Otherwise the output 279 # will be incorrect. 280 Clipper.__init__(self, Normals._getOutput(self), 281 Plane._getPlane(self)) 282 Clipper._setClipFunction(self) 283 284 DataSetMapper.__init__(self, Clipper._getOutput(self), 285 lookup_table._getLookupTable()) 286 DataSetMapper._setScalarRange(self, data_collector._getScalarRange()) 287 288 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) 289 scene._addActor3D(viewport, Actor3D._getActor3D(self)) 290   ViewVC Help Powered by ViewVC 1.1.26  
__label__pos
0.818576
Take the 2-minute tour × Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required. I had the following code, which was basically, class foo { public: void method(); }; void foo::foo::method() { } I had accidentally added an extra foo:: in front of the definition of foo::method. This code compiled without warning using g++(ver 4.2.3), but errored out using Visual Studio 2005. I didn't have a namespace named foo. Which compiler is correct? share|improve this question 1   I copied that code as is to a single file project and added an empty main function. This actually compiles under gcc 4.3.3. –  Matt Aug 12 '09 at 1:45 1   I can confirm that this indeed compile on g++ without warnings (I've tried it on 3.4.5 mingw) without any namespaces or anything. On the other hand MSVC2008 rejects it. Very strange. –  Tamas Czinege Aug 12 '09 at 1:46 1   Strange, with i686-apple-darwin8-g++-4.0.1, I could add as many foo:: as I wanted, and it compiled without warning, even with -Wall -Wextra. –  Adam Rosenfield Aug 12 '09 at 1:50 2   Lol, the first person to actually find a bug in g++/gcc! –  Hooked Aug 12 '09 at 2:06 2   Hardly the first. :) –  Greg Hewgill Aug 12 '09 at 3:00 show 9 more comments 4 Answers up vote 25 down vote accepted If I read the standard correctly, g++ is right and VS is wrong. ISO-IEC 14882-2003(E), §9.2 Classes (pag.153): A class-name is inserted into the scope in which it is declared immediately after the class-name is seen. The class-name is also inserted into the scope of the class itself; this is known as the injected-class-name. For purposes of access checking, the injected-class-name is treated as if it were a public member name. Following on the comments below, it's also particularly useful to retain the following concerning the actual Name Lookup rules: ISO-IEC 14882-2003(E), §3.4-3 Name Lookup (pag.29): The injected-class-name of a class (clause 9) is also considered to be a member of that class for the purposes of name hiding and lookup. It would be odd if it wasn't, given the final part of text at 9.2. But as litb commented this reassures us that indeed g++ is making a correct interpretation of the standard. No questions are left. share|improve this answer 1   Interesting, does this explain the fact that foo::foo::foo::method also works? –  MikeT Aug 12 '09 at 3:13 2   Not entirely, no. The description for that I believe can be found 3.4.3.1 - Qualified Name Lookup: The name of a class or namespace member can be referred to after the :: scope resolution operator (5.1) applied to a nested-name-specifier that nominates its class or namespace. During the lookup for a name preceding the :: scope resolution operator, object, function, and enumerator names are ignored. If the name found is not a class-name (clause 9) or namespace-name (7.3.1), the program is ill-formed –  Alexandre Bell Aug 12 '09 at 3:24      Of especial note, "During the lookup for a name preceding the :: scope resolution operator, object, function, and enumerator names are ignored." –  Alexandre Bell Aug 12 '09 at 3:25 2   Another quote: "The injected-class-name of a class (clause 9) is also considered to be a member of that class for the purposes of name hiding and lookup." from 3.4/3. Lookup in classes is defined in terms of member names - so it takes this quote to actually make it valid for cases like in the question. Note that comeau is wrong with struct A { void f() { A::A a; } }; rejecting that valid code :) If you include that quote in your answer, i will +1 you xD –  Johannes Schaub - litb Aug 13 '09 at 0:45      Certainly litb. But no need for the +1. I find 9.2 self-explanatory in many regards. But I do agree 3.4/3 makes it a lot more evident. A moment while I look it up on my copy of the standards... –  Alexandre Bell Aug 13 '09 at 1:17 show 1 more comment Krugar has the correct answer here. The name that is is being found each time is the injected class name. The following is an example which shows at least one reason why the compiler adds the injected class name: namespace NS { class B { // injected name B // #1 public: void foo (); }; int i; // #2 } class B // #3 { public: void foo (); }; int i; // #4 class A :: NS::B { public: void bar () { ++i; // Lookup for 'i' searches scope of // 'A', then in base 'NS::B' and // finally in '::'. Finds #4 B & b = *this; // Lookup for 'B' searches scope of 'A' // then in base 'NS::B' and finds #1 // the injected name 'B'. } }; Without the injected name the current lookup rules would eventually reach the enclosing scope of 'A' and would find '::B' and not 'NS::B'. We would therefore need to use "NS::B" everywhere in A when we wanted to refer to the base class. Another place that injected names get used are with templates, where inside the class template, the injected name provides a mapping between the template name and the type: template <typename T> class A { // First injected name 'A<T>' // Additional injected name 'A' maps to 'A<T>' public: void foo () { // '::A' here is the template name // 'A' is the type 'A<T>' // 'A<T>' is also the type 'A<T>' } }; share|improve this answer add comment Comeau online accepts it without any hickups, so it's either valid or the second bug in como I have found in almost ten years. share|improve this answer add comment Is there a namespace foo in some other module that you include (and you were just ignorant of it)? Otherwise, it is not correct. I am not sure why g++ allowed this. share|improve this answer      Actually, g++ allows it. I just tested. –  Matt Aug 12 '09 at 1:46      "I am not sure why g++ allowed this." –  Hooked Aug 12 '09 at 2:06 add comment Your Answer   discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged or ask your own question.
__label__pos
0.601297
Bergabunglah dengan TensorFlow di Google I/O, 11-12 Mei Daftar sekarang Komponen Pipa TFX InfraValidator InfraValidator adalah komponen TFX yang digunakan sebagai lapisan peringatan dini sebelum mendorong model ke dalam produksi. Nama validator "infra" berasal dari fakta bahwa ia memvalidasi model dalam model aktual yang melayani "infrastruktur". Jika Evaluator adalah untuk menjamin kinerja model, InfraValidator adalah untuk menjamin model secara mekanik baik dan mencegah model buruk dari didorong. Bagaimana cara kerjanya? InfraValidator mengambil model, meluncurkan server model kotak pasir dengan model, dan melihat apakah itu dapat berhasil dimuat dan ditanyakan secara opsional. Hasil infra validasi akan dihasilkan dalam blessing output dalam cara yang sama seperti Evaluator tidak. InfraValidator berfokus pada kompatibilitas antara biner server model (misalnya TensorFlow Melayani ) dan model untuk menyebarkan. Meskipun nama "infra" validator, itu adalah tanggung jawab pengguna untuk mengkonfigurasi lingkungan dengan benar, dan infra validator hanya berinteraksi dengan server model dalam lingkungan-dikonfigurasi pengguna untuk melihat apakah ia bekerja dengan baik. Mengonfigurasi lingkungan ini dengan benar akan memastikan bahwa validasi infra yang lolos atau gagal akan menjadi indikasi apakah model akan dapat ditayangkan di lingkungan penyajian produksi. Ini menyiratkan beberapa, tetapi tidak terbatas pada, berikut ini: 1. InfraValidator menggunakan model server biner yang sama seperti yang akan digunakan dalam produksi. Ini adalah tingkat minimal di mana lingkungan validasi infra harus menyatu. 2. InfraValidator menggunakan sumber daya yang sama (misalnya jumlah alokasi dan jenis CPU, memori, dan akselerator) seperti yang akan digunakan dalam produksi. 3. InfraValidator menggunakan konfigurasi server model yang sama seperti yang akan digunakan dalam produksi. Tergantung pada situasinya, pengguna dapat memilih sejauh mana InfraValidator harus identik dengan lingkungan produksi. Secara teknis, sebuah model dapat divalidasi infra di lingkungan Docker lokal dan kemudian disajikan di lingkungan yang sama sekali berbeda (misalnya cluster Kubernetes) tanpa masalah. Namun, InfraValidator tidak akan memeriksa perbedaan ini. Mode operasi Tergantung pada konfigurasi, validasi infra dilakukan dalam salah satu mode berikut: • LOAD_ONLY modus: memeriksa apakah model itu berhasil dimuat dalam infrastruktur melayani atau tidak. ATAU • LOAD_AND_QUERY modus: LOAD_ONLY modus ditambah mengirimkan beberapa permintaan sampel untuk memeriksa apakah model mampu melayani kesimpulan. InfraValidator tidak peduli prediksi itu benar atau tidak. Hanya apakah permintaan itu berhasil atau tidak yang penting. Bagaimana cara menggunakannya? Biasanya InfraValidator didefinisikan di sebelah komponen Evaluator, dan outputnya diumpankan ke Pusher. Jika InfraValidator gagal, model tidak akan didorong. evaluator = Evaluator( model=trainer.outputs['model'], examples=example_gen.outputs['examples'], baseline_model=model_resolver.outputs['model'], eval_config=tfx.proto.EvalConfig(...) ) infra_validator = InfraValidator( model=trainer.outputs['model'], serving_spec=tfx.proto.ServingSpec(...) ) pusher = Pusher( model=trainer.outputs['model'], model_blessing=evaluator.outputs['blessing'], infra_blessing=infra_validator.outputs['blessing'], push_destination=tfx.proto.PushDestination(...) ) Mengonfigurasi komponen InfraValidator. Ada tiga jenis proto untuk mengkonfigurasi InfraValidator. ServingSpec ServingSpec adalah konfigurasi penting yang paling untuk InfraValidator tersebut. Ini mendefinisikan: • apa jenis server model ke model run • di mana untuk menjalankannya Untuk jenis server model (disebut biner penyajian) kami mendukung Platform penyajian berikut saat ini didukung: • Docker Lokal (Docker harus diinstal terlebih dahulu) • Kubernetes (dukungan terbatas hanya untuk KubeflowDagRunner) Pilihan untuk melayani biner dan melayani platform yang dibuat dengan menentukan oneof blok ServingSpec . Misalnya menggunakan TensorFlow Melayani biner berjalan pada cluster Kubernetes, tensorflow_serving dan kubernetes lapangan harus ditetapkan. infra_validator=InfraValidator( model=trainer.outputs['model'], serving_spec=tfx.proto.ServingSpec( tensorflow_serving=tfx.proto.TensorFlowServing( tags=['latest'] ), kubernetes=tfx.proto.KubernetesConfig() ) ) Untuk mengkonfigurasi lanjut ServingSpec , silahkan periksa definisi protobuf . ValidationSpec Konfigurasi opsional untuk menyesuaikan kriteria atau alur kerja validasi infra. infra_validator=InfraValidator( model=trainer.outputs['model'], serving_spec=tfx.proto.ServingSpec(...), validation_spec=tfx.proto.ValidationSpec( # How much time to wait for model to load before automatically making # validation fail. max_loading_time_seconds=60, # How many times to retry if infra validation fails. num_tries=3 ) ) Semua bidang ValidationSpec memiliki nilai default suara. Periksa lebih rinci dari definisi protobuf . RequestSpec Konfigurasi opsional untuk menentukan bagaimana membangun permintaan sampel saat menjalankan infra validasi di LOAD_AND_QUERY modus. Untuk menggunakan LOAD_AND_QUERY modus, diperlukan untuk menentukan baik request_spec sifat eksekusi serta examples saluran masukan dalam definisi komponen. infra_validator = InfraValidator( model=trainer.outputs['model'], # This is the source for the data that will be used to build a request. examples=example_gen.outputs['examples'], serving_spec=tfx.proto.ServingSpec( # Depending on what kind of model server you're using, RequestSpec # should specify the compatible one. tensorflow_serving=tfx.proto.TensorFlowServing(tags=['latest']), local_docker=tfx.proto.LocalDockerConfig(), ), request_spec=tfx.proto.RequestSpec( # InfraValidator will look at how "classification" signature is defined # in the model, and automatically convert some samples from `examples` # artifact to prediction RPC requests. tensorflow_serving=tfx.proto.TensorFlowServingRequestSpec( signature_names=['classification'] ), num_examples=10 # How many requests to make. ) ) Memproduksi Model Tersimpan dengan pemanasan (Dari versi 0.30.0) Karena model InfraValidator memvalidasi dengan permintaan nyata, dapat dengan mudah menggunakan kembali permintaan validasi ini sebagai permintaan pemanasan dari SavedModel. InfraValidator memberikan pilihan ( RequestSpec.make_warmup ) untuk mengekspor SavedModel dengan pemanasan. infra_validator = InfraValidator( ..., request_spec=tfx.proto.RequestSpec(..., make_warmup=True) ) Maka output InfraBlessing artefak akan berisi SavedModel dengan pemanasan, dan juga dapat didorong oleh Pusher , seperti Model artefak. Keterbatasan InfraValidator saat ini belum lengkap, dan memiliki beberapa keterbatasan. • Hanya TensorFlow SavedModel Format model dapat divalidasi. • Saat menjalankan TFX pada Kubernetes, pipa harus dieksekusi oleh KubeflowDagRunner dalam Kubeflow Pipa. Server model akan diluncurkan di cluster Kubernetes yang sama dan namespace yang digunakan Kubeflow. • InfraValidator terutama difokuskan pada penyebaran ke TensorFlow Melayani , dan sementara masih berguna itu kurang akurat untuk penyebaran ke TensorFlow Lite dan TensorFlow.js , atau kerangka kerja inferensi lainnya. • Ada dukungan terbatas pada LOAD_AND_QUERY modus untuk Memprediksi metode tanda tangan (yang merupakan satu-satunya metode ekspor di TensorFlow 2). InfraValidator membutuhkan Memprediksi tanda tangan untuk mengkonsumsi serial tf.Example sebagai satu-satunya masukan. @tf.function def parse_and_run(serialized_example): features = tf.io.parse_example(serialized_example, FEATURES) return model(features) model.save('path/to/save', signatures={ # This exports "Predict" method signature under name "serving_default". 'serving_default': parse_and_run.get_concrete_function( tf.TensorSpec(shape=[None], dtype=tf.string, name='examples')) }) • Memeriksa sebuah contoh Penguin kode contoh untuk melihat bagaimana tanda tangan ini berinteraksi dengan komponen lain dalam TFX.
__label__pos
0.997609
Sscglpinnacle Dhaka Profit and Loss: SSC CGL Math Project 400 Questions Validity: 9 Months What you will get Course Highlights • Based on latest Pattern • English Medium eBooks Already Bookmark SSC Profit and Loss: SSC CGL Math Project 400 Questions Profit and Loss: SSC CGL Math Project 400 Questions. What is project 400? Click here Profit and Loss Q1. A man wanted to sell an article with 20% profit; but he actually sold at 20% loss for Rs 480. At what price (Rs) he wanted to sellit to earn the profit? a) 720 b) 840 c) 600 d) 750 Q2. The cost price of 36 books is is equal to the selling price of 30 books. The gain per cent is: a) 20% b) 50/3 % c) 18% d) 24% Q3. A person sells two machines at Rs 396 each. One one he gains 10% and on the other he loses 10%. His profit or loss in the whole transaction is: a) No gain no loss b) 1% loss c) 1% profit d) 8% profit Q4. A house and a shop were sold for Rs 1 lakh each. In this transaction, the house sale resulted into 20% loss whereas the shop sale into 20% profit. The entire transaction resulted in a) No loss no gain b) gain of Rs 1/24 lakh c) Loss of Rs 1/12 lakh d) Loss of Rs 1/18 lakh Q5. A sells a bicycle to B at a profit of 20%. B sells it to C at a profit of 25%. If C pays Rs 225 /- for it, the cost price of the bicycle for A is: a) Rs 110/- b) Rs 125 /- c) Rs 120 /- d) Rs 150/- Profit and Loss Maths Questions Q6. 12 copies of a book were sold for Rs 1800/- thereby gaining cost-price of 3 copies. The cost price of a copy is: a) Rs 120 b) 150 c) RS 1200 d) Rs 1500 Q7. If a man estimates his loss as 20% of the selling price, then his loss per cent is: a) 20% b) 25% c) 40/3% d) 50/3% Q8. If I would have purchased 11 articles for Rs 1o and sold all the articles at the rate of 10 for Rs 11, the profit per cent would have been: a) 10% b) 11% c) 21% d) 100% Q9. An article is sold at a loss of 10%. Had it been sold for Rs 9 more, there would have been a gain of 25/2% on it. The cost price of the article is: a) Rs40 b) RS 45 c) Rs 50 d) RS 35 Q10. A man buys a cycle for Rs 1400 and sells it at a loss of 15%. What is the selling price of the cycle? a) Rs 1202 b) Rs 1190 c) Rs 1160 d) RS 1000 Q11. The ratio of cost price and selling price is 5: 4, the loss percent is: a) 20% b0 25% c) 405 d) 50% Q12. A person buys some pencils at 5 for a rupee and sells them at 3 for a rupee. His gain percent will be: a) 200/3 b) 230/3 c) 170/3 d) 140/3 Q13. If selling price of an article is 8/5 times its cost price, the profit per cent on it is a) 120% b) 160% c) 40% d) 60% Q14. The price of coal is increased by 20%. By what per cent a family should decrease its consumption so that expenditure remains same? a) 40% b) 70/3% c) 20% d) 50/3% Q15. 100 oranges are bought for Rs 350 and sold at the rate of Rs 48 per dozen. The percentage of profit or loss is: a) 15% loss b) 15% gain c) 100/7% loss d) 100/7% profit Q16. A reduction of 20% in the price of salt enables a purchaser to obtain 4 kg more for Rs 100. The reduced price of salt per kg is: a) Rs 4 b) Rs 5 c) Rs 6.25 d) Rs 6.50 Profit and Loss Questions Q17. A person sells a table at a profit of 10%. If he had bought the table at 5% less cost and sold for rs 80 more, he would have gained 20%. The cost price of the table is a) Rs 3200 b) Rs 2500 c) Rs 2000 d) Rs 200 Q18. A person sells an article for Rs 75 and gains as much per cent as the cost price of the article in ruppes. The cost price of the article is: a) Rs 37.50 b) Rs 40 c) Rs 50 d) RS 150 Q19. A man had 100 kgs of sugar part of which he sold at 7% profit and rest at 17% profit. He gained 10% on the whole. How much did he sell at 7% profit? a) 65 kg b) 35 kg c) 30 kg d) 70 kg Q20. A person bought some articles at the rate of 5 per rupee and the same number at the rate of 4 per rupee. He mixed both the types and sold at the rate of 9 for 2 rupees. In this business he suffered a loss of rs 3. The total number of articles bought by him was: a) 1090 b) 1080 c) 540 d) 545 Q21. If a shopkeep gains 20% while buying the goods and 30% while selling them. Find his total gain percent. a) 505 b) 36% c) 56% d) 40% Q22. The percentage of loss when an article is sold at rs 50 is the as that of the profit when it is sold at Rs 70. The above mentioned pertange of profit or loss on the article is a) 10% b) 50/3% c) 20% d) 68/3 Profit and Loss : Answer Key 1 a 2 a 3 b 4 c 5 d 6 a 7 d 8 c 9 a 10 b 11 a 12 a 13 d 14 d 15 d 16 b 17 c 18 c 19 d 20 b 21 c 22 b If you have any problem, write in the comment section. We will revert. Percentage: SSC CGL Math Project 400 Questions Number System: SSC CGL Math Project 400 Questions Time and Distance : SSC CGL Math Project 400 Questions  
__label__pos
0.897044
Bài 2 trang 6 SGK Toán 5 Bình chọn: 4 trên 46 phiếu Giải bài 2 trang 6 SGK Toán 5. Quy đồng mẫu các phân số: Đề bài Quy đồng mẫu các phân số: a) \(\frac{2}{3}\) và \(\frac{5}{8}\);               b) \(\frac{1}{4}\) và \(\frac{7}{12}\);        c) \(\frac{5}{6}\) và \(\frac{3}{8}\). Lời giải chi tiết a) MSC: 24 \(\frac{2}{3}\) = \(\frac{2 \times 8}{3\times 8}\) = \(\frac{16}{24}\);            \(\frac{5}{8}\) = \(\frac{5\times 3}{8\times 3}\) = \(\frac{15}{24}\). b)  MSC: 12 \(\frac{1}{4}\) = \(\frac{1\times 3}{4\times 3}\) = \(\frac{3}{12}\) ;       Giữ nguyên \(\frac{7}{12}\). c) MSC 48: \(\frac{5}{6}\) = \(\frac{5 \times 8}{6\times 8}\) = \(\frac{40}{48}\);          \(\frac{3}{8}\) = \(\frac{3\times 6}{8\times 6}\) = \(\frac{18}{48}\). loigiaihay.com Luyện Bài tập trắc nghiệm môn Toán lớp 5 - Xem ngay Các bài liên quan: - Ôn tập: Tính chất cơ bản của phân số >>Học trực tuyến các môn Toán, Tiếng Việt, Tiếng Anh lớp 5, mọi lúc, mọi nơi. Các thầy cô giỏi nổi tiếng, dạy hay dễ hiểu
__label__pos
0.99971
Dismiss Notice Join Physics Forums Today! The friendliest, high quality science and math community on the planet! Everyone who loves science is here! Gaussian process with linear correlation 1. Jan 28, 2012 #1 Hi I have a stationary gaussian process { X_t } and I have the correlation function p(t) = Corr(X_s, X_(s+t)) = 1 - t/m, where X_t is in {1,2,..,m}, and I want to simulate this process. The main idea is to write X_t as sum from 1 to N of V_i, X_t+1 as sum from p+1 to N+p V_i and so on, where V_i are uniform variables in [-a, a]. From this point I will use the central limit theorem to prove that X_t is a normal variable. My question is: how can I find the correlation, covariance of X_T and X_t+k for example, a and p using this notification?   2. jcsd 3. Jan 29, 2012 #2 Stephen Tashi User Avatar Science Advisor I don't know why you chose sums of independent uniform random variables. Why not use sums of independent normal random variables? Then you know the sums are normally distributed instead of approximately normally distributed. A specific example of your question is: Let [itex] u_1,u_2,u_3, u_4 [/itex] each be independent uniformly distributed random variables on [0,1]. Let [itex] S_1 = u_1 + u_2 + u_3 [/itex] Let [itex] S_2 = u_2 + u_3 + u_4 [/itex] Find [itex] COV(S_1,S_2) [/itex]. Find the correlation of [itex] S_1 [/itex] with [itex] S_2 [/itex]. Well, the covariance of two sums of random variables should be easy enough. See http://mathworld.wolfram.com/Covariance.html equation 21. To force the autocorrelation to have a particular shape, you could use weighted sums . That would be another argument for using normal random variables for [itex] V_i [/itex].   4. Jan 29, 2012 #3 Thank you for the answer. Can you explain in detail how can I use the weighted sums to force the autocorrelation and how can I find all the parameters I need?   5. Jan 29, 2012 #4 Stephen Tashi User Avatar Science Advisor Whether I can explain it depends on you background in mathematics, including probability theory - and whether I have time! It isn't a good idea to write computer simulations for any serious purpose without having the mathematical background to understand how they work. If your are doing this for recreation, a board game etc. then perhaps it's Ok. To start with, I suggest that you consider the weights represented by constants [itex] k_1, k_2, k_3 [/itex]. Let [itex] S_j = k_1 x_j + k_2 x_{j+1} + k_3 x_{j+2} [/itex] Compute [itex] Cov(S_j, S_{j+1}), Cov(S_j,S_{j+2}) [/itex] etc. and see how the constants determine those covariances.   6. Jan 29, 2012 #5 Yes, I understand what I have to calculate. Actually , what I don't understand is a result from a book I read. The idea is [itex]X_t[/itex] is a stationary gaussian process. I have m states. [itex]p(t) = 1 - t/m[/itex] the autocorrelation function. So, [itex] p(t) = Cov(X_s, X_{s+t}) / Var(X_t) [/itex]. Now, to simulate it, are generated some uniform random values [itex]V_i[/itex] in [itex] [-a,a][/itex]. Now [itex]X_t = V_1 + V_2 + .. +V_N, X_{t+1} = V_{p+1} + V_{p+2} + .. + V_{N+p}[/itex] and so on.N is enough large to use the central limit theorem. My real problem is that there is stated that [itex]Cov[X_t , X_{t+k}] = E[(X_t - X_{t+k})^2] = 2No -Cov(X_t,X_{t+k}) [/itex], where o is the variance for [itex]V_t[/itex]. Next is stated that for [itex]k < N/p, Cov[X_t , X_{t+k}] = E[(X_t - X_{t+k})^2] = 2kp^2[/itex]. My problem is that I can't reach to this results, I can't prove them. If you can give me some ideas or links to read about this idea to aproximate, it would be great. Thanks again.   7. Jan 29, 2012 #6 Stephen Tashi User Avatar Science Advisor [tex] E[(X_t - X_{t+k})^2] = E( X_t^2 - 2 X_t X_{t+k} + X_{t+k}^2) = E(X_t^2) - 2 E(X_t X_{t_k}) + E(X_{t+k}^2) = N_o - 2 E(X_t X_{t+k}) + N_o [/tex] That could be a mess to write out, but the way I would start it is: [tex] COV( X_t, X_{t+k}) = COV( (\sum_A V_i + \sum_B V_i) (\sum_B V_i + \sum_C V_i) ) [/tex] Where [itex] A [/itex] are the [itex] Vi [/itex] unique to [itex] X_t [/itex], [itex] B [/itex] are the [itex] V_i [/itex] common to both [itex] X_t [/itex] and [itex] X_{t+k} [/itex] and [itex] C [/itex] are the [itex] V_i [/itex] unique to [itex] X_{t+k} [/itex]. As I recall, the covariance function obeys a distributive law that would give: [tex] = COV( \sum_A V_i ,\sum_B V_i) + COV(\sum_A V_i ,\sum_C V_i) + COV(\sum_B V_i ,\sum_B V_i) + COV(\sum_B V_i ,\sum_C V_i) [/tex] [tex] = 0 + 0 + COV(\sum_B V_i, \sum_B V_i) + 0 [/tex] So you must comput the variance of [itex] \sum_B V_i [/itex], which will be a function of the variance of one particular [itex] V_i [/itex] and the number of the [itex] V_i [/itex] in the set [itex] B [/itex].   8. Jan 29, 2012 #7 I have one more question. Maybe is obvious, but I don't see it. Why is the relation [itex]Cov(X_t,X_{t+k}) = E[(X_t - X_{t+k})^2][/itex] true?   9. Jan 29, 2012 #8 Stephen Tashi User Avatar Science Advisor I don't have time to think about that now. Is [itex] X_t [/itex] assumed to have mean = 0 as part of the terminology "gaussian"? Also, I notice that I got [itex] 2 N_0 - 2 E(X_t,X_{t+k}) [/itex] instead of what you wrote. I'll be back this evening.   10. Jan 29, 2012 #9 Yes, the mean is 0. Also, from what I calculated, there it should be [itex]kpo[\itex] instead of [itex]kp^2[\itex].   11. Jan 29, 2012 #10 Stephen Tashi User Avatar Science Advisor The notation is getting confusing. We have p() for the correlation function and p in the index that defines [itex] X_t [/itex] as a sum of the [itex] V_i [/itex]. What is "po"? Anyway, let's say that the cardinality of the set [itex] B [/itex] is b. [tex] COV( \sum_B V_i, \sum_B V_i) = VAR( \sum_B V_i) [/tex] [tex] =\sum_B ( VAR(V_i)) = b (VAR(V_i)) [/tex] versus: [tex] E( (X_t - X_{t+k})^2) = E ( ( \sum_A V_i - \sum_C V_i)^2) [/tex] [tex] = E( (\sum_A V_i)^2 + (\sum_C V_i)^2 - 2 \sum_A V_i \sum_C V_i ) [/tex] [tex] = E( (\sum_A V_i)^2 + E (\sum_C V_i)^2 - 2 E( \sum_A V_i)E(\sum_C V_i) [/tex] I gather we are assuming [itex] E(V_i) = 0 [/itex] so [itex] E( \sum_A V_i)^2 = VAR( \sum_A V_i) [/itex] etc. So the above is [tex] = VAR( \sum_A V_i) + VAR(\sum_C V_i) - 2 (0)(0) [/tex] Let a = the cardinality of [itex] A [/itex] and c = the cardinality of [itex] C [/itex] [tex] = (a + c) VAR(V_i) [/tex] It there an argument that (a+c) = b ?   12. Jan 30, 2012 #11 Thank you for the help, I figured it out finally. I have one more question. Now I have the algorithm for simulating the process and I want to validate it. Can you give some hints how it must be done?   13. Jan 30, 2012 #12 Stephen Tashi User Avatar Science Advisor Do you mean you want to validate it as a computer program by running it and looking at the data? Or do you mean you want to validate whether the algorithm implements the procedure in the book by reading the code of the algorithm?   14. Jan 30, 2012 #13 I meant if I see the values the computer program generated, what tests could I use to see if it is working correctly? I am thinking to check if the average of the values estimates the mean, the values respect the autocorrelation function rules and I was wondering if there are more things I could test.   15. Jan 30, 2012 #14 Stephen Tashi User Avatar Science Advisor I'd have to think about this in detail to give good advice. On the spur of the moment, I'd say to also check whether the X_i are normally distributed. In the history of simulations, there are examples where the random number generating functions were flawed in certain software packages. Don't assume that the random number generator in your software really works. Test it or at least find some documentation that someone else did. A quick test is to do a 2D plot of (X,Y,color) where each component is selected by a uniform distribution on some scale. See if any pronounced visual patterns appear. (Some random number generators misbehave only on particular seeds.)   Share this great discussion with others via Reddit, Google+, Twitter, or Facebook Loading...
__label__pos
0.979495
init.c 1.21 KB Newer Older 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 /* * Example initialization file - spawns 2 native FPU tasks * */ #define CONFIGURE_INIT #define TASKS 2 #include "system.h" #include <stdio.h> rtems_task Init(rtems_task_argument argument) { rtems_status_code status; rtems_name Task_name[TASKS]; /* task names */ rtems_id Task_id[TASKS]; /* task ids */ int i; for(i = 0; i < TASKS; i++) { // Initialize Task name Task_name[i] = rtems_build_name('T', 'T', "0" + i / 10, "0" + i % 10); // Create Task status = rtems_task_create( Task_name[i], (rtems_task_priority) 2, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_FLOATING_POINT, // use RTEMS_DEFAULT_ATTRIBUTES for non-native FPU tasks &Task_id[i]); if (status != RTEMS_SUCCESSFUL) { printf("Failed to rtems_task_create... status:%0x\n", status); rtems_task_delete(RTEMS_SELF); } // Start Task status = rtems_task_start( Task_id[i], Task_EntryPoint, i); } printf("Parent task sleeps for a second...\n"); rtems_task_wake_after(100); printf("Parent task bids adieu...\n"); rtems_task_delete(RTEMS_SELF); }
__label__pos
0.941194
Paul Khuong mostly on Lisp Bitsets Match Regular Expressions, Compactly This post describes how graph and automata theory can help compile a regular expression like “ab(cd|e)*fg” into the following asymptotically (linear-time) and practically (around 8 cycles/character on my E5-4617) efficient machine code. The technique is easily amenable to SSE or AVX-level vectorisation, and doesn’t rely on complicated bit slicing tricks nor on scanning multiple streams in parallel. matcher inner loop 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ; 8F70: L1: 4839D9 CMP RCX, RBX ; look for end of string ; 8F73: 7D6C JNL L5 ; 8F75: 488BC1 MOV RAX, RCX ; 8F78: 48D1F8 SAR RAX, 1 ; 8F7B: 410FB6440001 MOVZX EAX, BYTE PTR [R8+RAX+1] ; read character ; 8F81: 48D1E2 SHL RDX, 1 ; 8F84: 488B35F5FEFFFF MOV RSI, [RIP-267] ; #(0 0 0 0 ; ...) ; 8F8B: 0FB6440601 MOVZX EAX, BYTE PTR [RSI+RAX+1] ; load mask from LUT ; 8F90: 48D1E0 SHL RAX, 1 ; only data-dependent part of ; 8F93: 4821C2 AND RDX, RAX ; transition ; 8F96: F6C258 TEST DL, 88 ; if any of states 2,3,5 are active ; 8F99: BE00000000 MOV ESI, 0 ; [fixnums are tagged with a low 0 bit] ; 8F9E: 41BB58000000 MOV R11D, 88 ; all of them are ; 8FA4: 490F45F3 CMOVNE RSI, R11 ; 8FA8: 4809F2 OR RDX, RSI ; now active ; 8FAB: 4885D2 TEST RDX, RDX ; if no state is active ; 8FAE: 751C JNE L3 ; 8FB0: 488BD1 MOV RDX, RCX ; return... :'( ; 8FB3: BF17001020 MOV EDI, 537919511 ; we're working on ; 8FB8: L2: 488D5D10 LEA RBX, [RBP+16] ; moving such code block ; 8FBC: B904000000 MOV ECX, 4 ; out of inner loops. ; 8FC1: BE17001020 MOV ESI, 537919511 ; 8FC6: F9 STC ; 8FC7: 488BE5 MOV RSP, RBP ; 8FCA: 5D POP RBP ; 8FCB: C3 RET ; 8FCC: L3: 4883C102 ADD RCX, 2 ; 8FD0: L4: 480FBAE208 BT RDX, 8 ; if we're not at the accept state ; 8FD5: 7399 JNB L1 ; loop back Bitap algorithms The canonical bitap algorithm matches literal strings, e.g. “abad”. Like other bitap algorithms, it exploits the fact that, given a bitset representation of states, it’s easy to implement transfer functions of the form “if state \( i \) was previously active and we just consumed character \( c \), state \( i+1 \) is now active”. It suffices to shift the bitset representation of the set of active states by 1, and to mask out transitions that are forbidden by the character that was just consumed. For example, when matching the literal string “abad”, a state is associated with each position in the pattern. 0 is the initial state, 1 is the state when we’ve matched the first ‘a’, 2 after we’ve also matched ‘b’, 3 after the second ‘a’, and 4 after ‘d’, the final character, has been matched. Transposing this information gives us the information we really need: ‘a’ allows a transition from 0 to 1 and from 2 to 3, ‘b’ a transition from 1 to 2, and ‘d’ from 3 to 4. A trivial state machine is probably clearer. The initial state is in grey, the accept state is a double circle, and transitions are labelled with the character they accept. Finding the substring “abad” in a long string thus reduces to a bunch of bitwise operations. At each step, we OR bit 0 in the set of states: we’re always looking for the beginning of a new match. Then, we consume a character. If it’s ‘a’, the mask is 0b01010; if it’s ‘b’, mask is 0b00100; if it’s ‘d’, mask is 0b10000; otherwise, its mask is 0. Then, we shift the set of state left by 1 bit, and AND with mask. The effect is that bit 1 is set iff mask has bit 1 set (and that only happens if the character is ‘a’), and bit 0 was previously set (… which is always the case), bit 2 is set iff mask has bit 2 set (i.e. we consumed a ‘b’) and bit 1 was previously set, etc. We declare victory whenever state 4 is reached, after a simple bit test. It’s pretty clear that this idea can be extended to wildcards or even character classes: multiple characters can have the same bit set to 1 in their mask. Large alphabets are also straightforward to handle: the mapping from character to mask can be any associative dictionary, e.g. a perfect hash table (wildcards and inverted character classes then work by modifying the default mask value). This works not only with strings, but with any sequence of objects, as long as we can easily map objects to attributes, and attributes to masks. Some thinking shows it’s even possible to handle the repetition operator ”+”: it’s simply a conditional transition from state \( i \) to state \( i \). What I find amazing is that the technique extends naturally to arbitrary regular expressions (or nondeterministic finite automata). Shift and mask for regular expressions Simulating an NFA by advancing a set of states in lockstep is an old technique. Russ Cox has written a nice review of classic techniques to parse or recognize regular languages. The NFA simulation was first described by Thomson in 1977, but it’s regularly being rediscovered as taking the Brzozowski derivative of regular expressions ;) Fast Text Searching With Errors by Sun Wu and Udi Manber is a treasure trove of clever ideas to compile pattern matching, a symbolic task, into simple bitwise operations. For regular expressions, the key insight is that the set of states can be represented with a bitset such that the transition table for the NFA’s states can be factored into a simple data-dependent part followed by \( \epsilon \)-transitions that are the same, regardless of the character consumed. Even better: the NFA’s state can be numbered so that each character transition is from state \( i \) to \( i+1 \), and such a numbering falls naturally from the obvious way to translate regular expression ASTs into NFAs. For the initial example “ab(cd|e)*fg”, the AST looks like a node to match ‘a’, succeeded by a node to match ‘b’, then a repetition node into either “cd”, “e” or \( \epsilon \), and the repetition node is succeeded by “fg” (and, finally, accept). Again, a drawing is much clearer! Circles correspond to character-matching states, the square to a repetition node, the diamond to a choice node, and the pointy boxes to dummy states. The final accept state is, again, a double circle. \( \epsilon \)-transitions are marked in blue, and regular transitions are labelled with the character they consume. The nodes are numbered according to a straight depth-first ordering in which children are traversed before the successor. As promised, character transitions are all from \( i \) to \( i+1 \), e.g. 0 to 1, 1 to 2, 6 to 7, … This is a simple consequence of the fact that character-matching nodes have no children and a single successor. This numbering is criminally wasteful. States 3, 6 and 10 serves no purpose, except forwarding \( \epsilon \) transitions to other states. The size of the state machine matters because bitwise operations become less efficient when values larger than a machine word must be manipulated. Using fewer states means that larger regular expressions will be executed more quickly. Eliminating them and sliding the numbers back yields the something equivalent to the more reasonable 11-state machine shown in Wu and Manber (Figure 3 on page 10). Simply not assigning numbers to states that don’t match characters and don’t follow character states suffices to obtain such decent numberings. Some more thinking shows we can do better, and shave three more states. State 2 could directly match against character ‘e’, instead of only forwarding into state 3; what is currently state 4 could match against character ‘c’, instead of only forwarding into state 8, then 2 and then 5 (which itself matches against ‘c’); and similarly for state 7 into state 8. The result wastes not a single state: each state is used to match against a character, except for the accept state. Interestingly, the \( \epsilon \) transitions are also more regular: they form a complete graph between states 2, 3 and 5. It’s possible to use fewer states than the naïve translation, and it’s useful to do so. How can a program find compact numberings? Compact bitap automata The natural impulse for functional programmers (particularly functional compiler writers ;) is probably to start matching patterns to iteratively reduce the graph. If they’ve had bad experience with slow fixpoint computations, there might also be some attempts at recognising patterns before even emitting them. This certainly describes my first couple stabs; they were either mediocre or wrong (sometimes both), and certainly not easy to reason about. It took me a while to heed age-old advice about crossing the street and compacting state machines. Really, what we’re trying to do when compacting the state machine is to determine equivalence classes of states: sets of states that can be tracked as an atomic unit. With rewrite rules, we start by assuming that all the states are distinct, and gradually merge them. In other words, we’re computing a fixed point starting from the initial hypothesis that nothing is equivalent. Problem is, we should be doing the opposite! If we assume that all the states can be tracked as a single unit, and break equivalence classes up in as we’re proven wrong, we’ll get maximal equivalence classes (and thus as few classes as possible). To achieve this, I start with the naïvely numbered state machine. I’ll refer to the start state and character states as “interesting sources”, and to the accept state and character states as “interesting destinations”. Ideally, we’d be able to eliminate everything but interesting destinations: the start state can be preprocessed away by instead working with all the interesting destinations transitively reachable from the start state via \( \epsilon \) transitions (including itself if applicable). The idea is that two states are equivalent iff they are always active after the same set of interesting sources. For example, after the start state 0, only state 1 is active (assuming that the character matches). After state 1, however, all of 2, 3, 4, 6, 7, 10 and 11 are active. We have the same set after states 4 and 8. Finally, only one state is alive after each of 11 and 12. Intersecting the equivalence relations thus defined give a few trivial equivalence classes (0, 1, 5, 8, 9, 12, 13), and one huge equivalence class comprised of {2,3,4,6,7,10,11} made of all the states that are active exactly after 1, 5 and 9. For simplicity’s sake, I’ll refer to that equivalence class as K. After contraction, we find this smaller state graph. We can renumber this reasonably to obey the restriction on character edges: K is split into three nodes (one for each outgoing character-consuming edge) numbered 2, 4 and 7. We could do even better if 5 and 9 (3 and 6 above) in the earlier contracted graph were also in equivalence class K: they only exist to forward back into K! I suggest to achieve that with a simple post-processing pass. Equivalence classes are found by find determining after which interesting node each state is live. States that are live after exactly the same sets of interesting nodes define an equivalence class. I’ll denote this map from state to transitive interesting predecessors \( pred(state) \). We can coarsen the relationship a bit, to obtain \( pred\sp{\prime}(state) \). For interesting destinations, \( pred\sp{\prime} = pred \). For other nodes, \(pred\sp{\prime}(state) = \cap\sb{s\in reachable(state)}pred(s)\), where \(reachable(state)\) is the set of interesting destinations reachable via \( \epsilon \) transitions from \(state\). This widening makes sense because \(state\) isn’t interesting (we never want to know whether it is active, only whether its reachable set is), so it doesn’t matter if \(state\) is active when it shouldn’t, as long as its destinations would all be active anyway. This is how we get the final set of equivalence classes. We’re left with a directed multigraph, and we’d like to label nodes such that each outgoing edge goes from its own label \( i \) to \( i+1 \). We wish to do so while using the fewest number of labels. I’m pretty sure we can reduce something NP-Hard like the minimum path cover problem to this problem, but we can still attempt a simple heuristic. If there were an Eulerian directed path in the multigraph, that path would give a minimal set of labels: simply label the origin of each arc with its rank in the path. An easy way to generate an Eulerian circuit, if there is one, is to simply keep following any unvisited outgoing arc. If we’re stuck in a dead end, restart from any vertex that has been visited and still has unvisited outgoing arcs. There’s a fair amount of underspecification there. Whenever many equivalence classes could be chosen, I choose the one that corresponds to the lexicographically minimal (sorted) set of regexp states (with respect to their depth-first numbering). This has the effect of mostly following the depth-first traversal, which isn’t that bad. There’s also no guarantee that there exists an Eulerian path. If we’re completely stuck, I start another Eulerian path, again starting from the lexicographically minimal equivalence class with an unvisited outgoing edge. Finally, once the equivalence states are labelled, both character and \( \epsilon \) transitions are re-expressed in terms of these labels. The result is a nice 8-state machine. But that’s just theory This only covers the abstract stuff. There’s a CL code dump on github. You’re probably looking for compile-regexp3.lisp and scalar-bitap.lisp; the rest are failed experiments. Once a small labeling is found, generating a matcher is really straightforward. The data-dependent masks are just a dictionary lookup (probably in a vector or in a perfect hash table), a shift and a mask. Traditionally, epsilon transitions have been implemented with a few table lookups. For example, the input state can be cut up in bytes; each byte maps to a word in a different lookup table, and all the bytes are ORed together. The tables can be pretty huge (n-states/8 lookup tables of 256 state values each), and the process can be slow for large states (bitsets). This makes it even more important to reduce the size of the state machine. When runtime compilation is easy, it seems to make sense to instead generate a small number of test and conditional moves… even more so if SIMD is used to handle larger state sets. A couple branch-free instructions to avoid some uncorrelated accesses to LUTs looks like a reasonable tradeoff, and, if SIMD is involved, the lookups would probably cause some slow cross-pipeline ping-ponging. There’s another interesting low-level trick. It’s possible to handle large state sets without multi-word shifts: simply insert padding states (linked via \( \epsilon \) transitions) to avoid character transitions that straddle word boundaries. There’s a lot more depth to this bitap for regexp matching thing. For example, bitap regular expressions can be adapted to fuzzy matchings (up to a maximum edit distance), by counting the edit distance in unary and working with one bitset for each edit distance value. More important in practice, the approach described so far only handles recognising a regular language; parsing into capture groups and selecting the correct match is a complex issue about which Russ Cox has a lot to say. What I find interesting is that running the NFA backward from accept states gives us a forward oracle: we can then tell whether a certain state at a given location in the string will eventually reach an accept state. Guiding an otherwise deterministic parsing process with such a regular language oracle clearly suffices to implement capture groups (all non-deterministic choices become deterministic), but it also looks like it would be possible to parse useful non-regular languages without backtracking or overly onerous memoisation. Comments
__label__pos
0.548096
phoenix_title wx.svg The classes in this package facilitate the parsing, normalizing, drawing and rasterizing of Scalable Vector Graphics (SVG) images. The primary interface to this functionality is via the wx.svg.SVGimage class, which provides various integrations with wxPython. It, in turn, uses a set of wrappers around the NanoSVG library (https://github.com/memononen/nanosvg) to do the low-level work. There are a few features defined in the SVG spec that are not supported, but all the commonly used ones seem to be there. Example 1 Drawing an SVG image to a window, scaled to fit the size of the window and using a wx.GraphicsContext can be done like this: def __init__(self, ...): ... self.img = wx.svg.SVGimage.CreateFromFile(svg_filename) self.Bind(wx.EVT_PAINT, self.OnPaint) def OnPaint(self, event): dc = wx.PaintDC(self) dc.SetBackground(wx.Brush('white')) dc.Clear() dcdim = min(self.Size.width, self.Size.height) imgdim = min(self.img.width, self.img.height) scale = dcdim / imgdim width = int(self.img.width * scale) height = int(self.img.height * scale) ctx = wx.GraphicsContext.Create(dc) self.img.RenderToGC(ctx, scale) Since it is drawing the SVG shapes and paths using the equivalent GC primitives then any existing transformations that may be active on the context will be applied automatically to the SVG shapes. Note that not all GraphicsContext backends are created equal. Specifically, the GDI+ backend (the default on Windows) simply can not support some features that are commonly used in SVG images, such as applying transforms to gradients. The Direct2D backend on Windows does much better, and the Cairo backend on Windows is also very good. The default backends on OSX and Linux do very good as well. Example 2 If you’re not already using a wx.GraphicsContext then a wx.Bitmap can easily be created instead. For example, the last 2 lines in the code above could be replaced by the following, and accomplish basically the same thing: bmp = self.img.ConvertToBitmap(scale=scale, width=width, height=height) dc.DrawBitmap(bmp, 0, 0) Example 3 The ConvertToBitmap shown above gives a lot of control around scaling, translating and sizing the SVG image into a bitmap, but most of the time you probably just want to get a bitmap of a certain size to use as an icon or similar. The ConvertToScaledBitmap provides an easier API to do just that for you. It automatically scales the SVG image into the requested size in pixels.: bmp = img.ConvertToScaledBitmap(wx.Size(24,24)) Optionally, it can accept a window parameter that will automatically adjust the size according to the Content Scale Factor of that window, if supported by the platform and if the window is located on a HiDPI display the the bitmap’s size will be adjusted accordingly.: bmp = img.ConvertToScaledBitmap(wx.Size(24,24), self) module_summary Modules Summary _nanosvg NanoSVG is a “simple stupid single-header-file SVG parser” from _version class_summary Classes Summary SVGimage The SVGimage class provides various ways to load and use SVG images
__label__pos
0.826816
Using R Within the IPython Notebok Using the rmagic extension, users can run R code from within the IPython Notebook. This example Notebook demonstrates this capability. In [1]: %matplotlib inline Line magics IPython has an rmagic extension that contains a some magic functions for working with R via rpy2. This extension can be loaded using the %load_ext magic as follows: In [2]: %load_ext rmagic A typical use case one imagines is having some numpy arrays, wanting to compute some statistics of interest on these arrays and return the result back to python. Let's suppose we just want to fit a simple linear model to a scatterplot. In [3]: import numpy as np import matplotlib.pyplot as plt X = np.array([0,1,2,3,4]) Y = np.array([3,5,4,6,7]) plt.scatter(X, Y) Out[3]: <matplotlib.collections.PathCollection at 0x107efe2d0> We can accomplish this by first pushing variables to R, fitting a model and returning the results. The line magic %Rpush copies its arguments to variables of the same name in rpy2. The %R line magic evaluates the string in rpy2 and returns the results. In this case, the coefficients of a linear model. In [3]: %Rpush X Y %R lm(Y~X)$coef Out[3]: array([ 3.2, 0.9]) We can check that this is correct fairly easily: In [4]: Xr = X - X.mean(); Yr = Y - Y.mean() slope = (Xr*Yr).sum() / (Xr**2).sum() intercept = Y.mean() - X.mean() * slope (intercept, slope) Out[4]: (3.2000000000000002, 0.90000000000000002) It is also possible to return more than one value with %R. In [5]: %R resid(lm(Y~X)); coef(lm(X~Y)) Out[5]: array([-2.5, 0.9]) One can also easily capture the results of %R into python objects. Like R, the return value of this multiline expression (multiline in the sense that it is separated by ';') is the final value, which is the coef(lm(X~Y)). To pull other variables from R, there is one more magic. There are two more line magics, %Rpull and %Rget. Both are useful after some R code has been executed and there are variables in the rpy2 namespace that one would like to retrieve. The main difference is that one returns the value (%Rget), while the other pulls it to self.shell.user_ns (%Rpull). Imagine we've stored the results of some calculation in the variable "a" in rpy2's namespace. By using the %R magic, we can obtain these results and store them in b. We can also pull them directly to user_ns with %Rpull. They are both views on the same data. In [6]: b = %R a=resid(lm(Y~X)) %Rpull a print(a) assert id(b.data) == id(a.data) %R -o a [-0.2 0.9 -1. 0.1 0.2] %Rpull is equivalent to calling %R with just -o In [7]: %R d=resid(lm(Y~X)); e=coef(lm(Y~X)) %R -o d -o e %Rpull e print(d) print(e) import numpy as np np.testing.assert_almost_equal(d, a) [-0.2 0.9 -1. 0.1 0.2] [ 3.2 0.9] On the other hand %Rpush is equivalent to calling %R with just -i and no trailing code. In [8]: A = np.arange(20) %R -i A %R mean(A) Out[8]: array([ 9.5]) The magic %Rget retrieves one variable from R. In [9]: %Rget A Out[9]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], dtype=int32) Plotting and capturing output R's console (i.e. its stdout() connection) is captured by ipython, as are any plots which are published as PNG files like the notebook with arguments --pylab inline. As a call to %R may produce a return value (see above) we must ask what happens to a magic like the one below. The R code specifies that something is published to the notebook. If anything is published to the notebook, that call to %R returns None. In [10]: from __future__ import print_function v1 = %R plot(X,Y); print(summary(lm(Y~X))); vv=mean(X)*mean(Y) print('v1 is:', v1) v2 = %R mean(X)*mean(Y) print('v2 is:', v2) Call: lm(formula = Y ~ X) Residuals: 1 2 3 4 5 -0.2 0.9 -1.0 0.1 0.2 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.2000 0.6164 5.191 0.0139 * X 0.9000 0.2517 3.576 0.0374 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.7958 on 3 degrees of freedom Multiple R-squared: 0.81, Adjusted R-squared: 0.7467 F-statistic: 12.79 on 1 and 3 DF, p-value: 0.03739 v1 is: [ 10.] v2 is: [ 10.] What value is returned from %R? Some calls have no particularly interesting return value, the magic %R will not return anything in this case. The return value in rpy2 is actually NULL so %R returns None. In [11]: v = %R plot(X,Y) assert v == None Also, if the return value of a call to %R (in line mode) has just been printed to the console, then its value is also not returned. In [12]: v = %R print(X) assert v == None [1] 0 1 2 3 4 But, if the last value did not print anything to console, the value is returned: In [13]: v = %R print(summary(X)); X print('v:', v) Min. 1st Qu. Median Mean 3rd Qu. Max. 0 1 2 2 3 4 v: [0 1 2 3 4] The return value can be suppressed by a trailing ';' or an -n argument. In [14]: %R -n X In [15]: %R X; Cell level magic Often, we will want to do more than a simple linear regression model. There may be several lines of R code that we want to use before returning to python. This is the cell-level magic. For the cell level magic, inputs can be passed via the -i or --inputs argument in the line. These variables are copied from the shell namespace to R's namespace using rpy2.robjects.r.assign. It would be nice not to have to copy these into R: rnumpy ( http://bitbucket.org/njs/rnumpy/wiki/API ) has done some work to limit or at least make transparent the number of copies of an array. This seems like a natural thing to try to build on. Arrays can be output from R via the -o or --outputs argument in the line. All other arguments are sent to R's png function, which is the graphics device used to create the plots. We can redo the above calculations in one ipython cell. We might also want to add some output such as a summary from R or perhaps the standard plotting diagnostics of the lm. In [16]: %%R -i X,Y -o XYcoef XYlm = lm(Y~X) XYcoef = coef(XYlm) print(summary(XYlm)) par(mfrow=c(2,2)) plot(XYlm) Call: lm(formula = Y ~ X) Residuals: 1 2 3 4 5 -0.2 0.9 -1.0 0.1 0.2 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.2000 0.6164 5.191 0.0139 * X 0.9000 0.2517 3.576 0.0374 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.7958 on 3 degrees of freedom Multiple R-squared: 0.81, Adjusted R-squared: 0.7467 F-statistic: 12.79 on 1 and 3 DF, p-value: 0.03739 Passing data back and forth Currently, data is passed through RMagics.pyconverter when going from python to R and RMagics.Rconverter when going from R to python. These currently default to numpy.ndarray. Future work will involve writing better converters, most likely involving integration with http://pandas.sourceforge.net. Passing ndarrays into R seems to require a copy, though once an object is returned to python, this object is NOT copied, and it is possible to change its values. In [17]: seq1 = np.arange(10) In [18]: %%R -i seq1 -o seq2 seq2 = rep(seq1, 2) print(seq2) [1] 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 In [19]: seq2[::2] = 0 seq2 Out[19]: array([0, 1, 0, 3, 0, 5, 0, 7, 0, 9, 0, 1, 0, 3, 0, 5, 0, 7, 0, 9], dtype=int32) In [20]: %%R print(seq2) [1] 0 1 0 3 0 5 0 7 0 9 0 1 0 3 0 5 0 7 0 9 Once the array data has been passed to R, modifring its contents does not modify R's copy of the data. In [21]: seq1[0] = 200 %R print(seq1) [1] 0 1 2 3 4 5 6 7 8 9 But, if we pass data as both input and output, then the value of "data" in user_ns will be overwritten and the new array will be a view of the data in R's copy. In [22]: print(seq1) %R -i seq1 -o seq1 print(seq1) seq1[0] = 200 %R print(seq1) seq1_view = %R seq1 assert(id(seq1_view.data) == id(seq1.data)) [200 1 2 3 4 5 6 7 8 9] [200 1 2 3 4 5 6 7 8 9] [1] 200 1 2 3 4 5 6 7 8 9 Exception handling Exceptions are handled by passing back rpy2's exception and the line that triggered it. In [23]: try: %R -n nosuchvar except Exception as e: print(e) pass parsing and evaluating line "nosuchvar". R error message: "Error in eval(expr, envir, enclos) : object 'nosuchvar' not found " R stdout:"Error in eval(expr, envir, enclos) : object 'nosuchvar' not found " Structured arrays and data frames In R, data frames play an important role as they allow array-like objects of mixed type with column names (and row names). In bumpy, the closest analogy is a structured array with named fields. In future work, it would be nice to use pandas to return full-fledged DataFrames from rpy2. In the mean time, structured arrays can be passed back and forth with the -d flag to %R, %Rpull, and %Rget In [24]: datapy= np.array([(1, 2.9, 'a'), (2, 3.5, 'b'), (3, 2.1, 'c')], dtype=[('x', '<i4'), ('y', '<f8'), ('z', '|S1')]) In [25]: %%R -i datapy -d datar datar = datapy In [26]: datar Out[26]: array([(1, 2.9, 'a'), (2, 3.5, 'b'), (3, 2.1, 'c')], dtype=[('x', '<i4'), ('y', '<f8'), ('z', '|S1')]) In [27]: %R datar2 = datapy %Rpull -d datar2 datar2 Out[27]: array([(1, 2.9, 'a'), (2, 3.5, 'b'), (3, 2.1, 'c')], dtype=[('x', '<i4'), ('y', '<f8'), ('z', '|S1')]) In [28]: %Rget -d datar2 Out[28]: array([(1, 2.9, 'a'), (2, 3.5, 'b'), (3, 2.1, 'c')], dtype=[('x', '<i4'), ('y', '<f8'), ('z', '|S1')]) For arrays without names, the -d argument has no effect because the R object has no colnames or names. In [29]: Z = np.arange(6) %R -i Z %Rget -d Z Out[29]: array([0, 1, 2, 3, 4, 5], dtype=int32) For mixed-type data frames in R, if the -d flag is not used, then an array of a single type is returned and its value is transposed. This would be nice to fix, but it seems something that should be fixed at the rpy2 level (See: https://bitbucket.org/lgautier/rpy2/issue/44/numpyrecarray-as-dataframe) In [30]: %Rget datar2 Out[30]: array([['1', '2', '3'], ['2', '3', '2'], ['a', 'b', 'c']], dtype='|S1')
__label__pos
0.713016
Randommer The Randommer connector Service used to define a connection required for associated actions and start events. Examples include Salesforce and Box. Method of integration to cloud services, business applications and content stores. is used to create connections for Randommer actions A tool for building the processes, logic, and direction within workflows.. The following actions are available: Use these actions in a workflow to add validation and password security to a business process. This is useful when adding a new account or membership, as you can generate a new user password, and validate their phone numbers and identity documents. Create a Randommer connection You can create connections from the Automate or Designer page. Assign permissions Permissions enable you to manage access for other users to use, edit, and delete connections. Note: By default, users with administrator role will have the same rights as a Connection owner.   Use Edit Delete Assign permissions Owners Users Follow these steps to assign permissions from the Connections page: 1. On the Connections page, click for the required connection. 2. From the menu, select Permissions. 3. To assign permissions: • In the Owners field, type the name of the user, and select from the list. • In the Users field, type the name of the user, and select from the list. 1. Click Save permissions.
__label__pos
0.829101
Easy To Use Patents Search & Patent Lawyer Directory At Patents you can conduct a Patent Search, File a Patent Application, find a Patent Attorney, or search available technology through our Patent Exchange. Patents are available using simple keyword or date criteria. If you are looking to hire a patent attorney, you've come to the right place. Protect your idea and hire a patent lawyer. Search All Patents:   This Patent May Be For Sale or Lease. Contact Us   Is This Your Patent? Claim This Patent Now. Register or Login To Download This Patent As A PDF United States Patent 9,596,606 Palmer ,   et al. March 14, 2017 Application programming interface gateway for sponsored data services Abstract A method to facilitate secure access to a sponsored data service (SDS) through an application programming interface gateway includes providing an access token to a content provider device, where the access token authorizes the content provider device to receive sponsored data services (SDSs). The method also includes receiving a first request for an SDS resource from the content provider device; generating a first timestamp associated with the first request; determining a destination for the first request, where the destination specifies a network address corresponding to an SDS resource device; forwarding the first request to the SDS resource device based on the determined destination; receiving a first response from the SDS resource device corresponding to the first request; generating a second timestamp associated with the first response; and forwarding the first response, along with the first timestamp and the second timestamp, to the content provider device. Inventors: Palmer; Okeno (Oakland, CA), Ren; Dahai (Lincoln, MA), Saint-Hilaire; Hector (Waltham, MA), Wu; Shuai (Wellesley, MA) Applicant: Name City State Country Type Verizon Patent and Licensing Inc. Arlington VA US Assignee: VERIZON PATENT AND LICENSING INC. (Basking Ridge, NJ) Family ID: 1000001903994 Appl. No.: 15/137,119 Filed: April 25, 2016 Current U.S. Class: 1/1 Current CPC Class: H04W 12/08 (20130101); H04W 12/06 (20130101); H04L 63/0846 (20130101); H04W 88/16 (20130101) Current International Class: H04M 1/66 (20060101); H04W 12/08 (20090101); H04L 29/06 (20060101); H04W 12/06 (20090101); H04M 3/16 (20060101); H04M 1/68 (20060101); H04W 88/16 (20090101) References Cited [Referenced By] U.S. Patent Documents 8243928 August 2012 Park 2005/0088976 April 2005 Chafle 2014/0270172 September 2014 Peirce 2015/0245202 August 2015 Patil 2015/0341333 November 2015 Feng 2015/0372875 December 2015 Turon Primary Examiner: Patel; Ajit Claims What is claimed is: 1. A method, comprising: providing, from an application programming interface (API) gateway device, an access token to a content provider device, wherein the access token authorizes the content provider device to access resources for sponsored data services (SDSs); receiving, at the API gateway device, a first request for an SDS resource from the content provider device; generating, at the API gateway device, a first timestamp associated with the first request; determining, at the API gateway device, a destination for the first request, wherein the destination specifies a network address corresponding to an SDS resource device; forwarding, from the API gateway device, the first request to the SDS resource device based on the determined destination; receiving, at the API gateway device, a first response from the SDS resource device corresponding to the first request; generating, at the API gateway device, a second timestamp associated with the first response; and forwarding, from the API gateway device, the first response, along with the first timestamp and the second timestamp, to the content provider device. 2. The method of claim 1, wherein providing the access token to the content provider device, further comprises: receiving, at the API gateway device, an authentication request from the content provider device, wherein the authentication request includes credentials of the content provider device; generating, at the API gateway device, a third timestamp associated with the authentication request; determining, at the API gateway device, that an authentication device is a destination for the authentication request; forwarding, from the API gateway device, the authentication request and the credentials of the content provider device to the authentication device; receiving, at the API gateway device, the access token, wherein the access token is based on the credentials of the content provider device; generating, at the API gateway device, a fourth timestamp associated with the authentication request; and forwarding, from the API gateway device, the access token, along with the third timestamp and the fourth timestamp, to the content provider device. 3. The method of claim 2, further comprising: caching, at the API gateway device, the access token. 4. The method of claim 2, wherein receiving the authentication request further comprises: receiving credentials which include a client identifier and a client secret. 5. The method of claim 1, wherein the receiving the first request further comprises receiving a session timing record manager (STRM) call from the content provider device, wherein the STRM call includes the access token, wherein the generating the first timestamp further comprises generating the first timestamp associated with the STRM call, and the method further comprises: determining, at the API gateway device, whether an authentication header associated with the STRM call is valid. 6. The method of claim 5, further comprising: sending a request to an authentication device to validate the access token in response to determining that the authentication header is valid. 7. The method of claim 6, wherein in response to the request to the authentication device to validate the access token, the method further comprises: receiving a confirmation from the authentication device that the access token is valid; wherein the determining the destination for the first request further comprises determining the STRM as the destination; wherein the forwarding the first request further comprises forwarding the STRM call along with the first timestamp and the validated access token to the STRM; wherein the receiving the first response further comprises receiving an acknowledgement from the STRM corresponding to the STRM call; wherein the generating a second timestamp further comprises generating the second timestamp in response to the acknowledgement from the STRM; and wherein the forwarding the first response further comprises forwarding the acknowledgment from the STRM, along with the first timestamp and the second timestamp, to the content provider device. 8. The method of claim 6, wherein in response to the request to the authentication device to validate the access token, the method further comprises: receiving an error message indicating the access token is invalid; and forwarding the error message to the content provider device. 9. The method of claim 5, wherein upon determining that the authentication header is not valid, the method further comprises: receiving an error message indicating the authentication header is invalid; and forwarding the error message to the content provider device. 10. A device, comprising: an interface configured to communicate with a network; a memory configured to store instructions; and a processor, coupled to the interface and the memory, wherein the stored instructions, when executed by the processor, cause the processor to: provide an access token to a content provider device, wherein the access token authorizes the content provider device to access resources for sponsored data services (SDSs), receive a first request for an SDS resource from the content provider device, generate a first timestamp associated with the first request, determine a destination for the first request, wherein the destination specifies a network address corresponding to an SDS resource device, forward the first request to the SDS resource device based on the determined destination, receive a first response from the SDS resource device corresponding to the first request, generate a second timestamp associated with the first response, and forward the first response, along with the first timestamp and the second timestamp, to the content provider device. 11. The device of claim 10, wherein the instructions to provide the access token to the content provider device comprise instructions further causing the processor to: receive an authentication request from the content provider device, wherein the authentication request includes credentials of the content provider device, generate a third timestamp associated with the authentication request, determine that an authentication device is a destination for the authentication request, forward the authentication request and the credentials of the content provider device to the authentication device, receive the access token, wherein the access token is based on the credentials of the content provider device, generate a fourth timestamp associated with the authentication request, and forward the access token, along with the third timestamp and the fourth timestamp, to the content provider device. 12. The device of claim 11, wherein the instructions further cause the processor to: cache the access token. 13. The device of claim 11, wherein the instructions to receive the authentication request further cause the processor to: receive credentials which include a client identifier and a client secret. 14. The device of claim 10, wherein the instructions to receive the first request cause the processor to: receive a session timing record manager (STRM) call from the content provider device, wherein the STRM call includes the access token, wherein the instructions to generate the first timestamp further cause the processor to: generate the first timestamp associated with the STRM call, and the memory stores instructions further causing the processor to: determine whether an authentication header associated with the STRM call is valid. 15. The device of claim 14, wherein when determining whether the authentication header is valid, the instructions further cause the processor to: send a request to an authentication device to validate the access token in response to determining that the authentication header is valid. 16. The device of claim 15, wherein in response to the request to the authentication device to validate the access token, the instructions further cause the processor to: receive a confirmation from the authentication device that the access token is valid; wherein the instructions to determine the destination for the first request causes the processor to determine the STRM as the destination; wherein the instructions to forward the first request causes the processor to forwarding the STRM call along with the first timestamp and the validated access token to the STRM; wherein the instructions to receive the first response further causes the processor to receive an acknowledgement from the STRM corresponding to the STRM call; wherein the instructions to generate a second timestamp further causes the processor to generate the second timestamp in response to the acknowledgement from the STRM; and wherein the instructions to forward the first response further causes the processor to forward the acknowledgment from the STRM, along with the first timestamp and the second timestamp, to the content provider device. 17. The device of claim 15, wherein in response to the request to the authentication device to validate the access token, the instructions further cause the processor to: receive an error message indicating the access token is invalid, and forward the error message to the content provider device. 18. The device of claim 14, wherein upon determining that the authentication header is not valid, the instructions further cause the processor to: receive an error message indicating the authentication header is invalid; and forward the error message to the content provider device. 19. A non-transitory computer-readable medium comprising instructions, which, when executed by a processor, cause the processor to: provide an access token to a content provider device, wherein the access token authorizes the content provider device to access resources for sponsored data services (SDSs); receive a first request for an SDS resource from the content provider device; generate a first timestamp associated with the first request; determine a destination for the first request, wherein the destination specifies a network address corresponding to an SDS resource device; forward the first request to the SDS resource device based on the determined destination; receive a first response from the SDS resource device corresponding to the first request; generate a second timestamp associated with the first response; and forward the first response, along with the first timestamp and the second timestamp, to the content provider device. 20. The non-transitory computer-readable medium of claim 19, wherein the instructions to provide the access token to the content provider device comprise instructions further causing the processor to: receive an authentication request from the content provider device, wherein the authentication request includes credentials of the content provider device; generate a third timestamp associated with the authentication request; determine that an authentication device is a destination for the authentication request; forward the authentication request and the credentials of the content provider device to the authentication device; receive the access token, wherein the access token is based on the credentials of the content provider device; generate a fourth timestamp associated with the authentication request; and forward the access token, along with the third timestamp and the fourth timestamp, to the content provider device. Description BACKGROUND User access to wireless communication networks and data services typically involves some form of payment made to the network provider. In some instances, a third party may wish to sponsor a user's data consumption in order to entice user engagement. A user's access to sponsored data may involve data exchanges between content providers and a variety of infrastructure devices in order to provide secure access to content and accurate billing to the sponsor for data consumed by the user. BRIEF DESCRIPTION OF THE DRAWINGS FIG. 1 is a block diagram of an exemplary network environment for facilitating access to sponsored data services (SDSs) using an application programming interface (API) gateway device; FIG. 2 is a block diagram of an exemplary networking system that provides sponsored data over various types of wireless channels; FIG. 3 is a block diagram illustrating details of the content provider device, the API gateway device, and the SDS resource device(s) according to an embodiment; FIG. 4 is a block diagram showing exemplary components of an API gateway device according to an embodiment; FIG. 5 is a diagram depicting exemplary message flows between selected devices within the network environment shown in FIG. 1; FIG. 6 is a diagram depicting exemplary message flows associated with granting an access token to a content provider device within the network environment shown in FIG. 1; FIG. 7 is a diagram depicting exemplary message flows associated with an authentication device and a session timing record manager (STRM) in the network environment shown in FIG. 1; and FIG. 8 is a flow chart showing an exemplary process for facilitating secure access to a sponsored data service (SDS) through an application programming interface (API) gateway device. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS The following detailed description refers to the accompanying drawings. The same reference numbers in different drawings may identify the same or similar elements. The following detailed description does not limit the invention. Embodiments described herein are directed to an application programming interface (API) gateway which may facilitate secure access by a content provider to a sponsored data service (SDS). An SDS (which is also referred to herein as a "toll free data service") may include a network service that is financially supported by a third party entity. The third party entity, hereinafter referred to as a "sponsor," subsidizes the network data exchanged between a user device and a specified content provider. The sponsor may have a relationship with the network provider that permits the automatic billing of the sponsor for the exchanged data, instead of the user of a user device. Thus, the data exchanged through the SDS (which may also be referred to herein as "sponsored data" or "sponsored content") is effectively "toll-free" as seen by the user of the user device. The sponsored data may be downloaded to the user device from the specified content provider. Sponsored content may include, for example, content represented as alphanumeric text, graphics, images, audio, and/or video data. In modern network configurations, sponsored content may be provided from a number of different content providers interconnected by one or more networks. In some instances, one or more content providers, in addition to hosting their own content, may act as content aggregators or "middlemen," and provide access to additional content hosted by other "downstream" content providers. In order to maintain network security and proper billing and data accounting integrity, secure methods may be used to provide sponsored data among the various content providers using architectures which may include an API gateway device. The API gateway device, in conjunction with modules and APIs residing within the content providers (hereinafter referred to as "service side plugins"), may manage interactions between the content providers and network infrastructure devices supporting SDS resources. Thus, the API gateway device 170 may act as a "reverse proxy" for the content providers in accessing SDS resources. As will be explained in more detail below, such secure methods can include the use of time stamps and credentials for authentication and validation of billing and/or data accounting. Thus, embodiments presented herein reduce the burden of content partners interacting with a variety of infrastructure devices to support sponsored data services. FIG. 1 is a block diagram of an exemplary network environment 100 for facilitating access to sponsored data services (SDSs) through an application programming interface (API) gateway device. Environment 100 may include one or more user devices 105, network 115, a content provider device 160, an API gateway device 170, one or more SDS resource device(s) 180, and an SDS portal device 190. Network 115 may include one or more wireless network(s) 110 and a wide area network 150. Wireless networks 110 may further include, for example, a cellular network 120, a wide area wireless network 130, and/or a local area wireless network 140. For ease of explanation, only one user device 105, content provider device 160, API gateway device 170, and SDS portal device 190 are illustrated as being connected to network 115. However, it should be understood that a plurality of user devices 105, content provider devices 160, API gateway devices 170, SDS portal devices 190, and/or other known network entities may be communicatively coupled to network 115. FIG. 1 depicts a representative environment 100 with exemplary components and configuration shown for purposes of explanation. Other embodiments may include additional or different network entities in alternative configurations than which are exemplified in FIG. 1. User device 105 may obtain access to network 115 through wireless network(s) 110 over any type of known radio channel or combinations thereof. For example, user device 105 may access cellular network 120 over wireless channel 125. Access over wireless channel 125 may be provided through a base station, eNodeB, etc., within cellular network 120, as will be described in more detail below in reference to an embodiment shown in FIG. 2. In various embodiments, cellular network 120, wide area wireless network 130, and/or local area wireless network 140 may also communicate with each other in addition to user device 105. User device 105 may also access network 115 over wireless channel 135 through wide area wireless network 130. Wide area wireless network 130 may include any type wireless network covering larger areas, and may include a mesh network (e.g., IEEE 801.11s) and/or or a WiMAX IEEE 802.16. User device 105 may access network 115 over wireless channel 145 through local area wireless network 140, which may include WiFi (e.g., any IEEE 801.11x network, where x=a, b, g, n, and/or ac). The wireless network(s) 110 may exchange data with wide area network 150 that may include backhaul networks, backbone networks, and/or core networks. Content provider device 160, API gateway device 170, and SDS portal device 190 may interface with wide area network 150, and thus with user device 105 over one or more of the air interfaces 125, 135, 145 through wireless network(s) 110. In the embodiment shown in FIG. 1, SDS resource device(s) 180 may communicate with API gateway device 170 over, for example, a back-end private network (not shown) which may be controlled by a network provider. However, in other embodiments, additionally, or alternatively, SDS resource device(s) may also communicate with API gateway device 170 through wide area network 150. User device 105 may obtain SDS access to network 115 over one or more air interfaces 125, 135, and/or 145, which may be supported by the sponsor to provide content to user device 105 through content provider device 160. As used herein, content may also be referred to herein as "media," and may include any type of digital data representing user-interpretable information, including text, image, audio, and/or video data. Media may also include one or more combinations of any type of digital data that may be arranged, composited, and presented to the user, such as, for example, in the form of web pages described using hypertext markup language (HTML). Connections for sponsored data exchanges may be established by sponsors who arrange access for particular events and/or promotions (which may be referred to herein as "campaigns"). The campaigns may be arranged through SDS portal device 190 assigned by the network provider (e.g., a web portal under control of the network provider). In an embodiment, the sponsor may access SDS portal device 190 through content provider device 160. Additionally, or alternatively, the sponsor may also access SDS portal device 190 through another independent network device (not shown). When setting up a particular content provider device 160 to provide sponsored content for a campaign, the SDS portal 190 may be used to obtain software and/or data files (e.g., a server side plugin) to facilitate communications through API gateway device 170 for accessing various SDS resource device(s) 180. Additionally, SDS portal device 190 may provide credentials for the content provider which allow access to SDS resource devices 180. When arranging a campaign, the sponsor may set various parameters for the campaign (such as, for example, media specification, time duration, maximum number of users, maximum allotment of data, etc.). The sponsor may also provide campaign network addresses identifying content providers and customer identifiers indicating the identity of a content provider. Accordingly, campaign network addresses and customer identifiers may be entered for content provider device 160. The campaign network addresses may be used in generating SDS network addresses which are used by the user device 105 to request sponsored content from content provider device 160. For example, a campaign network address may be a URL linking to content provider device 160 that user device 105 may use to access sponsored content. In order to validate transactions with the infrastructure of the SDS and/or ensure that sponsors are properly billed for content, API gateway device 170 provides an interface between a network provider's back-end infrastructure and content provider device 160. Accordingly, content provider device 160 may exchange data with SDS resource device(s) 180 through API gateway device 170, as, for example, a single point of contact. Thus, API gateway device 170 may accept requests from content provider 160 for various back-end SDS services, and then route the requests to the appropriate SDS resource device(s) 180 depending upon the request. Additionally, API gateway device 170 may receive responses from the requests, and route the responses back to the requesting content provider device 160. Moreover, to facilitate security, sponsor billing, and/or data consumption tracking, API gateway device 170 may further generate timestamps corresponding to received requests from content provider device 160 and/or responses from SDS resource device(s) 180, and bundle timestamps when forwarding the requests to SDS resource devices 180 and/or the responses to content provider device 160. Further referring to FIG. 1, user device 105 may include any type of electronic device having communication capabilities, and thus communicate over network 115 using a variety of different channels, including both wired and wireless connections. User device 105 may include, for example, a cellular radiotelephone, a smart phone, a wearable computer (e.g., a wrist watch, eye glasses, etc.), a tablet, a set-top box (STB), a mobile phone, any type of IP communications device, a Voice over Internet Protocol (VoIP) device, a laptop computer, a palmtop computer, a gaming device, a media player device, or a digital camera that includes communication capabilities (e.g., wireless communication mechanisms). User device 105 may use applications or websites to download sponsored content by making network requests using the signed SDS network addresses. Requests for sponsored content may be intercepted by network devices in back-end infrastructure (not shown) which are responsible for tracking downloaded toll free data and billing sponsors campaign for cost of data used. Wireless network(s) 110 may include one or more wireless networks of any type, such as, for example, a local area network (LAN), a wide area network (WAN), a wireless satellite network, and/or one or more wireless public land mobile networks (PLMNs). The PLMN(s) may include a Code Division Multiple Access (CDMA) 2000 PLMN, a Global System for Mobile Communications (GSM) PLMN, a Long Term Evolution (LTE) PLMN and/or other types of PLMNs not specifically described herein. Wide area network 150 may be any type of wide area network connecting back-haul networks and/or core networks, and may include a metropolitan area network (MAN), an intranet, the Internet, a cable-based network (e.g., an optical cable network), networks operating known protocols, including Asynchronous Transfer Mode (ATM), Optical Transport Network (OTN), Synchronous Optical Networking (SONET), Synchronous Digital Hierarchy (SDH), Multiprotocol Label Switching (MPLS), and/or Transmission Control Protocol/Internet Protocol (TCP/IP). Content provider device 160 may be any type of network device (e.g., a web server, computer, media repository, streaming source, etc.) that may provide access to sponsored content via signed SDS network addresses. The signed SDS network address may link to sponsored content which is hosted locally on content provider device 160, or remotely on one or more content partner devices (not shown). Content provider device 160 may be owned by the sponsor or act as agent of the sponsor, serving as a "middle man" to provide access for sponsored content to user device 105 from any content provider identified by signed SDS network identifiers. Content provider device 160 may host and/or provide links to any type of media, such as, for example, text, audio, image, video, software code, etc. API gateway device 170 may be any type of network device (e.g., a server, computer, etc.), or servlet running within a web server, that may respond to requests from content provider device 160 for SDS resources, and provide responses from SDS resource device(s) 180 back to content provider device 160. API gateway device 170 may act as a reverse proxy by redirecting relevant requests to appropriate SDS resource device(s) 180 by determining network destinations based on requests from content provider devices 160, and determine network destinations of content provider devices 160 based on responses from SDS resource device(s) 180. In addition to serving as a reverse proxy, API gateway device 170 may generate timestamps associated with received requests and responses, and attach the generated timestamps when forwarding the requests and response to the appropriate network device. The timestamps appended to the request/response pairs associated with content provider device 160 are used in the determination of billing for the sponsored content used in the SDS sessions. SDS resource device(s) 180 may be any type of network device, such as, for example, a server, computer, a servlet, etc., which may reside in the back-end infrastructure of sponsored data service, and may be controlled in whole, or in part, by a network provider. SDS resource devices 180 may provide various resources in response to requests from content provider devices 160 received through API gateway device 170. Examples of SDS resource device(s) 180 may include authentication devices for validating SDS requests, content provider devices 160 and/or their associated sponsors, user devices 105 and/or client end users. SDS resource device(s) 180 may also include various managers and/or collection devices to facilitate sponsor billing and data usage tracking. For example, SDS resource device(s) 180 may include a session timing record manager (STRM) which may collect and manage time stamps received from the API gateway device. SDS portal device 190 may be any type of network device, such as, for example, a server, computer, etc., that receives information from sponsors and/or their agents to generate and modify a campaign for sponsored data. In embodiments provided herein, the sponsor may designate content provider device 160 (either under the direct control of the sponsor, or as a designated agent) to create the campaign by logging into SDS portal device 190 to supply campaign network addresses (e.g., campaign URLs) for content providers and customer identifiers (e.g., customer identification numbers) associated with the campaign network addresses. SDS portal device 190 may provide content provider devices 160 credentials (such as client identifiers (IDs) and/or client secrets), software APIs (e.g., service side plugins described below in relation to FIG. 3), and/or data to facilitate exchanges with the SDS resource device(s) 180 through API gateway device 170. Content provider devices 160 may also log into SDS portal device 190 to obtain APIs and/or security credentials used for signing SDS network addresses to validate requests from user device 105. FIG. 2 is a block diagram of an exemplary networking system 200 that provides sponsored data over various types of wireless channels. As shown in FIG. 2, networking system 200 may include user device 105 embodied as user equipment (UE) 205-A and UE 205-B (as used herein, collectively referred to as "UE 205" and individually as "UE 205-x"), a wireless network 210 which includes an evolved Packet Core (ePC) 212 and an evolved UMTS Terrestrial Network (eUTRAN) 214, an Internet Protocol (IP) network 250, a WiFi wireless access point (WAP) 225, content provider device 160, API gateway device 170, SDS resource device(s) 180, and SDS portal device 190. Wireless network 210 may be a long term evolution (LTE) network, and include one or more devices that are physical and/or logical entities interconnected via standardized interfaces. Wireless network 210 provides wireless packet-switched services and wireless IP connectivity to user devices to provide, for example, data, voice, and/or multimedia services. The ePC 212 may further include a mobility management entity (MME) 230, a serving gateway (SGW) device 240, a packet data network gateway (PGW) 270, and a home subscriber server (HSS) 260. The eUTRAN 214 may further include one or more eNodeBs 220-A and 220-B (herein referred to plurally as "eNodeB 220" and individually as "eNodeB 220-x"). It is noted that FIG. 2 depicts a representative networking system 200 with exemplary components and configuration shown for purposes of explanation. Other embodiments may include additional or different network entities in alternative configurations than which are exemplified in FIG. 2. Further referring to FIG. 2, each eNodeB 220 may include one or more devices and other components having functionality that allow UE 205 to wirelessly connect to eUTRAN 214. eNodeB 220-A and eNodeB 220-B may each interface with ePC 212 via a S1 interface, which may be split into a control plane S1-MME interface 225-A and a data plane S1-U interface 226. For example, S1-MME interface 225-A may interface with MME device 230. S1-MME interface 225-A may be implemented, for example, with a protocol stack that includes a Network Access Server (NAS) protocol and/or Stream Control Transmission Protocol (SCTP). S1-U interface 226-B may interface with SGW 240 and may be implemented, for example, using a General Packet Radio Service Tunneling Protocol version 2 (GTPv2). ENodeB 220-A may communicate with eNodeB 220-B via an X2 interface 222. X2 interface 222 may be implemented, for example, with a protocol stack that includes an X2 application protocol and SCTP. MME device 230 may implement control plane processing for ePC 212. For example, MME device 230 may implement tracking and paging procedures for UE 205, may activate and deactivate bearers for UE 205, may authenticate a user of UE 205, and may interface to non-LTE radio access networks. A bearer may represent a logical channel with particular quality of service (QoS) requirements. MME device 230 may also select a particular SGW 240 for a particular UE 205. A particular MME device 230 may interface with other MME devices 230 in ePC 212 and may send and receive information associated with UEs, which may allow one MME device to take over control plane processing of UEs serviced by another MME device, if the other MME device becomes unavailable. SGW 240 may provide an access point to and from UE 205, may handle forwarding of data packets for UE 205-A, and may act as a local anchor point during handover procedures between eNodeBs 220. SGW 240 may interface with PGW 270 through an S5/S8 interface 245. S5/S8 interface 245 may be implemented, for example, using GTPv2. PGW 270 may function as a gateway to IP network 250 through a SGi interface 255. IP network 250 may include, for example, an IP Multimedia Subsystem (IMS) network, which may provide voice and multimedia services to UE 205, based on Session Initiation Protocol (SIP). A particular UE 205, while connected to a single SGW 240, may be connected to multiple PGWs 270, one for each packet network with which UE 205 communicates. Alternatively, UE 205-B may exchange data with IP network 250 though WiFi wireless access point (WAP) 225. The WiFi WAP 225 may be part of a local area network, and access IP network 250 through a wired connection via a router. Alternatively, WiFi WAP 225 may be part of a mesh network (e.g., IEEE 801.11s). WiFi WAP 225 may be part of a local area network, or part of a wide area network (WiMaxx) or a mesh network (IEEE 801.11s). MME device 230 may communicate with SGW 240 through an S11 interface 235. S11 interface 235 may be implemented, for example, using GTPv2. S11 interface 235 may be used to create and manage a new session for a particular UE 205. S11 interface 235 may be activated when MME device 230 needs to communicate with SGW 240, such as when the particular UE 205 attaches to ePC 212, when bearers need to be added or modified for an existing session for the particular UE 205, when a connection to a new PGW 270 needs to created, or during a handover procedure (e.g., when the particular UE 205 needs to switch to a different SGW 240). HSS device 260 may store information associated with UEs 205 and/or information associated with users of UEs 205. For example, HSS device 260 may store user profiles that include authentication and access authorization information. MME device 230 may communicate with HSS device 260 through an S6a interface 265. S6a interface 265 may be implemented, for example, using a Diameter protocol. Content provider device 160 may be any type of web server, media repository, streaming source, etc., that can provide UE 205 with sponsored content which is locally hosted, or provided from another networked content partner device (not shown). Content provider device 160 may exchange information using a standard TCP/IP interface with IP network 250, and further communicate with ePC 212 using SGi 255. Communications between content provider device 160 and UEs 205 may be performed through ePC 212 and eUTRAN 214 as shown for UE 205-A, or through WiFi WAP 225 as shown for UE 205-B. Content provider device 160 may provide any form of media, text, audio, image, video, etc., to requesting UE 205. Moreover, content provider device 160 may provide simultaneous broadcast of data to a plurality of UEs 205 using simulcast and/or multicast techniques, such as, for example, any type of multimedia broadcast multicast service (MBMS) and/or evolved MBMS (eMBMS) over LTE. In one embodiment, UE 205 may provide a request to content provider device 160 over wireless network 210. The request for sponsored data access may be initially received by the eUTRAN 214, and then forwarded through gateways SGW 240 and PGW 270 to content provider device 160. The communications between content provider device 160 and UE 205 may be "channel agnostic," and thus may be performed using any known wireless and/or wired channels, or combinations thereof. Accordingly, other methods for communication between content provider device 160 and UE 205 may be used which are not illustrated in FIG. 2. API gateway device 170 may be any type of network device, computer, web server, etc. which may act as an intermediary between content provider device 160 and SDS resource device(s) 180. API gateway device 170 may interface to IP network 250 for exchanging data between content provider device 160 and SDS resource device(s) 180. SDS resource device(s) 180 may be network device, computer, web server, etc. which may provide resources to content provider devices 160 to facilitate sponsored data services. SDS resource device(s) 180 may interface to IP network 250 to exchange data with other network components, for example, with content provider device 160 through API gateway device 170. SDS portal device 190 may be any type of web server, computer, network device, etc. that may be used to generate and modify a campaign for sponsored data based on information received from sponsor controlled devices, such as, for example, content provider device 160. In embodiments provided herein, the sponsor may create the campaign by logging into SDS portal device 190 to supply campaign network addresses and customer identifiers associated with the campaign network addresses. SDS portal device 190 may exchange information with content provider device 160 using, for example, a standard TCP/IP interface with IP network 250. While FIG. 2 shows exemplary components of system 200, in other implementations, networking system 200 may include fewer components, different components, differently arranged components, or additional components than depicted in FIG. 2. Additionally, or alternatively, one or more components of networking system 200 may perform functions described as being performed by one or more other components of networking system 200. FIG. 3 is a block diagram illustrating details of content provider device 160, API gateway device 170, and SDS resource device(s) 180 according to an embodiment. Content provider device 160 may include application server 310, server side plugin 320, and service side plugin database 330. API gateway device 170 may include mapping file 360 and configuration file 370. SDS resource device(s) 180 may include session timing record manager (STRM) 340 and authentication device 350. Content provider device 160 may receive a request for sponsored content (e.g., a request for movie files from a movie site) from end users via user device 105 over network 115. Application server 310 may initially process the sponsored content request which may be received via an SDS network address used by mobile device 105 to access content provider device 160. In an embodiment, the SDS network address and content request may be made in the form of a URL request using hypertext transfer protocol (HTTP). Application server 310 may pass the sponsored content request to server side plugin 320 which detects the SDS network address, and caches selected information received from the SDS network address in server side plugin database 330. The cached information may include, for example, the credentials of the user making the request. Additionally, server side plugin database 330 may also cache timestamps generated by API gateway device 170, as will be described in more detail below in regards to FIG. 5. In order to authenticate the sponsored content request, and/or to record information for billing and/or data usage (e.g. timestamps), server side plugin 320 may access SDS resource device(s) 180 via wide area network 150 through API gateway device 170. SDS resource device(s) 180 may be embodied in back-end infrastructure devices, and thus may be protected by network security devices (e.g., firewalls). Accordingly, access to SDS resource device(s) 180 by server side plugin 320 is securely managed by API gateway device 170. All requests going through API gateway device 170 may be validated by authentication device 350. SDS resource device(s) 180 may further include STRM 340 which records and manages timestamps generated by API gateway device 170. The timestamps appended to the request/response pairs involved with server side plugin 320 aide in the proper calculation of Session Timing Records (STR) which may be used for billing information and/or data usages associated with SDS (e.g., HTTP secure) sessions. Described below is a simplified description of the call flow for server side plugin 320 to access services of STRM 340 through API gateway device 170. Detailed descriptions of different call flows are described in relation to FIGS. 5-7. Initially, server side plugin 320 may send a call to STRM 340 requesting that it record a timestamp generated by API gateway device 170. Server side plugin 320 may send the call via wide area network 150 to API gateway device 170. API gateway device 170 may access authentication device 350 to determine if content provider device 160 is authorized to send this call to STRM 340. Upon being validated by authentication device 350, API gateway device 170 may determine from information embedded in the call that the STRM 340 is the appropriate destination to forward the call, and then may generate a timestamp of when the call was received, and forward the call along with the timestamp to the STRM 340. STRM 340 may process the call and record received timestamp, and provide an acknowledgment back to the API gateway device 170. The API gateway device 170 may generate another timestamp of when the acknowledgment was received, and forward the acknowledgment and the timestamp pair to the server side plugin 320. Internally, API gateway device 170 may determine a destination to forward traffic based on information received in the request (e.g., in a uniform resource identifier). The destinations for traffic may be defined in configuration file 370. When a request is received, API gateway device 170 may execute a mapping according to mapping file 360 to determine whether the API gateway device 170 will take action on the request or not. The mapping permits the API gateway device 170 to parse information (e.g., characters in the received request) to match string patterns associated with different SDS resource devices 180. If a match is determined and a string pattern is recognized, then API gateway device 170 may obtain a network address of the SDS resource device 180 corresponding to the matched string pattern. In an embodiment, mapping file 360 may be in the form of an extensible markup language (XML) file, and configuration file may be a text-based data that can be manually specified. FIG. 4 is a block diagram showing exemplary components of an API gateway device 170 according to an embodiment. API gateway device 170 may include a bus 410, a processor 420, a memory 430, mass storage 440, an input device 450, an output device 460, and a communication interface 470. Other devices in environment 100, such as content provider device 160, SDS resource device(s) 180, and SDS portal device 190 may be configured in a similar manner. Bus 410 includes a path that permits communication among the components of API gateway device 170. Processor 420 may include any type of single-core processor, multi-core processor, microprocessor, latch-based processor, and/or processing logic (or families of processors, microprocessors, and/or processing logics) that interprets and executes instructions. In other embodiments, processor 420 may include an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), and/or another type of integrated circuit or processing logic. For example, processor 420 may be an x86 based CPU, and may use any operating system, which may include varieties of the Windows, UNIX, and/or Linux operating systems. Processor 420 may also use high-level analysis software packages and/or custom software written in any programming and/or scripting languages for interacting with other network entities are communicatively coupled to WAN 150. Memory 430 may include any type of dynamic storage device that may store information and/or instructions, for execution by processor 420, and/or any type of non-volatile storage device that may store information for use by processor 420. For example, memory 430 may include a random access memory (RAM) or another type of dynamic storage device, a read only memory (ROM) device or another type of static storage device, and/or a removable form of memory, such as a flash memory. Mass storage 440 may include any type of on-board device suitable for storing large amounts of data, and may include one or more hard drives, solid state drives, and/or various types of redundant array of independent disks (RAID) arrays. Mass storage device 440 is suitable for storing data associated with, for example, mapping file 360, configuration file 370, various credentials (for example client identifiers and client secrets), etc. Input device 450, which may be optional, can allow an operator to input information into API gateway device 170, if required. Input device 450 may include, for example, a keyboard, a mouse, a pen, a microphone, a remote control, an audio capture device, an image and/or video capture device, a touch-screen display, and/or another type of input device. In some embodiments, API gateway device 170 may be managed remotely and may not include input device 450. Output device 460 may output information to an operator of API gateway device 170. Output device 460 may include a display (such as a liquid crystal display (LCD)), a printer, a speaker, and/or another type of output device. In some embodiments, API gateway device 170 may be managed remotely and may not include output device 460. Communication interface 470 may include a transceiver that enables API gateway device 170 to communicate with other devices and/or systems over a network (e.g., wide area network 150, IP network 250, etc.). Communications interface 470 may be configured to exchange data over wired communications (e.g., conductive wire, twisted pair cable, coaxial cable, transmission line, fiber optic cable, and/or waveguide, etc.), or a combination of wireless. In other embodiments, communication interface 470 may communicate using a wireless communications channel, such as, for example, radio frequency (RF), infrared, and/or visual optics, etc. Communication interface 470 may include a transmitter that converts baseband signals to RF signals and/or a receiver that converts RF signals to baseband signals. Communication interface 470 may be coupled to one or more antennas for transmitting and receiving RF signals. Communication interface 470 may include a logical component that includes input and/or output ports, input and/or output systems, and/or other input and output components that facilitate the transmission/reception of data to/from other devices. For example, communication interface 470 may include a network interface card (e.g., Ethernet card) for wired communications and/or a wireless network interface (e.g., a WiFi) card for wireless communications. Communication interface 470 may also include a universal serial bus (USB) port for communications over a cable, a Bluetooth.RTM. wireless interface, an radio frequency identification device (RFID) interface, a near field communications (NFC) wireless interface, and/or any other type of interface that converts data from one form to another form. As described below, API gateway device 170 may perform certain operations relating to facilitating secure communications between content provider devices 160 and SDS resource device(s) 180. API gateway device 170 may perform these operations in response to processor 420 executing software instructions contained in a computer-readable medium, such as memory 430 and/or mass storage 440. The software instructions may be read into memory 430 from another computer-readable medium or from another device. The software instructions contained in memory 430 may cause processor 420 to perform processes described herein. Alternatively, hardwired circuitry may be used in place of, or in combination with, software instructions to implement processes described herein. Thus, implementations described herein are not limited to any specific combination of hardware circuitry and software. Although FIG. 4 shows exemplary components of API gateway device 170, in other implementations, API gateway device 170 may include fewer components, different components, additional components, or differently arranged components than depicted in FIG. 4. FIG. 5 is a diagram depicting exemplary message flows 500 between selected devices within the network environment 100 shown in FIG. 1. Specifically, message flows between content provider device 160, API gateway device 170, and a particular SDS resource device 180 are shown. Initially, content provider device 160 may send a request for a particular SDS resource to API gateway device 170 (M502). API gateway device 170 may generate a timestamp (T1) upon receiving request M502 from content provider device 160 (Block 505). The timestamp may include time and date information, and may be in conformance with the International Organization for Standardization (ISO) 8601 standard. API gateway device 170 may also cache timestamps so they may be provided to content provider device 160 at a later time. API gateway device 170 may then capture header information in request M502 (Block 515), which may include various metadata, including credentials associated with the content provider device 160, destination information, etc. API gateway device 170 may obtain a destination network address for a particular SDS resource device 180 (Block 525) The destination network address (e.g., a URI) may be determined by matching string patterns in the received request M502 using instructions found in mapping file 360 and network addresses corresponding to string patterns specified in configuration file 370. Once the destination network address is determined, API gateway device 170 may forward the request received from content provider device 160 to the particular SDS resource device 180 (M504). The SDS resource device 180 may process the request (Block 535), and then provide a response to the request back to API gateway device 170 (M506). The API gateway device 170 may capture header information in response M506 (Block 545). API gateway device 170 may then generate a timestamp T2 upon receiving the response M506 (Block 555). Once the timestamp T2 is generated, API gateway device 170 may forward the response to the request, along with both timestamps T1 and T2, to content provider device 160 (M508). Because timestamp T1 can be cached by API gateway device 170 after being generated in Block 505, the timestamps T1 and T2 may be both provided in a single message M508, thus improving efficiency. Server side plugin 320 may store timestamps T1 and T2 and determine a difference between the two timestamps to assist in subsequent billing associated with sponsored content provided by content provider device 160. FIG. 6 is a diagram depicting exemplary message flows 600 associated with granting an access token to content provider device 160 within the network environment 100. Initially, as a precondition, content provider device 160 may configure server side plugin (designated "SSP" in FIG. 6) 320 with credentials which are associated with content provider device 160 for a particular campaign (Block 605). The client credentials may be provided by SDS portal device 190 when the sponsor configures content provider device 160 for the campaign. The client credentials may include, for example a client identifier (ID) and/or a client secret assigned to content provider device 160 for the campaign. Once server side plugin 320 is properly configured, content provider device 160 may send an authentication request to API gateway device 170 (M602). The authentication request M602 may include the credentials (e.g., client ID and/or client secret). API gateway device 170 may generate a timestamp (T1) upon receiving the authentication request M602 (Block 615). API gateway device 170 may then determine that the destination for the authentication request M602 is authentication device 350 (Block 625). API gateway device 170 may determine the destination using mapping file 360 and configuration file 370 in a manner similar to that described above for Block 525 in FIG. 5. API gateway device 170 may forward the authentication request, along with the credentials for the content provider device 160 (e.g., client ID and/or client secret) to authentication device 350 (M604). Authentication device 350 may generate an access token based on the credentials for content provider device 160 (Block 635), and forward the access token back to API Gateway device 170 (M606). For subsequent transactions, the access token may be used for authentication and/or validation of content provider device 160 instead of the client credentials. Additionally, the access token may improve security by expiring after a fixed time duration. In an embodiment, API gateway device 170 may cache the access token to reduce traffic to authentication device 350 (Block 645). API gateway device 655 may generate another timestamp T2 upon receiving the access token (Block 655). API Gateway device 170 may the forward the access token, along with timestamps T1 and T2, to content provider device 160 (M606). FIG. 7 is a diagram depicting exemplary message flows 700 associated with authentication device 350 and STRM 340 in network environment 100. Initially, content provider device 160 may acquire the access token using credentials as described above in relation to FIG. 6 (Block 705, which refers to message flow 600). Content provider device 160 may then send a STRM call, which may include the access token, to API gateway device 170. API gateway device 170 may generate a timestamp T3 upon receiving STRM call M702, and then check an authentication header included in STRM call M702 (Block 715). If the authentication header is determined to be valid in Block 715, then API gateway device 170 may send a request to authentication device 350 to validate the access token (M704). Upon receiving request M704, authentication device 350 may validate the access token (Block 725). If the access token is valid, authentication device 350 may send a confirmation message indicating the access token is valid to API Gateway device 170 (M706). API gateway device 170 may then determine that the destination in STRM call M702 is STRM 340 (Block 735). API gateway device 170 may then forward the STRM call and validated access token, along with timestamp T3 determined in Block 715, to STRM 340 (M708). STRM 340 will record timestamp T3, and provide a STRM acknowledgement (ACK) back to API gateway device 170 (M710). API gateway device 170 may then generate another timestamp T4 corresponding to STRM ACK M740 (Block 745). API gateway device 170 may then send the STRM ACK, along with timestamp T3 and timestamp T4, back to content provider device 160 (M712). Alternatively, if the authentication header is determined to be valid by API gateway device 170 in Block 715, but the access token is determined to be invalid by authentication device 350 in Block 725, then authentication device 350 will provide an error message to API gateway device 170 (M714). API gateway device 170 will forward the error message to content provider device 160 (M716). In another case, if the authentication header is determined to be invalid by API gateway device 170 in block 715 (or the authentication header was not found in STRM call M702), then API gateway device 170 will provide an error message to content provider 160 (M718). FIG. 8 is a flow chart showing an exemplary process for facilitating secure access to an SDS through API gateway device 170. In an embodiment, process 800 may be performed at API gateway device 170, by processor 420 executing instructions stored in memory 430, mass storage device 440, and/or downloaded through communication interface 470. Initially, API gateway device 170 may provide an access token to content provider device 160, where the access token authorizes content provider device 160 to access resources to facilitate sponsored data services (SDS) (Block 805). API gateway device 170 may receive a request for an SDS resource from content provider device 160 (Block 810). API gateway device 170 may then generate a first timestamp associated with the request received from content provider 160 for the SDS resource (Block 815). API gateway device 170 may determine a destination for the request for the SDS resource, where the destination specifies a network address corresponding to a particular SDS resource device 180 (Block 820). API gateway device 170 may forward the request to the SDS resource device 180 based on the determined destination (Block 825). API gateway device 170 may receive a response from SDS resource device 180 corresponding to the first request (Block 830). API gateway device 170 may generate a second timestamp associated with the received response (Block 835). API gateway device 170 may forward the response, along with the first timestamp and the second timestamp, to content provider device 160. The timestamps allow content provider device 160 to facilitate security, and track sponsored content access and/or data consumption to properly bill sponsors and/or analyze sponsored data provided to the user via user device 105 in a "toll-free" manner. In the preceding specification, various preferred embodiments have been described with reference to the accompanying drawings. It will, however, be evident that various modifications and changes may be made thereto, and additional embodiments may be implemented, without departing from the broader scope of the invention as set forth in the claims that follow. The specification and drawings are accordingly to be regarded in an illustrative rather than restrictive sense. The foregoing description of implementations provides illustration and description, but is not intended to be exhaustive or to limit the invention to the precise form disclosed. Modifications and variations are possible in light of the above teachings or may be acquired from practice of the invention. For example, while series of messages and/or blocks have been described with regard to FIGS. 5-8, the order of the messages and/or blocks may be modified in other embodiments. Further, non-dependent messaging and/or processing blocks may be performed in parallel. Certain features described above may be implemented as "logic" or a "unit" that performs one or more functions. This logic or unit may include hardware, such as one or more processors, microprocessors, application specific integrated circuits, or field programmable gate arrays, software, or a combination of hardware and software. To the extent the aforementioned embodiments collect, store or employ personal information provided by individuals, it should be understood that such information shall be used in accordance with all applicable laws concerning protection of personal information. Additionally, the collection, storage and use of such information may be subject to consent of the individual to such activity, for example, through well known "opt-in" or "opt-out" processes as may be appropriate for the situation and type of information. Storage and use of personal information may be in an appropriately secure manner reflective of the type of information, for example, through various encryption and anonymization techniques for particularly sensitive information. The terms "comprises" and/or "comprising," as used herein specify the presence of stated features, integers, steps or components but does not preclude the presence or addition of one or more other features, integers, steps, components, or groups thereof. Further, the term "exemplary" (e.g., "exemplary embodiment," "exemplary configuration," etc.) means "as an example" and does not mean "preferred," "best," or likewise. No element, act, or instruction used in the description of the present application should be construed as critical or essential to the invention unless explicitly described as such. Also, as used herein, the article "a" is intended to include one or more items. Further, the phrase "based on" is intended to mean "based, at least in part, on" unless explicitly stated otherwise. * * * * * File A Patent Application • Protect your idea -- Don't let someone else file first. Learn more. • 3 Easy Steps -- Complete Form, application Review, and File. See our process. • Attorney Review -- Have your application reviewed by a Patent Attorney. See what's included.
__label__pos
0.522087
Chapters Hide chapters Kotlin Multiplatform by Tutorials First Edition · Android 12, iOS 15, Desktop · Kotlin 1.6.10 · Android Studio Bumblebee 8. Testing Written by Saeed Taheri Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text. Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan. Unlock now Here it comes — that phase in software development that makes you want to procrastinate, no matter how important you know it really is. Whether you like it or not, having a good set of tests — both automated and manual — ensures the quality of your software. When using Kotlin Multiplatform, you’ll have enough tools at your hand to write tests. So if you’re thinking of letting it slide this time, you’ll have to come up with another excuse. :] Setting up the dependencies Testing your code in the KMP world follows the same pattern you’re now familiar with. You test the code in the common module. You may also need to use the expect/actual mechanism as well. With this in mind, setting up the dependencies is structurally the same as it is with non-test code. From the starter project, open the build.gradle.kts inside the shared module. In the sourceSets block, add a block for commonTest source set after val commonMain by getting: val commonTest by getting { dependencies { implementation(kotlin("test-common")) implementation(kotlin("test-annotations-common")) } } You’re adding two modules from the kotlin.test library. This library provides annotations to mark test functions and a set of utility functions needed for assertions in tests — independent of the test framework you’re using. The -common in the name shows that you can use these inside your common multiplatform code. Do a Gradle sync. As you declared above, your test codes will be inside the commonTest folder. Create it as a sibling directory to commonMain by right-clicking the src folder inside the shared module and choosing New ▸ Directory. Once you start typing commonTest, Android Studio will provide you with autocompletion. Choose commonTest/kotlin. Fig. 8.1 - Create a new directory in Android Studio Fig. 8.1 - Create a new directory in Android Studio Fig. 8.2 - Android Studio suggests naming the test directory Fig. 8.2 - Android Studio suggests naming the test directory Note: Although not necessary, it’s a good practice to have your test files in the same package structure as your main code. If you want to do that, type commonTest/kotlin/com/raywenderlich/organize/presentation in the previous step, or create the nested directories manually afterward. Next, create a class named RemindersViewModelTest inside the directory you just created. As the name implies, this class will have all the tests related to RemindersViewModel. Now it’s time to create the very first test function for the app. Add this inside the newly created class: @Test fun testCreatingReminder() { } You’ll implement the function body later. The point to notice is the @Test annotation. It comes from the kotlin.test library you previously added as a dependency. Make sure to import the needed package at the top of the file if Android Studio didn’t do it automatically for you: import kotlin.test.Test. As soon as you add a function with @Test annotation to the class, Android Studio shows run buttons in the code gutter to make it easier for you to run the tests. Fig. 8.3 - Run button for tests in code gutter Fig. 8.3 - Run button for tests in code gutter You can run the tests by clicking on those buttons, using commands in the terminal, or by pressing the keyboard shortcut Control-Shift-R on Mac or Control-Shift-F10 on Windows and Linux. Fig. 8.4 - Choosing test platform Fig. 8.4 - Choosing test platform Choose android (:testDebugUnitTest) to run the test in Debug mode on Android. Congratulations! You ran your first test successfully…or did you? Fig. 8.5 - First test failed Fig. 8.5 - First test failed If you read the logs carefully, you’ll notice that the compiler was unable to resolve the references to Test. Here’s why this happened: As mentioned earlier, the kotlin.test library only provides the test annotations independently of the test library you’re using. When you ask the system to run the test on Android, it needs to find a test library on that platform to run your tests on. Since you hadn’t defined any test libraries for JVM targets, it couldn’t resolve the annotations, and the test failed. As a result, the next step would be to add test libraries to the app targets. Once again, open build.gradle.kts in the shared module. Inside sourceSets block, make sure to add these items: //1 val iosX64Test by getting val iosArm64Test by getting val iosSimulatorArm64Test by getting val iosTest by creating { dependsOn(commonTest) iosX64Test.dependsOn(this) iosArm64Test.dependsOn(this) iosSimulatorArm64Test.dependsOn(this) } //2 val androidTest by getting { dependencies { implementation(kotlin("test-junit")) implementation("junit:junit:4.13.2") } } //3 val desktopTest by getting { dependencies { implementation(kotlin("test-junit")) implementation("junit:junit:4.13.2") } } 1. You create a source set for the iOS platform named iosTest by combining the platform’s various architectures. iOS doesn’t need any specific dependencies for testing. The needed libraries are already there in the system. 2. For Android, you add a source set with dependencies to junit. This will make sure there’s a concrete implementation for provided annotations by kotlin.test library. 3. Since desktop uses JVM like Android does, you add the same set of dependencies as Android. Do a Gradle sync to download the dependencies. Now run the test again for Android. It’ll pass, and the system won’t throw any errors. Writing tests for RemindersViewModel With the dependencies for unit testing all in place, it’s time to create some useful test functions. private lateinit var viewModel: RemindersViewModel @BeforeTest fun setup() { viewModel = RemindersViewModel() } @Test fun testCreatingReminder() { //1 val title = "New Title" //2 viewModel.createReminder(title) //3 val count = viewModel.reminders.count { it.title == title } //4 assertTrue( actual = count == 1, message = "Reminder with title: $title wasn't created.", ) } internal val reminders: List<Reminder> get() = repository.reminders Fig. 8.6 - Choosing allTests from Gradle pane Zad. 5.8 - Njuivumd ivbZavch zpot Bpeslo fuva Fig. 8.7 - Successful test for creating a reminder Dol. 1.2 - Sakdumtret magr tur pyauwedx e kopuppak Writing tests for Platform All implementation details of the RemindersViewModel class was inside the commonMain source set. However, the Platform class is a bit different. As you remember, Platform uses the expect/actual mechanism. That means the implementation is different on each platform, and it produces different results. expect class PlatformTest { @Test fun testOperatingSystemName() } Android Create PlatformTest.kt inside the directories you created earlier in androidTest and update as follows: actual class PlatformTest { private val platform = Platform() @Test actual fun testOperatingSystemName() { assertEquals( expected = "Android", actual = platform.osName, message = "The OS name should be Android." ) } } iOS actual class PlatformTest { private val platform = Platform() @Test actual fun testOperatingSystemName() { assertTrue( actual = platform.osName.equals("iOS", ignoreCase = true) || platform.osName == "iPadOS", message = "The OS name should either be iOS or iPadOS." ) } } You check if the OS name is either iOS or iPadOS. Desktop actual class PlatformTest { private val platform = Platform() @Test actual fun testOperatingSystemName() { assertTrue( actual = platform.osName.contains("Mac", ignoreCase = true) || platform.osName.contains("Windows", ignoreCase = true) || platform.osName.contains("Linux", ignoreCase = true) || platform.osName == "Desktop", message = "Non-supported operating system" ) } } This is a bit difficult to test properly. For now, you can check if the reported OS name contains the app’s supported platforms. If not, let the test fail. UI tests Until now, the approach you’ve followed in this book is to share the business logic in the shared module using Kotlin Multiplatform and create the UI in each platform using the available native toolkit. Consequently, you’ve been able to share the tests for the business logic inside the shared module as well. Android You created the UI for Organize entirely using Jetpack Compose. Testing Compose layouts are different from testing a View-based UI. The View-based UI toolkit defines what properties a View has, such as the rectangle it’s occupying, its properties and so forth. In Compose, some composables may emit UI into the hierarchy. Hence, you need a new matching mechanism for UI elements. androidTestImplementation( "androidx.compose.ui:ui-test-junit4:${rootProject.extra["composeVersion"]}" ) debugImplementation( "androidx.compose.ui:ui-test-manifest:${rootProject.extra["composeVersion"]}" ) androidTestImplementation("androidx.fragment:fragment-testing:1.4.0") androidTestImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test:runner:1.4.0") testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" class AppUITest { @get:Rule val composeTestRule = createAndroidComposeRule<MainActivity>() } Semantics Semantics give meaning to a piece of UI — whether it’s a simple button or a whole set of composables. The semantics framework is primarily there for accessibility purposes. However, tests can take advantage of the information exposed by semantics about the UI hierarchy. IconButton( onClick = onAboutButtonClick, modifier = Modifier.semantics { contentDescription = "aboutButton" }, ) { Icon( imageVector = Icons.Outlined.Info, contentDescription = "About Device Button", ) } @Test fun testAboutButtonExistence() { composeTestRule .onNodeWithContentDescription("aboutButton") .assertIsDisplayed() } Fig. 8.8 - Successful test for about button existence Hac. 4.5 - Vugtofkver noyr rik oseon rurdok etuwhuvci @Test fun testOpeningAndClosingAboutPage() { //1 composeTestRule .onNodeWithContentDescription("aboutButton") .performClick() //2 composeTestRule .onNodeWithText("About Device") .assertIsDisplayed() //3 composeTestRule .onNodeWithContentDescription("Up Button") .performClick() //4 composeTestRule .onNodeWithText("Reminders") .assertIsDisplayed() } Desktop As the UI code for Android and desktop are essentially the same, the tests will be very similar. The setup is a bit different, though. The code is already there for you in the starter project. These are the differences you should consider: named("jvmTest") { dependencies { @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) implementation(compose.uiTestJUnit4) implementation(compose.desktop.currentOs) } } @Before fun setUp() { composeTestRule.setContent { var screenState by remember { mutableStateOf(Screen.Reminders) } when (screenState) { Screen.Reminders -> RemindersView( onAboutButtonClick = { screenState = Screen.AboutDevice } ) Screen.AboutDevice -> AboutView() } } } @Test fun testOpeningAboutPage() { //1 composeTestRule .onNodeWithText("Reminders") .assertExists() //2 composeTestRule .onNodeWithContentDescription("aboutButton") .performClick() //3 composeTestRule.waitForIdle() //4 composeTestRule .onNodeWithContentDescription("aboutView") .assertExists() } iOS To make the UI code testable in Xcode, you need to add a UI Test target to your project. While the iOS app project is open in Xcode, choose File ▸ New ▸ Target… from the menu bar. Fig. 8.9 - Xcode New Target Template Zid. 0.9 - Mgefa Got Huvliz Cacdqava Fig. 8.10 - Xcode UI Test Target files Saq. 0.88 - Lfuzo AI Qafj Kobfab fugab private let app = XCUIApplication() override func setUp() { continueAfterFailure = false app.launch() } func testAboutButtonExistence() { XCTAssert(app.buttons["About"].exists) } .accessibilityIdentifier("aboutButton") Button { shouldOpenAbout = true } label: { Label("About", systemImage: "info.circle") .labelStyle(.titleAndIcon) } .accessibilityIdentifier("aboutButton") .padding(8) .popover(isPresented: $shouldOpenAbout) { AboutView() .frame( idealWidth: 350, idealHeight: 450 ) } XCTAssert(app.buttons["aboutButton"].exists) Recording UI tests Xcode has a cool feature that you can take advantage of to make the process of creating UI tests easier. func testOpeningAndClosingAboutPage() { // Put the cursor here } Fig. 8.11 - Xcode UI Test Record button Pad. 0.94 - Ckosi EE Pujs Nekapw vepyas func testOpeningAndClosingAboutPage() { let app = XCUIApplication() app.toolbars["Toolbar"].buttons["aboutButton"].tap() app.navigationBars["About Device"].buttons["Done"].tap() } func testOpeningAndClosingAboutPage() { //1 app.buttons["aboutButton"].tap() //2 let aboutPageTitle = app.staticTexts["About Device"] XCTAssertTrue(aboutPageTitle.exists) //3 app.navigationBars["About Device"].buttons["Done"].tap() //4 let remindersPageTitle = app.staticTexts["Reminders"] XCTAssertTrue(remindersPageTitle.exists) } Fig. 8.12 - Xcode UI Test Success - Console Hin. 3.79 - Gxuqi EU Zevg Cofvirm - Tevrita Fig. 8.13 - Xcode UI Test Success - Gutter Yup. 3.29 - Dlino IU Nuyg Hirqevp - Qopkog Challenge Here is a challenge for you to see if you’ve got the idea. The solution is inside the materials for this chapter. Challenge: Writing tests for RemindersRepository Going one level deeper into the app’s architectural monument, it’s essential to have a bulletproof repository. After all, repositories are the backbone of the viewModels in Organize. Although it may seem effortless and similar to the viewModels for the time being, you’ll see how these tests will play a vital role when you connect a database to the repository as you move forward. Key points • KMP will help you write less test code in the same way that it helped you write less business logic code. • You can write tests for your common code as well as for platform-specific code — all in Kotlin. • Declaring dependencies to a testing library for each platform is necessary. KMP will run your tests via the provided environment — such as JUnit on JVM. • Using expect/actual mechanisms in test codes is possible. • For UI tests, you consult each platform’s provided solution: Jetpack Compose Tests for UIs created with Jetpack Compose and XCUITest for UIs created with UIKit or SwiftUI. Where to go from here? This chapter barely scratched the surface of testing. It didn’t talk about mocks and stubs, and it tried not to use third-party libraries, for that matter. There are a few libraries worth mentioning, though: Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here. © 2024 Kodeco Inc. You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan. Unlock now
__label__pos
0.700606
class TRootEmbeddedCanvas: public TGCanvas TRootEmbeddedCanvas This class creates a TGCanvas in which a TCanvas is created. Use GetCanvas() to get a pointer to the TCanvas. Function Members (Methods) public: TRootEmbeddedCanvas(const char* name = 0, const TGWindow* p = 0, UInt_t w = 10, UInt_t h = 10, UInt_t options = kSunkenFrame|kDoubleBorder, Pixel_t back = GetDefaultFrameBackground()) virtual~TRootEmbeddedCanvas() voidTObject::AbstractMethod(const char* method) const virtual voidTGFrame::Activate(Bool_t) virtual voidTGCanvas::AddFrame(TGFrame* f, TGLayoutHints* l = 0) voidTGFrame::AddInput(UInt_t emask) voidAdoptCanvas(TCanvas* c) virtual voidTObject::AppendPad(Option_t* option = "") static Bool_tTQObject::AreAllSignalsBlocked() Bool_tTQObject::AreSignalsBlocked() const static Bool_tTQObject::BlockAllSignals(Bool_t b) Bool_tTQObject::BlockSignals(Bool_t b) virtual voidTObject::Browse(TBrowser* b) virtual voidTGFrame::ChangeBackground(Pixel_t back) virtual voidTQObject::ChangedBy(const char* method)SIGNAL virtual voidTGFrame::ChangeOptions(UInt_t options) static TClass*Class() virtual const char*TObject::ClassName() const virtual voidTObject::Clear(Option_t* = "") virtual voidTGCanvas::ClearViewPort() virtual TObject*TObject::Clone(const char* newname = "") const voidTQObject::CollectClassSignalLists(TList& list, TClass* cls) virtual Int_tTObject::Compare(const TObject* obj) const Bool_tTQObject::Connect(const char* signal, const char* receiver_class, void* receiver, const char* slot) static Bool_tTQObject::Connect(TQObject* sender, const char* signal, const char* receiver_class, void* receiver, const char* slot) static Bool_tTQObject::Connect(const char* sender_class, const char* signal, const char* receiver_class, void* receiver, const char* slot) virtual voidTQObject::Connected(const char*) Bool_tTGFrame::Contains(Int_t x, Int_t y) const virtual voidTObject::Copy(TObject& object) const virtual voidTGFrame::Delete(Option_t* = "") virtual voidTGFrame::DeleteWindow() virtual voidTQObject::Destroyed()SIGNAL virtual voidTGWindow::DestroySubwindows() virtual voidTGWindow::DestroyWindow() Bool_tTQObject::Disconnect(const char* signal = 0, void* receiver = 0, const char* slot = 0) static Bool_tTQObject::Disconnect(TQObject* sender, const char* signal = 0, void* receiver = 0, const char* slot = 0) static Bool_tTQObject::Disconnect(const char* class_name, const char* signal, void* receiver = 0, const char* slot = 0) virtual voidTQObject::Disconnected(const char*) virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py) virtual voidTObject::Draw(Option_t* option = "") virtual voidTGCanvas::DrawBorder() virtual voidTGFrame::DrawClass() const virtual TObject*TGFrame::DrawClone(Option_t* = "") const virtual voidTGFrame::DrawCopy(Handle_t, Int_t, Int_t) virtual voidTGFrame::Dump() const voidTQObject::Emit(const char* signal) voidTQObject::Emit(const char* signal, Long_t* paramArr) voidTQObject::Emit(const char* signal, const char* params) voidTQObject::Emit(const char* signal, Double_t param) voidTQObject::Emit(const char* signal, Long_t param) voidTQObject::Emit(const char* signal, Long64_t param) voidTQObject::Emit(const char* signal, Bool_t param) voidTQObject::Emit(const char* signal, Char_t param) voidTQObject::Emit(const char* signal, UChar_t param) voidTQObject::Emit(const char* signal, Short_t param) voidTQObject::Emit(const char* signal, UShort_t param) voidTQObject::Emit(const char* signal, Int_t param) voidTQObject::Emit(const char* signal, UInt_t param) voidTQObject::Emit(const char* signal, ULong_t param) voidTQObject::Emit(const char* signal, ULong64_t param) voidTQObject::Emit(const char* signal, Float_t param) voidTQObject::EmitVA(const char* signal, Int_t nargs) voidTQObject::EmitVA(const char* signal, Int_t nargs, va_list va) virtual voidTObject::Error(const char* method, const char* msgfmt) const virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0) virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0) virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py) virtual voidTObject::Fatal(const char* method, const char* msgfmt) const virtual TObject*TObject::FindObject(const char* name) const virtual TObject*TObject::FindObject(const TObject* obj) const Bool_tGetAutoFit() const virtual Pixel_tTGFrame::GetBackground() const static const TGGC&TGFrame::GetBckgndGC() static const TGGC&TGFrame::GetBlackGC() static Pixel_tTGFrame::GetBlackPixel() Int_tTGFrame::GetBorderWidth() const TCanvas*GetCanvas() const Int_tGetCanvasWindowId() const TGClient*TGObject::GetClient() const TGFrame*TGCanvas::GetContainer() const static Int_tTGWindow::GetCounter() static Pixel_tTGFrame::GetDefaultFrameBackground() virtual UInt_tTGFrame::GetDefaultHeight() const static Pixel_tTGFrame::GetDefaultSelectedBackground() virtual TGDimensionTGCanvas::GetDefaultSize() const virtual UInt_tTGFrame::GetDefaultWidth() const virtual TDNDData*TGFrame::GetDNDData(Atom_t) virtual Int_tTGFrame::GetDragType() const virtual Option_t*TObject::GetDrawOption() const virtual Int_tTGFrame::GetDropType() const static Long_tTObject::GetDtorOnly() virtual UInt_tTGWindow::GetEditDisabled() const UInt_tTGFrame::GetEventMask() const virtual Pixel_tTGFrame::GetForeground() const TGFrameElement*TGFrame::GetFrameElement() const virtual TGFrame*TGFrame::GetFrameFromPoint(Int_t x, Int_t y) UInt_tTGFrame::GetHeight() const static const TGGC&TGFrame::GetHilightGC() virtual Int_tTGCanvas::GetHsbPosition() const TGHScrollBar*TGCanvas::GetHScrollbar() const virtual const char*TObject::GetIconName() const Handle_tTGObject::GetId() const TList*TQObject::GetListOfClassSignals() const TList*TQObject::GetListOfConnections() const TList*TQObject::GetListOfSignals() const virtual const TGWindow*TGWindow::GetMainFrame() const UInt_tTGFrame::GetMaxHeight() const UInt_tTGFrame::GetMaxWidth() const UInt_tTGFrame::GetMinHeight() const UInt_tTGFrame::GetMinWidth() const virtual const char*TGWindow::GetName() const virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const static Bool_tTObject::GetObjectStat() virtual Option_t*TObject::GetOption() const virtual UInt_tTGFrame::GetOptions() const const TGWindow*TGWindow::GetParent() const Int_tTGCanvas::GetScrolling() const static const TGGC&TGFrame::GetShadowGC() TGDimensionTGFrame::GetSize() const virtual const char*TObject::GetTitle() const virtual UInt_tTObject::GetUniqueID() const TGViewPort*TGCanvas::GetViewPort() const virtual Int_tTGCanvas::GetVsbPosition() const TGVScrollBar*TGCanvas::GetVScrollbar() const static const TGGC&TGFrame::GetWhiteGC() static Pixel_tTGFrame::GetWhitePixel() UInt_tTGFrame::GetWidth() const Int_tTGFrame::GetX() const Int_tTGFrame::GetY() const virtual Bool_tTGFrame::HandleButton(Event_t*) virtual Bool_tTGFrame::HandleClientMessage(Event_t* event) virtual Bool_tTGFrame::HandleColormapChange(Event_t*) virtual Bool_tTGFrame::HandleConfigureNotify(Event_t* event) virtual Bool_tTGFrame::HandleCrossing(Event_t*) virtual Bool_tHandleDNDDrop(TDNDData* data) virtual Atom_tHandleDNDEnter(Atom_t* typelist) virtual Bool_tTGFrame::HandleDNDFinished() virtual Bool_tHandleDNDLeave() virtual Atom_tHandleDNDPosition(Int_t, Int_t, Atom_t action, Int_t, Int_t) virtual Bool_tTGFrame::HandleDoubleClick(Event_t*) virtual Bool_tTGFrame::HandleDragDrop(TGFrame*, Int_t, Int_t, TGLayoutHints*) virtual Bool_tTGFrame::HandleDragEnter(TGFrame*) virtual Bool_tTGFrame::HandleDragLeave(TGFrame*) virtual Bool_tTGFrame::HandleDragMotion(TGFrame*) virtual Bool_tTGFrame::HandleEvent(Event_t* event) virtual Bool_tTGWindow::HandleExpose(Event_t* event) virtual Bool_tTGFrame::HandleFocusChange(Event_t*) virtual Bool_tTGWindow::HandleIdleEvent(TGIdleHandler*) virtual Bool_tTGFrame::HandleKey(Event_t*) virtual Bool_tTGFrame::HandleMotion(Event_t*) virtual Bool_tTGFrame::HandleSelection(Event_t*) virtual Bool_tTGFrame::HandleSelectionClear(Event_t*) virtual Bool_tTGFrame::HandleSelectionRequest(Event_t*) virtual Bool_tTGWindow::HandleTimer(TTimer*) virtual Bool_tTQObject::HasConnection(const char* signal_name) const virtual ULong_tTGObject::Hash() const virtual voidTQObject::HighPriority(const char* signal_name, const char* slot_name = 0) virtual voidTGWindow::IconifyWindow() virtual voidTObject::Info(const char* method, const char* msgfmt) const virtual Bool_tTObject::InheritsFrom(const char* classname) const virtual Bool_tTObject::InheritsFrom(const TClass* cl) const virtual voidTGFrame::Inspect() const voidTObject::InvertBit(UInt_t f) virtual TClass*IsA() const virtual Bool_tTGFrame::IsActive() const virtual Bool_tTGFrame::IsComposite() const Bool_tTGFrame::IsDNDSource() const Bool_tTGFrame::IsDNDTarget() const virtual Bool_tTGFrame::IsEditable() const virtual Bool_tTGObject::IsEqual(const TObject* obj) const virtual Bool_tTObject::IsFolder() const virtual Bool_tTGFrame::IsLayoutBroken() const virtual Bool_tTGWindow::IsMapped() virtual Bool_tTGWindow::IsMapSubwindows() const Bool_tTObject::IsOnHeap() const virtual Bool_tTObject::IsSortable() const Bool_tTObject::IsZombie() const virtual voidTGCanvas::Layout() static voidTQObject::LoadRQ_OBJECT() virtual voidTGWindow::LowerWindow() virtual voidTQObject::LowPriority(const char* signal_name, const char* slot_name = 0) virtual voidTObject::ls(Option_t* option = "") const virtual voidTGFrame::MapRaised() virtual voidTGCanvas::MapSubwindows() virtual voidTGFrame::MapWindow() voidTObject::MayNotUse(const char* method) const virtual voidTQObject::Message(const char* msg)SIGNAL virtual voidTGFrame::Move(Int_t x, Int_t y) virtual voidTGFrame::MoveResize(Int_t x, Int_t y, UInt_t w = 0, UInt_t h = 0) virtual Int_tTGWindow::MustCleanup() const virtual Bool_tTObject::Notify() virtual Int_tTQObject::NumberOfConnections() const virtual Int_tTQObject::NumberOfSignals() const static voidTObject::operator delete(void* ptr) static voidTObject::operator delete(void* ptr, void* vp) static voidTObject::operator delete[](void* ptr) static voidTObject::operator delete[](void* ptr, void* vp) void*TObject::operator new(size_t sz) void*TObject::operator new(size_t sz, void* vp) void*TObject::operator new[](size_t sz) void*TObject::operator new[](size_t sz, void* vp) virtual voidTObject::Paint(Option_t* option = "") virtual voidTObject::Pop() virtual voidTGFrame::Print(Option_t* option = "") const virtual voidTGFrame::ProcessedEvent(Event_t* event)SIGNAL virtual Bool_tTGCanvas::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2) virtual voidTGWindow::RaiseWindow() virtual Int_tTObject::Read(const char* name) virtual voidTGFrame::ReallyDelete() virtual voidTObject::RecursiveRemove(TObject* obj) voidTGFrame::RemoveInput(UInt_t emask) virtual voidTGFrame::ReparentWindow(const TGWindow* p, Int_t x = 0, Int_t y = 0) virtual voidTGWindow::RequestFocus() voidTObject::ResetBit(UInt_t f) virtual voidTGFrame::Resize(TGDimension size) virtual voidTGFrame::Resize(UInt_t w = 0, UInt_t h = 0) virtual voidTGObject::SaveAs(const char* filename = "", Option_t* option = "") const virtual voidSavePrimitive(ostream& out, Option_t* option = "") voidTGFrame::SaveUserColor(ostream& out, Option_t*) virtual voidTGFrame::SendMessage(const TGWindow* w, Long_t msg, Long_t parm1, Long_t parm2) voidSetAutoFit(Bool_t fit = kTRUE) virtual voidTGFrame::SetBackgroundColor(Pixel_t back) virtual voidTGWindow::SetBackgroundPixmap(Pixmap_t pixmap) voidTObject::SetBit(UInt_t f) voidTObject::SetBit(UInt_t f, Bool_t set) virtual voidTGFrame::SetCleanup(Int_t = kLocalCleanup) virtual voidTGCanvas::SetContainer(TGFrame* f) voidTGFrame::SetDNDSource(Bool_t onoff) voidTGFrame::SetDNDTarget(Bool_t onoff) virtual voidTGFrame::SetDragType(Int_t type) virtual voidTGFrame::SetDrawOption(Option_t* = "") virtual voidTGFrame::SetDropType(Int_t type) static voidTObject::SetDtorOnly(void* obj) virtual voidTGFrame::SetEditable(Bool_t) virtual voidTGWindow::SetEditDisabled(UInt_t on = kEditDisable) virtual voidTGFrame::SetForegroundColor(Pixel_t) voidTGFrame::SetFrameElement(TGFrameElement* fe) virtual voidTGFrame::SetHeight(UInt_t h) virtual voidTGCanvas::SetHsbPosition(Int_t newPos) virtual voidTGFrame::SetLayoutBroken(Bool_t = kTRUE) virtual voidTGWindow::SetMapSubwindows(Bool_t) virtual voidTGFrame::SetMaxHeight(UInt_t h) virtual voidTGFrame::SetMaxWidth(UInt_t w) virtual voidTGFrame::SetMinHeight(UInt_t h) virtual voidTGFrame::SetMinWidth(UInt_t w) virtual voidTGWindow::SetName(const char* name) static voidTObject::SetObjectStat(Bool_t stat) voidTGCanvas::SetScrolling(Int_t scrolling) virtual voidTGFrame::SetSize(const TGDimension& s) virtual voidTObject::SetUniqueID(UInt_t uid) virtual voidTGCanvas::SetVsbPosition(Int_t newPos) virtual voidTGFrame::SetWidth(UInt_t w) virtual voidTGWindow::SetWindowName(const char* name = 0) virtual voidTGFrame::SetX(Int_t x) virtual voidTGFrame::SetY(Int_t y) virtual voidShowMembers(TMemberInspector& insp, char* parent) virtual voidStreamer(TBuffer& b) voidStreamerNVirtual(TBuffer& b) virtual voidTObject::SysError(const char* method, const char* msgfmt) const Bool_tTObject::TestBit(UInt_t f) const Int_tTObject::TestBits(UInt_t f) const virtual voidTGFrame::UnmapWindow() virtual voidTObject::UseCurrentStyle() virtual voidTObject::Warning(const char* method, const char* msgfmt) const virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const protected: static Int_tTQObject::CheckConnectArgs(TQObject* sender, TClass* sender_class, const char* signal, TClass* receiver_class, const char* slot) static Bool_tTQObject::ConnectToClass(TQObject* sender, const char* signal, TClass* receiver_class, void* receiver, const char* slot) static Bool_tTQObject::ConnectToClass(const char* sender_class, const char* signal, TClass* receiver_class, void* receiver, const char* slot) virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const virtual voidTGFrame::DoRedraw() virtual voidTGFrame::Draw3dRectangle(UInt_t type, Int_t x, Int_t y, UInt_t w, UInt_t h) static Time_tTGFrame::GetLastClick() TStringTGFrame::GetOptionString() const const TGResourcePool*TGFrame::GetResourcePool() const virtual void*TGFrame::GetSender() virtual const char*TQObject::GetSenderClassName() const virtual Bool_tHandleContainerButton(Event_t* ev) virtual Bool_tHandleContainerConfigure(Event_t* ev) virtual Bool_tHandleContainerCrossing(Event_t* ev) virtual Bool_tHandleContainerDoubleClick(Event_t* ev) virtual Bool_tHandleContainerExpose(Event_t* ev) virtual Bool_tHandleContainerKey(Event_t* ev) virtual Bool_tHandleContainerMotion(Event_t* ev) voidTObject::MakeZombie() virtual voidTGFrame::StartGuiBuilding(Bool_t on = kTRUE) private: TRootEmbeddedCanvas(const TRootEmbeddedCanvas&) TRootEmbeddedCanvas&operator=(const TRootEmbeddedCanvas&) Data Members public: enum TGCanvas::[unnamed] { kCanvasNoScroll kCanvasScrollHorizontal kCanvasScrollVertical kCanvasScrollBoth }; enum TGFrame::[unnamed] { kDeleteWindowCalled }; enum TGWindow::EEditMode { kEditEnable kEditDisable kEditDisableEvents kEditDisableGrab kEditDisableLayout kEditDisableResize kEditDisableHeight kEditDisableWidth kEditDisableBtnEnable kEditDisableKeyEnable }; enum TObject::EStatusBits { kCanDelete kMustCleanup kObjInCanvas kIsReferenced kHasUUID kCannotPick kNoContextMenu kInvalidObject }; enum TObject::[unnamed] { kIsOnHeap kNotDeleted kZombie kBitMask kSingleKey kOverwrite kWriteDelete }; protected: Bool_tfAutoFitcanvas container keeps same size as canvas Pixel_tTGFrame::fBackgroundframe background color Int_tTGFrame::fBorderWidthframe border width Int_tfButtoncurrently pressed button Int_tfCWinIdwindow id used by embedded TCanvas TCanvas*fCanvaspointer to TCanvas TRootEmbeddedContainer*fCanvasContainercontainer in canvas widget TGClient*TGObject::fClientConnection to display server Int_tTGFrame::fDNDStateEDNDFlags Atom_t*fDNDTypeListhandles DND types UInt_tTGWindow::fEditDisabledflags used for "guibuilding" UInt_tTGFrame::fEventMaskcurrenty active event mask TGFrameElement*TGFrame::fFEpointer to frame element TGHScrollBar*TGCanvas::fHScrollbarhorizontal scrollbar UInt_tTGFrame::fHeightframe height Handle_tTGObject::fIdX11/Win32 Window identifier TList*TQObject::fListOfConnections! list of connections to this object TList*TQObject::fListOfSignals! list of signals from this object UInt_tTGFrame::fMaxHeightmaximal frame height UInt_tTGFrame::fMaxWidthmaximal frame width UInt_tTGFrame::fMinHeightminimal frame height UInt_tTGFrame::fMinWidthminimal frame width TStringTGWindow::fNamename of the window used in SavePrimitive() Bool_tTGWindow::fNeedRedrawkTRUE if window needs to be redrawn UInt_tTGFrame::fOptionsframe options const TGWindow*TGWindow::fParentParent window Int_tTGCanvas::fScrollingflag which scrolling modes are allowed Bool_tTQObject::fSignalsBlocked! flag used for suppression of signals TGVScrollBar*TGCanvas::fVScrollbarvertical scrollbar TGViewPort*TGCanvas::fVportviewport through which we look at contents UInt_tTGFrame::fWidthframe width Int_tTGFrame::fXframe x position Int_tTGFrame::fYframe y position static Bool_tTQObject::fgAllSignalsBlockedflag used for suppression of all signals static const TGGC*TGFrame::fgBckgndGC static const TGGC*TGFrame::fgBlackGC static Pixel_tTGFrame::fgBlackPixel static Int_tTGWindow::fgCountercounter of created windows in SavePrimitive static Window_tTGFrame::fgDbw static Int_tTGFrame::fgDbx static Int_tTGFrame::fgDby static Pixel_tTGFrame::fgDefaultFrameBackground static Pixel_tTGFrame::fgDefaultSelectedBackground static const TGGC*TGFrame::fgHilightGC static Bool_tTGFrame::fgInit static UInt_tTGFrame::fgLastButton static Time_tTGFrame::fgLastClick static const TGGC*TGFrame::fgShadowGC static UInt_tTGFrame::fgUserColor static const TGGC*TGFrame::fgWhiteGC static Pixel_tTGFrame::fgWhitePixel Class Charts Inheritance Inherited Members Includes Libraries Class Charts Function documentation TRootEmbeddedCanvas(const char* name = 0, const TGWindow* p = 0, UInt_t w = 10, UInt_t h = 10, UInt_t options = kSunkenFrame|kDoubleBorder, Pixel_t back = GetDefaultFrameBackground()) Create an TCanvas embedded in a TGFrame. A pointer to the TCanvas can be obtained via the GetCanvas() member function. To embed a canvas derived from a TCanvas do the following: TRootEmbeddedCanvas *embedded = new TRootEmbeddedCanvas(0, p, w, h); [note name must be 0, not null string ""] Int_t wid = embedded->GetCanvasWindowId(); TMyCanvas *myc = new TMyCanvas("myname", 10, 10, wid); embedded->AdoptCanvas(myc); [ the MyCanvas is adopted by the embedded canvas and will be destroyed by it ] ~TRootEmbeddedCanvas() Delete embedded ROOT canvas. void AdoptCanvas(TCanvas* c) Canvas c is adopted from this embedded canvas. Bool_t HandleContainerButton(Event_t* ev) Handle mouse button events in the canvas container. Bool_t HandleContainerDoubleClick(Event_t* ev) Handle mouse button double click events in the canvas container. Bool_t HandleContainerConfigure(Event_t* ev) Handle configure (i.e. resize) event. Bool_t HandleContainerKey(Event_t* ev) Handle keyboard events in the canvas container. Bool_t HandleContainerMotion(Event_t* ev) Handle mouse motion event in the canvas container. Bool_t HandleContainerExpose(Event_t* ev) Handle expose events. Bool_t HandleContainerCrossing(Event_t* ev) Handle enter/leave events. Only leave is activated at the moment. Bool_t HandleDNDDrop(TDNDData* data) Handle drop events. Atom_t HandleDNDPosition(Int_t , Int_t , Atom_t action, Int_t , Int_t ) Handle dragging position events. Atom_t HandleDNDEnter(Atom_t* typelist) Handle drag enter events. Bool_t HandleDNDLeave() Handle drag leave events. void SavePrimitive(ostream& out, Option_t* option = "") Save an embedded canvas as a C++ statement(s) on output stream out. TRootEmbeddedCanvas(const TRootEmbeddedCanvas& ) TRootEmbeddedCanvas& operator=(const TRootEmbeddedCanvas& ) TCanvas * GetCanvas() { return fCanvas; } Int_t GetCanvasWindowId() { return fCWinId; } Bool_t GetAutoFit() { return fAutoFit; } void SetAutoFit(Bool_t fit = kTRUE) { fAutoFit = fit; } Author: Fons Rademakers 15/07/98 Last change: root/gui:$Id: TRootEmbeddedCanvas.h 23115 2008-04-10 13:35:37Z rdm $ Last generated: 2008-06-25 08:52 Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.
__label__pos
0.933511
Spotify not downloading in the background Reply Spotify not downloading in the background dorian2786 Casual Listener I noticed that downloading stops when spotify runs in the background. Is this normal? 3 Replies Re: Spotify not downloading in the background Schalch Newbie Unfortunately for iOS this is normal. The device must be unlocked and spotify must be on screen, furthermore, two minutes of inactivity will pause the downloads. Re: Spotify not downloading in the background dorian2786 Casual Listener So just so I'm clear, the app cannot be in the background with the phone unlocked or no? Highlighted Re: Spotify not downloading in the background max_lobur Casual Listener It can. Anything that is not opened right now on the screen is in a background and paused. That's how iOS works days on a single charge SUGGESTED POSTS
__label__pos
0.708179
PPM Financial Planning – Update FIN_PLAN Values using API: How-to guide In the picture: PPM > Portfolio Management > Financial Planning My project had a requirement to add up actual values(actual and actual-manual) and copy to forecast values in the Financial Planning of the PPM Module. Even though this sounds very simple, anyone who knows PPM tables knows that it is more than what meets the eye. I struggled a lot to find an apt way of achieving this. I tried many other processes like Function Module(FM) /RPM/FIN_PLAN_SAVE_DB. The problem with this FM was that all entries in the plan table belonging to a group had to be passed to this FM even when we had to update just one record in that group. I also explored the BADIs /RPM/EX_FIN_B_PLAN_BADI, /RPM/EX_FIN_PLAN, /RPM/FIN_CAP_PLAN . But I wanted something that can be called within in an FM which updates the /RPM/FIN_PLAN table with plan details. Finally while debugging I stumbled upon the API /rpm/cl_fin_cap_planning_api. This API was best suited for my requirement as I only had to pass the changed entry and it internally selects the rest of the plan entries in the group. I spent a lot of researching how to make use of this API specially to know how to pass the context to the API. I am writing this blog post to help my fellow developers. The steps described in this blog post can also be used to update Capacity Planning tables. Requirement: There are 2 views to capture actual cost – Actual(comes from ECC) and Actual-Manual(entered manually). The requirement is that the Forecast view should be calculated by adding the two costs – Actual and Actual-Manual. Even though this sounds very simple, anyone who knows PPM tables knows that it is more than what meets the eye. After doing lot of research and debugging, I found out that the there is an API /rpm/cl_fin_cap_planning_api to do this. I have created an RFC Function Module that takes 1/more external-ID of the item(project) as input and updates the tables(/RPM/FIN_PLAN,  /RPM/FIN_GROUP) and in turn views of the Forecast. This blog post is a step-by-step how-to guide to achieve this objective. Steps: 1. Get guid from table /RPM/ITEM_D for the external_id in the input table(IT_PROJ) 2. Get required fields into 1 table using join from /rpm/item_d /rpm/fin_cat, /rpm/fin_group /rpm/fin_plan 3. Add the values of actual and actual-manual costs of corresponding months and categories 4. Update the forecast costs using API. Use get_plan_info method to pass the context**. Call initialize_planning method and finally fin_groups_modify  to update values. The API is well designed in the sense that only the changed fin_plan entries need to be passed and the API handles the rest. ** very crucial part..took me a while to figure out how to pass the context 1. Very important to call the cl_inm_ppm_services=>save to commit work. 2. Capture the messages and display. FM Interface: FUNCTION z_forecast_calculate_rfc . TYPES: BEGIN OF type_item_d, guid TYPE /rpm/tv_guid, external_id TYPE /rpm/tv_extid, portfolio_guid TYPE /rpm/tv_guid, END OF type_item_d, BEGIN OF type_fin_planf, guid TYPE rpm_tv_guid, period TYPE /rpm/tv_start_date, amount(16) TYPE p DECIMALS 2, END OF type_fin_planf , BEGIN OF type_fin_plan_tmp, guid TYPE rpm_tv_guid, plan_type TYPE /rpm/tv_fin_view, period TYPE /rpm/tv_start_date, amount(16) TYPE p DECIMALS 2, END OF type_fin_plan_tmp , BEGIN OF type_fin_plan, guid TYPE rpm_tv_guid, period TYPE /rpm/tv_start_date, amount(16) TYPE p DECIMALS 2, END OF type_fin_plan, BEGIN OF type_itemcatgrp, guid TYPE /rpm/tv_guid, external_id TYPE /rpm/tv_extid, portfolio_guid TYPE /rpm/tv_guid, guid_c TYPE /rpm/tv_guid, category TYPE /rpm/tv_cap_catg, guid_g TYPE rpm_tv_guid, group_id TYPE rpm_tv_extid, sponsor TYPE /rpm/tv_sponsor, parent_guid TYPE rpm_tv_guid, changed_by TYPE /rpm/tv_changed_by, changed_on TYPE /rpm/tv_timestamp, active TYPE /rpm/tv_active, original TYPE /rpm/tv_original, END OF type_itemcatgrp, BEGIN OF type_fin_plan_full, guid TYPE rpm_tv_guid, plan_type TYPE /rpm/tv_fin_view, period TYPE /rpm/tv_start_date, changed_on TYPE /rpm/tv_timestamp, amount TYPE /rpm/tv_curr_amount, currency TYPE /rpm/tv_currency, END OF type_fin_plan_full , BEGIN OF type_grpplan_full, guid TYPE /rpm/tv_guid, external_id TYPE /rpm/tv_extid, portfolio_guid TYPE /rpm/tv_guid, guid_c TYPE /rpm/tv_guid, category TYPE /rpm/tv_cap_catg, guid_g TYPE rpm_tv_guid, group_id TYPE rpm_tv_extid, sponsor TYPE /rpm/tv_sponsor, parent_guid TYPE rpm_tv_guid, active TYPE /rpm/tv_active, original TYPE /rpm/tv_original, guid_p TYPE rpm_tv_guid, plan_type TYPE /rpm/tv_fin_view, period TYPE /rpm/tv_start_date, changed_on TYPE /rpm/tv_timestamp, amount TYPE /rpm/tv_curr_amount, currency TYPE /rpm/tv_currency, END OF type_grpplan_full . "internal tables DATA: t_item_d TYPE TABLE OF type_item_d, t_fin_plan_coll TYPE HASHED TABLE OF type_fin_plan WITH UNIQUE KEY guid period, t_fin_plan_full73 TYPE TABLE OF type_fin_plan_full, t_fin_plan_api TYPE /rpm/tt_plan_api, t_fin_group_api TYPE /rpm/tt_fin_group_api, t_fin_plan TYPE TABLE OF type_fin_plan, t_date_range TYPE TABLE OF rsdatrange, t_int_range TYPE TABLE OF rsintrange, t_msgs TYPE /rpm/tt_messages, t_msgs_group TYPE /rpm/tt_messages, t_msgs_item TYPE /rpm/tt_messages, t_grp_plan TYPE TABLE OF type_grpplan_full, t_itemcatgrp TYPE TABLE OF type_itemcatgrp, t_filter_data TYPE /rpm/tt_filter_data_api, t_grpplan_full TYPE TABLE OF type_grpplan_full, t_fin_plan_tmp TYPE TABLE OF type_fin_plan_tmp, "work areas w_fin_plan TYPE type_fin_plan, w_fin_plan_tmp TYPE type_fin_plan_tmp, w_fin_plan_api TYPE /rpm/ts_plan_api, w_fin_group_api TYPE /rpm/ts_fin_group_api, w_grp_plan TYPE type_grpplan_full, w_grp_plan_temp TYPE type_grpplan_full, w_item_d TYPE type_item_d, w_date_range TYPE rsdatrange, w_fin_plan_full73 TYPE type_fin_plan_full, w_fin_plan_coll LIKE LINE OF t_fin_plan_coll, w_context TYPE /rpm/ts_object_hier, w_plan_info TYPE /rpm/ts_plan_info, "range table r_item TYPE RANGE OF /rpm/tv_guid, w_item LIKE LINE OF r_item, "variables v_cat_guid TYPE /rpm/tv_guid, v_subrc TYPE i ##needed, v_high_date TYPE sydatum, v_73 TYPE /rpm/tv_curr_amount, v_coll TYPE /rpm/tv_curr_amount, v_updated TYPE boolean, v_rejected TYPE boole_d ##needed. "constants CONSTANTS: c_hierarchy_type TYPE /rpm/tv_hier_type VALUE 'VCG', c_language TYPE laiso VALUE 'EN', c_parent_type TYPE /rpm/object_type VALUE 'RIH', c_object_type TYPE /rpm/object_type VALUE 'RIH', c_plantype_73 TYPE /rpm/tv_fin_view VALUE '73', c_plantype_75 TYPE /rpm/tv_fin_view VALUE '75', c_plantype_77 TYPE /rpm/tv_fin_view VALUE '77', c_cat_i05 TYPE /rpm/tv_cap_catg VALUE 'IT_I05', c_cat_i10 TYPE /rpm/tv_cap_catg VALUE 'IT_I10', c_fin_cap TYPE /rpm/tv_fin_cap VALUE '1', c_pipe(1) TYPE c VALUE '|', c_msgtype_s TYPE symsgty VALUE 'S', c_zit_bau TYPE /rpm/tv_item_id VALUE 'IT_BAU', c_zit_inf TYPE /rpm/tv_item_id VALUE 'IT_INF', c_zit_opm TYPE /rpm/tv_item_id VALUE 'IT_OPM', c_zit_sap TYPE /rpm/tv_item_id VALUE 'IT_SAP', c_sts_zf02 TYPE /rpm/tv_status_common VALUE 'F02', c_unit TYPE meins VALUE 'H'. "reference(s) DATA: lo_fin_cap_planning_api TYPE REF TO /rpm/cl_fin_cap_planning_api. "field-symbols FIELD-SYMBOLS: <fs_fin_plan> TYPE type_fin_planf, <fs_msg> TYPE /rpm/ts_messages. "select only IT projects in the selection IF it_proj[] IS NOT INITIAL. SELECT guid external_id portfolio_guid FROM /rpm/item_d INTO TABLE t_item_d FOR ALL ENTRIES IN it_proj WHERE external_id = it_proj-extid AND ( item_type = c_zit_bau OR item_type = c_zit_inf OR item_type = c_zit_opm OR item_type = c_zit_sap ). IF sy-subrc <> 0. CLEAR t_item_d[]. ENDIF. ENDIF. "create range table for guid LOOP AT t_item_d INTO w_item_d. CLEAR w_item. w_item-low = w_item_d-guid. w_item-sign = 'I'. w_item-option = 'EQ'. APPEND w_item TO r_item. CLEAR w_item. ENDLOOP. "join cat and group tables IF t_item_d[] IS NOT INITIAL. SELECT i~guid i~external_id i~portfolio_guid c~guid c~category g~guid g~group_id g~sponsor g~parent_guid g~changed_by g~changed_on g~active g~original INTO TABLE t_itemcatgrp FROM /rpm/item_d AS i INNER JOIN /rpm/fin_cat AS c ON i~guid = c~parent_guid INNER JOIN /rpm/fin_group AS g ON c~guid = g~parent_guid FOR ALL ENTRIES IN it_proj WHERE i~external_id = it_proj-extid AND ( c~category = c_cat_i05 OR c~category = c_cat_i10 ) AND c~active = abap_true AND g~active = abap_true. IF sy-subrc <> 0. CLEAR t_itemcatgrp[]. ENDIF. ENDIF. SORT t_itemcatgrp[] BY guid external_id portfolio_guid guid_c category guid_g group_id sponsor parent_guid. "get first day of the previous month CALL FUNCTION 'RS_VARI_V_LAST_MONTH' TABLES p_datetab = t_date_range p_intrange = t_int_range. CLEAR w_date_range. READ TABLE t_date_range INTO w_date_range INDEX 1. IF sy-subrc = 0. CLEAR v_high_date. v_high_date = w_date_range-high. ENDIF. "get group and plan details in 1 table- existing data SELECT i~guid i~external_id i~portfolio_guid c~guid c~category g~guid g~group_id g~sponsor g~parent_guid g~active g~original p~guid p~plan_type p~period p~changed_on p~amount p~currency INTO TABLE t_grp_plan FROM /rpm/item_d AS i INNER JOIN /rpm/fin_cat AS c ON i~guid = c~parent_guid INNER JOIN /rpm/fin_group AS g ON c~guid = g~parent_guid INNER JOIN /rpm/fin_plan AS p ON g~guid = p~guid WHERE i~guid IN r_item AND ( c~category = c_cat_i05 OR c~category = c_cat_i10 ) AND c~active = abap_true AND g~active = abap_true AND ( p~plan_type = c_plantype_75 OR p~plan_type = c_plantype_77 OR p~plan_type = c_plantype_73 ) AND period <= v_high_date. IF sy-subrc <> 0. CLEAR t_grp_plan[]. ENDIF. IF t_itemcatgrp[] IS NOT INITIAL. "get plan SELECT guid plan_type period amount FROM /rpm/fin_plan INTO TABLE t_fin_plan_tmp FOR ALL ENTRIES IN t_itemcatgrp WHERE guid = t_itemcatgrp-guid_g AND ( plan_type = c_plantype_75 OR plan_type = c_plantype_77 ) AND period <= v_high_date. IF sy-subrc <> 0. CLEAR t_fin_plan_tmp[]. ENDIF. ENDIF. SORT t_fin_plan_tmp[] BY guid plan_type period. LOOP AT t_fin_plan_tmp INTO w_fin_plan_tmp. CLEAR w_fin_plan. w_fin_plan-guid = w_fin_plan_tmp-guid. w_fin_plan-period = w_fin_plan_tmp-period. w_fin_plan-amount = w_fin_plan_tmp-amount. APPEND w_fin_plan TO t_fin_plan. CLEAR w_fin_plan. ENDLOOP. SORT t_fin_plan[] BY guid period. "add actual and actual-manual values LOOP AT t_fin_plan ASSIGNING <fs_fin_plan>. COLLECT <fs_fin_plan> INTO t_fin_plan_coll. ENDLOOP. UNASSIGN <fs_fin_plan>. "get all fields to pass to API IF t_fin_plan_coll[] IS NOT INITIAL. SELECT i~guid i~external_id i~portfolio_guid c~guid c~category g~guid g~group_id g~sponsor g~parent_guid g~active g~original p~guid p~plan_type p~period p~changed_on p~amount p~currency INTO TABLE t_grpplan_full FROM /rpm/item_d AS i INNER JOIN /rpm/fin_cat AS c ON i~guid = c~parent_guid INNER JOIN /rpm/fin_group AS g ON c~guid = g~parent_guid INNER JOIN /rpm/fin_plan AS p ON g~guid = p~guid FOR ALL ENTRIES IN t_fin_plan_coll WHERE i~guid IN r_item AND ( c~category = c_cat_i05 OR c~category = c_cat_i10 ) AND c~active = abap_true AND g~active = abap_true AND p~guid = t_fin_plan_coll-guid AND ( p~plan_type = c_plantype_75 OR p~plan_type = c_plantype_77 ) AND p~period = t_fin_plan_coll-period. IF sy-subrc <> 0. CLEAR t_grpplan_full[]. ENDIF. "get all 73 SELECT guid plan_type period changed_on amount currency FROM /rpm/fin_plan INTO TABLE t_fin_plan_full73 FOR ALL ENTRIES IN t_fin_plan_coll WHERE guid = t_fin_plan_coll-guid AND plan_type = c_plantype_73 AND period = t_fin_plan_coll-period. IF sy-subrc <> 0. CLEAR t_fin_plan_full73[]. ENDIF. ENDIF. SORT t_grpplan_full[] BY guid external_id portfolio_guid guid_c category guid_g group_id sponsor parent_guid active original guid_p period. DELETE ADJACENT DUPLICATES FROM t_grpplan_full COMPARING guid external_id portfolio_guid guid_c category guid_g group_id sponsor parent_guid active original guid_p period. "get api reference CALL METHOD /rpm/cl_fin_cap_planning_api=>get_instance RECEIVING rr_instance = lo_fin_cap_planning_api. IF lo_fin_cap_planning_api IS BOUND. "loop projects LOOP AT t_item_d INTO w_item_d. CLEAR: t_fin_group_api[], t_fin_plan_api. "populate context CLEAR w_context. w_context-portfolio_guid = w_item_d-portfolio_guid. w_context-parent_type = c_parent_type. "'RIH'. w_context-parent_guid = w_item_d-guid. w_context-object_type = c_object_type."'RIH'. w_context-object_guid = w_item_d-guid. "get plan info CLEAR: v_subrc, w_plan_info. CALL METHOD lo_fin_cap_planning_api->get_plan_info EXPORTING is_context = w_context * iv_language = iv_fin_cap = c_fin_cap "1 IMPORTING es_plan_info = w_plan_info et_msgs = t_msgs[] ev_rc = v_subrc. APPEND LINES OF t_msgs TO t_msgs_item. CLEAR t_msgs[]. "pass context CALL METHOD lo_fin_cap_planning_api->initialize_planning EXPORTING is_context = w_context iv_hierarchy_type = c_hierarchy_type iv_fin_cap = c_fin_cap "1 * iv_language = it_filter_data = t_filter_data[] is_plan_info = w_plan_info * iv_portfolio_type = IMPORTING et_msgs = t_msgs[] * es_mode = * . APPEND LINES OF t_msgs TO t_msgs_item. CLEAR t_msgs[]. "append project UNASSIGN <fs_msg>. LOOP AT t_msgs_item ASSIGNING <fs_msg> WHERE msgtype <> c_msgtype_s."'S'."non-success msgs only <fs_msg>-objectid = w_item_d-external_id. APPEND <fs_msg> TO et_msgs. ENDLOOP. UNASSIGN <fs_msg>. CLEAR t_msgs_item[]. "this is to eliminate duplicate 75/77/73 entries SORT t_grp_plan[] BY guid external_id portfolio_guid guid_c category guid_g group_id sponsor parent_guid active original guid_p period . DELETE ADJACENT DUPLICATES FROM t_grp_plan COMPARING guid external_id portfolio_guid guid_c category guid_g group_id sponsor parent_guid active original guid_p period . "this is for overwriting existing 73 entries CLEAR: t_fin_group_api[], t_fin_plan_api[]. LOOP AT t_grp_plan INTO w_grp_plan_temp WHERE guid = w_item_d-guid ##loop_at_ok. "separate group and plan based on guid CLEAR w_grp_plan. w_grp_plan = w_grp_plan_temp. "grp AT NEW guid_g. CLEAR v_cat_guid. v_cat_guid = w_grp_plan-guid_c. CLEAR w_fin_group_api. w_fin_group_api-guid = w_grp_plan-guid_g. w_fin_group_api-external_id = w_grp_plan-group_id. w_fin_group_api-sponsor = w_grp_plan-sponsor. w_fin_group_api-parent_guid = w_grp_plan-parent_guid. w_fin_group_api-changed_by = sy-uname. w_fin_group_api-active = w_grp_plan-active. w_fin_group_api-original = w_grp_plan-original. APPEND w_fin_group_api TO t_fin_group_api. ENDAT. "plan "dont append if already present CLEAR w_fin_plan_api. READ TABLE t_fin_plan_api INTO w_fin_plan_api WITH KEY guid = w_grp_plan-guid_p plan_type = c_plantype_73 period = w_grp_plan-period. "#EC WARNOK IF sy-subrc <> 0. CLEAR w_fin_plan_coll. READ TABLE t_fin_plan_coll INTO w_fin_plan_coll WITH KEY guid = w_grp_plan-guid_p period = w_grp_plan-period. "#EC WARNOK IF sy-subrc = 0. CLEAR v_coll. v_coll = w_fin_plan_coll-amount. ELSE. "if coll is zero, zero the 73 CLEAR: w_fin_plan_api, v_updated. w_fin_plan_api-guid = w_grp_plan-guid_p. w_fin_plan_api-plan_type = c_plantype_73. w_fin_plan_api-period = w_grp_plan-period. w_fin_plan_api-amount = 0. w_fin_plan_api-currency = w_grp_plan-currency. w_fin_plan_api-unit = c_unit."'H'. w_fin_plan_api-external_id = w_grp_plan-group_id . APPEND w_fin_plan_api TO t_fin_plan_api. CLEAR w_fin_plan_api. v_updated = abap_true. ENDIF. IF v_updated = abap_false. CLEAR w_fin_plan_full73. READ TABLE t_fin_plan_full73 INTO w_fin_plan_full73 WITH KEY guid = w_grp_plan-guid_p plan_type = c_plantype_73 period = w_grp_plan-period. "#EC WARNOK IF sy-subrc = 0. CLEAR v_73. v_73 = w_fin_plan_full73-amount. "compare values IF v_coll <> v_73. CLEAR w_fin_plan_api. w_fin_plan_api-guid = w_grp_plan-guid_p. w_fin_plan_api-plan_type = c_plantype_73. w_fin_plan_api-period = w_grp_plan-period. w_fin_plan_api-amount = w_fin_plan_coll-amount. w_fin_plan_api-currency = w_grp_plan-currency. w_fin_plan_api-unit = c_unit."'H'. w_fin_plan_api-external_id = w_grp_plan-group_id . APPEND w_fin_plan_api TO t_fin_plan_api. CLEAR w_fin_plan_api. ENDIF. ELSE. "if not found, insert CLEAR w_fin_plan_api. w_fin_plan_api-guid = w_grp_plan-guid_p. w_fin_plan_api-plan_type = c_plantype_73. w_fin_plan_api-period = w_grp_plan-period. w_fin_plan_api-amount = w_fin_plan_coll-amount. w_fin_plan_api-currency = w_grp_plan-currency. w_fin_plan_api-unit = c_unit."'H'. w_fin_plan_api-external_id = w_grp_plan-group_id . APPEND w_fin_plan_api TO t_fin_plan_api. CLEAR w_fin_plan_api. ENDIF. ENDIF. CLEAR: v_73, v_coll, v_updated. ENDIF. CLEAR: v_73, v_coll, v_updated. "for every group AT END OF guid_g ##loop_at_ok. "only if plan table is filled "update fin plan IF t_fin_plan_api[] IS NOT INITIAL. "call api CALL METHOD lo_fin_cap_planning_api->fin_groups_modify EXPORTING iv_category_guid = v_cat_guid it_fin_groups = t_fin_group_api[] it_fin_plan = t_fin_plan_api[] iv_hierarchy_type = c_hierarchy_type iv_language = c_language is_plan_info = w_plan_info IMPORTING ev_rc = v_subrc et_msgs = t_msgs[]. APPEND LINES OF t_msgs TO t_msgs_group. CLEAR t_msgs[]. "save CALL METHOD cl_inm_ppm_services=>save( EXPORTING iv_check_only = /rpm/cl_co=>sc_false IMPORTING et_messages = t_msgs[] ev_rejected = v_rejected ). APPEND LINES OF t_msgs TO t_msgs_group. CLEAR t_msgs[]. "append project and group external ID UNASSIGN <fs_msg>. LOOP AT t_msgs_group ASSIGNING <fs_msg>. <fs_msg>-objectid = w_item_d-external_id. ENDLOOP. UNASSIGN <fs_msg>. APPEND LINES OF t_msgs_group TO et_msgs. CLEAR t_msgs_group[]. ENDIF. CLEAR: t_fin_group_api[], t_fin_plan_api[], w_fin_group_api. ENDAT. ENDLOOP. ENDLOOP. ENDIF. "delete duplicate messages SORT et_msgs[]. DELETE ADJACENT DUPLICATES FROM et_msgs COMPARING ALL FIELDS. "clear variables CLEAR: t_item_d, t_fin_plan_coll, t_grpplan_full, t_fin_plan_full73, t_fin_plan_api, t_fin_group_api, t_fin_plan, t_date_range, t_int_range, t_msgs, t_grp_plan, t_itemcatgrp, t_filter_data, "work areas w_fin_plan_api, w_fin_group_api, w_grp_plan, w_grp_plan_temp, w_item_d, w_date_range, w_fin_plan_full73, w_fin_plan_coll, w_context, w_plan_info, "variables v_cat_guid, v_subrc, v_high_date, v_rejected. ENDFUNCTION. To summarize, you learnt how to make use of std. SAP API /rpm/cl_fin_cap_planning_api to update /RPM/FIN_PLAN and /RPM/FIN_GROUP tables. Did this blog post help you, or answer at least some of your questions. Please share your feedback or thoughts in a comment 😊.
__label__pos
0.833823
Instantly share code, notes, and snippets. @non /laws.md Last active Aug 29, 2018 Embed What would you like to do? I feel like conversations around laws and lawfulness in Scala are often not productive, due to a lack of rigor involved. I wanted to try to be as clear and specific as possible about my views of lawful (and unlawful) behavior, and what I consider a correct and rigorous way to think about laws (and their limits) in Scala. Laws A law is a group of two or more expressions which are required to be the same. The expressions will usually involve one or more typed holes ("inputs") which vary. Some examples: x.map(id) === x x.map(f).map(g) === x.map(f andThen g) (expr, expr) === { val y = expr; (y, y) } x |+| y === y |+| x x.flatMap(f).flatMap(g) === x.flatMap(a => f(a).flatMap(g)) Sameness In general we don't have a decidable way to prove that any two Scala values are (or are not) the same. Specifically, if x and y are the same, then for any pure, total function f we require that f(x) and f(y) are also the same. This definition is recursive, and ultimately relies on the fact that for particular types we can find decidable ways to compute sameness. In general, we can't rely on universal equality (which in some cases says values are equal when they have observable differences), and we can't rely on having an instance of Eq (which doesn't exist for some types). In general, we have to rely on informal reasoning. Pure, total functions The Scala type Function1 permits partiality (exceptions), reading/modifying mutable state, infinite loops/non-termination, and other side-effects. If we require our laws to be true for any possible Function1 value in Scala then we won't have any laws. Thus, in the previous definition we have to mandate that the functions used must be total and pure. We can only enforce this requirement via care and informal reasoning. Relaxing this requirement will tend to break things like referential transparency. For example: def f(x: Int): Int = sys.error("🕱" * x) val lhs = { val y = f(2); val x = f(1); (x, y) } val rhs = { val x = f(1); val y = f(2); (x, y) } lhs === rhs // false due to side-effecting throw. // even under very relaxed sameness criteria, // sys.error("🕱") is not sys.error("🕱🕱"). Universe of values (and expressions) For any law with typed holes, we require that any valid value of the correct type must pass the law when used. What does validity mean? Similar to the previous point, we can create values which are impure, which read or modify global state, have side-effects, etc. These values can be used to break most (or all) laws. Thus, we must exclude these kinds of values and expressions when analyzing our laws. For example: // given these inputs to our law: type F[_] type A type B type C val functor: Functor[F] val fa: F[A] val f: A => B val g: B => C // and a sameness criteria: val sameness: Eq[F[C]] // we require that lhs is the same as rhs: val lhs = fa.map(f).map(g) val rhs = fa.map(f andThen g) lhs === rhs Here are some invalid values which, if valid, would demonstrate that this law was false: val fa: F[A] = null // lhs and rhs both produce NPEs not values def f(a: A): B = if (scala.util.Random.nextBoolean) b0 else b1 // f is not a function, so sameness criteria will often fail. var counter = 0 def f(a: Int): Int = { counter += 1; counter } val lhs = List(1,2,3).map(f).map(f) // List(4,5,6) val rhs = List(1,2,3).map((f _) andThen (f _)) // List(2,4,6) lhs =!= rhs // mutable state makes order of function application visible. // the goal of our law is to allow maps to be rewritten, which // can't be done in the presence of observable effects. def f(a: Int): Option[Int] = Some(a) def g(b: Option[Int]): Int = System.identityHashCode(b) val fa = List(1,2,3) val lhs = fa.map(f).map(g) // List(1790453435, 563984469, 922931437) val rhs = fa.map(f andThen g) // List(618864390, 1562772628, 222556677) lhs != rhs // System.identityHashCode is a deterministic function, but it // observes runtime information about values which we normally don't // consider when thinking about "sameness". If we use this method then // we will need an Eq[C] which uses eq, eliminating almost any possible // rewriting we can do. (The reason we consider these values invalid is that the types and type class instances being used are widely considered to be law-abiding -- it is more useful to constrain a universe of values than to throw out otherwise reasonable type class instances.) There is no requirement that all laws use the same universe of values. We might consider certain side-effects invisible (or visible) for the purposes of particular laws. This is fine, but should be explicitly stated. The "default" universe we inhabit (when reasoning using intersubstitutability and referential transparency) is the universe of pure, effect-free values (and functions operating on these values). The same argument applies for expressions: instead of applying a single value to a law, we can apply a valid expression from our universe which evaluates to a valid value. The expression must not contain any invalid sub-expressions (e.g. those which produce side-effects). Law violations A law violation occurs when values from the law's universe are found that cause the law's expressions to evaluate to different values (as determined by the sameness criteria). When a law violation occurs, there are several possible responses: • Observing that the law is false (the most common case). • Observing that the law could be true for a narrower universe. • Observing that the value(s) are not valid. • Observing that the sameness criterion is not valid. For example, two values which we might consider the same could look different under reflection, or via sun.misc.Unsafe. This doesn't disprove our law, it just illustrates that our "function" for sameness is invalid. Similarly, we might want to write a law about asynchronous operations (ensuring that both ultimately complete, possibly in a certain order). This might require allowing a specific kind of side-effect into our universe of expressions, so that we can write laws which observe order of effects. In these cases, we need to be explicit that we are no longer inhabiting our usual universe, and be explicit about the fact that these expressions are not referentially-transparent to begin with (i.e. for many other kinds of important laws they will be invalid). Parametricity and other restrictions Counter-intuitively, we may be forbidden to use certain methods on a type when considering "sameness". One example is eq, which we can use to observe whether two values point to the same memory address or not. Very few laws can be proven if we require their results to be eq, and many effects which we would prefer to be unobservable (e.g. memoization of immutable values, reference sharing, etc.) are observable with eq. Similarly, we can use runtime reflection or reflective pattern-matching to "sniff out" the erased type of a value at run time. This allows us to define functions which can violate parametricity and break laws. We usually don't consider these functions as valid either. Non-violations Notably, if we can prove (or convince ourselves) that a law is true for its universe of valid types and expressions, we can't say anything about its behavior for invalid values (those outside the universe). The kind of equational reasoning laws grant us are inherently constrained to the universe of values and expressions we used to prove those laws. Similarly, from the point of view of lawfulness there isn't a good reason to believe that one behavior is better than another when it comes to invalid inputs or functions. A type whose map method could magically "sniff out" (and throw) when given an impure function isn't any more (or less) lawful than one which memoizes the function and only runs it once, or one which runs the function N times, or whatever. We may desire other behavior from our types, but that analysis occurs outside the realm of the laws we define for the type. If we wanted to write laws in terms of the universe of all possible Scala values and expressions, we would have to accept that our toolbox for informal reasoning would be almost totally empty. Conclusion Laws allow us to reason with rigor about code which we prove (or at least believe) to be lawful. However, in order to be sure we are reasoning about laws correctly, we must be rigorous about what laws require, as well as distinguishing things laws can tell us versus things about which they must remain silent. See Also The discussion here is indebted to Proofs and Refutations (Lakatos, 1976) [1]. That text introduces the idea that mathematical objects (e.g. a polyhedron) and proofs involving those objects (e.g. the Euler characteristic of a polyhedron) co-evolve based on the prior commitments and philosophical views of mathematicians. When a proof fails, we have to decide whether to amend the terms the proof uses (i.e. narrow its scope), look for a better proof, or give up and declare the proof (and the underlying idea of the proof) invalid. [1] https://en.wikipedia.org/wiki/Proofs_and_Refutations @Ichoran This comment has been minimized. Ichoran commented Apr 24, 2017 I wholeheartedly agree! Indeed, I'm not even sure what one could argue with here? If there is confusion on this point, this gist should be required reading. Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
__label__pos
0.80413
DEV Community loading... Screensaver in JavaScript Michał Muszyński Programming & Cartography Originally published at michalmuszynski.com ・4 min read All of us know very well the screensavers in our operating systems. In this post, I'd like to show how to implement such functionality in our web application using Javascript. The animation I present is not very sophisticated and complicated, but it's a place to start implementing your own, more complex solution here. The code I present here is a part of my first npm package and it may be reused in your website. Class properties First, I defined a few class properties: interface BaseConfig { text?: string background?: string baseElement?: HTMLElement | Element backgroundImg?: string animationSpeed?: 'slow' | 'regular' | 'fast' customElement?: HTMLElement | Element | string, triggerTime?: number, } class JsScreensaver { private config: BaseConfig = baseConfig; private windowDimensions: IDimensions = {width : 0, height : 0}; private playAnimation: boolean = true; private screensaverElement: HTMLElement = document.body; private eventsList: string[] = ['keydown', 'mousemove']; private defaultScreensaver: string = ` <div class="screensaver__element-wrapper"> <div class="screensaver__element-content"> <p class="screensaver__element-text"></p> </div> </div> ` Enter fullscreen mode Exit fullscreen mode In the BaseConfig interface, I listed all options that may be passed into the screensaver configuration. Screensaver is initialized with the start() method. If there are no options passed as an argument, the baseConfig is loaded. start(config?: BaseConfig): void { this.config = {...baseConfig, ...config}; this.setActionsListeners(); } Enter fullscreen mode Exit fullscreen mode In the next step, listeners for the events are added. Screensaver will be turned on after the time defined (in milliseconds)in the triggerTime property. The default value is set to 2 seconds. For each of the events in the array (keyup and mousemove) the addEventListener is set, with a callback function that creates the screensaver container after a certain time. If the event is triggered, the timeout is cleared and the screensaver element is removed. private stopScreensaverListener() { this.eventsList.forEach(event => window.addEventListener(event, (e) => { e.preventDefault(); this.playAnimation = false; this.screensaverElement.remove(); })); } private setActionsListeners() { let mouseMoveTimer: ReturnType<typeof setTimeout>; this.eventsList.forEach(event => window.addEventListener(event, () => { clearTimeout(mouseMoveTimer); mouseMoveTimer = setTimeout(() => { this.createContainer(); }, this.config.triggerTime) })) } Enter fullscreen mode Exit fullscreen mode The stopScreensaverListener method is triggered from the createContainer. The latter creates a DOM element with appropriate classes and styling. The screensaver container and element (a rectangle in this case) are appended to the body as a default, but we can define any other container, passing it into a configuration in a baseElement property. Here, the animation is triggered. For now, I have only one animation available in this package. It's a simple one, just a rectangle bouncing around the screen with text inside. I want to extend this package by adding more predefined animations to it. In addition, the user should be able to define its own animation as well. But that's something that needs to be developed in the nearest future. Not, let's focus on the existing animation. I use the requestAnimationFrame API which I described in my previous post. In that post I showed the same animation. In this package, it's a little bit enhanced. private runAnimation(element: HTMLElement): void { this.playAnimation = true; element.style.position = 'absolute'; let positionX = this.windowDimensions.width / 2; let positionY = this.windowDimensions.height / 2; let movementX = this.config.animationSpeed ? speedOptions[this.config.animationSpeed] : speedOptions.regular; let movementY = this.config.animationSpeed ? speedOptions[this.config.animationSpeed] : speedOptions.regular; const animateElements = () => { positionY += movementY positionX += movementX if (positionY < 0 || positionY >= this.windowDimensions.height - element.offsetHeight) { movementY = -movementY; } if (positionX <= 0 || positionX >= this.windowDimensions.width - element.clientWidth) { movementX = -movementX; } element.style.top = positionY + 'px'; element.style.left = positionX + 'px'; if (this.playAnimation) { requestAnimationFrame(animateElements); } } requestAnimationFrame(animateElements) } Enter fullscreen mode Exit fullscreen mode The rectangle's start position is set to the center. That's calculated in the positionX and positionY variables. The movement represents the number of pixels that the object will move in every frame. Here I used the values from the configuration, letting the user set the speed of movement. In every frame, the position of the rectangle is checked, whether it's inside the container or if it hits the border of the container. If the breakpoint values are reached, the movement values are set to the opposite, which generates the motion in the opposite direction. Usage Usage of the screensaver is very simple. The whole class is exported: const classInstance = new JsScreensaver(); export { classInstance as JsScreensaver }; Enter fullscreen mode Exit fullscreen mode So you only have to import the class somewhere in your code with import { JsScreensaver } from "../js-screensaver"; And use the start() method with the configuration (or leave the config blank). JsScreensaver.start({ text: "Hello Screensaver", customElement: document.querySelector('.screen-saver'), triggerTime: 4000, animationSpeed: 'slow' }); Enter fullscreen mode Exit fullscreen mode The customElement property lets you create the screensaver from the HTML or component in your own project. So you can inject any customized element with styling that sits in your project. Conclusion That's the final result, the screensaver with a custom HTML, styling, text inside: Screensaver example I did not show every line of code in this post. The whole project is available here, so you can check every method and configuration. This package is very simple and not much customizable so far, but - it has potential ;-). Discussion (0)
__label__pos
0.922257
Adding AMQPCPP C++ libraries for TCP Socket Connection, TX2 device I want to install some c++ libraries in order to handle a TCP connection from my host machine, to a TX2 device on the same wifi network. I have downloaded the AMQPCPP library from: I followed the instructions for installing using Make. This did put .so files in the /usr/lib directory and a bunch of .h files in the /usr/include directory for the amqpcpp. I believe to deploy proper binaries to the Jetson, they must be included in /usr/aarch64-linux-gnu. So I have copided the .so file from /usr/lib to /usr/aarch64-linux-gnu/lib and .h files from /usr/include to /usr/aarch64-linux-gnu/include. A lot of manual copy and paste has been done to get files that I’m certain I need. Is this the way I’m suppossed to do this or is there a more systematic approach for getting these files to build properly and deploy to the Jetson device? The ultimate goal is to use rabbitmq and run a messaging server over the wifi network. This is being run on Ubuntu 18.04 with the 2019.2 Isaac SDK. I did add build files to the directory “~/isaac/third_party” using the tensorrt as a template. Here is what one build in the third_party folder looks like below and named “amqpcpp.BUILD”: cc_library( name = “amqpcpp”, includes = [“include”,], srcs = glob([“lib/libamqpcpp.so*”]), hdrs = glob([“include/amqpcpp.h”, “include/amqpcpp/.h", "include/amqpcpp/**/.h”]), visibility = ["//visibility:public"], include_prefix = “include”, linkopts = [ “-L/usr/lib”, ], linkstatic = True, ) A second build file is shown in the below comment as well: And also a second build file named “amqpcpp_jetson.BUILD” cc_library( name = “amqpcpp_jetson”, includes = [“include”], srcs = glob([“lib/libamqpcpp.so*”]), hdrs = glob([“include/amqpcpp.h”, “include/amqpcpp/.h", "include/amqpcpp/**/.h”]), visibility = ["//visibility:public"], include_prefix = “include”, linkopts = [ “-L/usr/aarch64-linux-gnu/lib”, ], linkstatic = True, ) Added to main "BUILD: file in issac/third_party: cc_library( name = “amqpcppLib”, visibility = ["//visibility:public"], deps = select({ “//engine/build:platform_x86_64”: ["@amqpcpp"], “//engine/build:platform_jetpack42”: ["@amqpcpp_aarch64_jetson"], }), ) cc_library( name = “libeventLib”, visibility = ["//visibility:public"], deps = select({ “//engine/build:platform_x86_64”: ["@libevent"], “//engine/build:platform_jetpack42”: ["@libevent_aarch64_jetson"], }), ) These are appended below the original libraries. @repositories were added to package.bzl file (found in isaac/third_party). Must have “load(”//engine/build:isaac.bzl", “isaac_new_local_repository”)" at top. isaac_new_local_repository( name = "amqpcpp", path = "/usr", build_file = clean_dep("//third_party:amqpcpp.BUILD"), licenses = ["//:LICENSE"], ) isaac_new_local_repository( name = "amqpcpp_jetson", path = "/usr/aarch64-linux-gnu", build_file = clean_dep("//third_party:amqpcpp_jetson.BUILD"), licenses = ["//:LICENSE"], ) I get a clean build using 'bazel build '. At this point I cannot deploy to the TX2 device. One of the warning message on deploy: “/usr/lib/gcc-cross/aarch64-linux-gnu/7/…/…/…/…/aarch64-linux-gnu/bin/ld: skipping incompatible /usr/aarch64-linux-gnu/lib/libamqpcpp.so when searching for -lamqpcpp” At this point when I try to deploy to the Jetson, all .so files in /usr/aarch64-linux-gnu/lib regarding amqcpp are skipped due to incompatibility. Given this is not an error, it does lead to “unable to find -lamqpcpp” and “collect2: error: ld returned 1 exit status” I changed the “amqpcpp_Jetson.BUILD” file to: cc_library( name = “amqpcpp_jetson”, srcs = glob([“lib/aarch64-linux-gnu/amqpcpp/lib/libamqpcpp.so*”]), hdrs = glob(["/lib/aarch64-linux-gnu/amqpcpp/include/amqpcpp.h", “/lib/aarch64-linux-gnu/amqpcpp/include/amqpcpp/.h", "/lib/aarch64-linux-gnu/amqpcpp/include/amqpcpp/**/ .h”]), visibility = ["//visibility:public"], strip_include_prefix = “lib/aarch64-linux-gnu/amqpcpp/include”, linkopts = ["-L/usr/lib/aarch64-linux-gnu/amqpcpp/lib"], linkstatic = True, ) It seemed as though I specified the repository path as “/usr/lib/aarch64-linux-gnu/”, when searching for .so files, the path being searched was /usr/lib. At this point I can now deploy to the robot. However, when I run my application, I get the following error: “2019-09-23 09:26:01.850 ERROR engine/alice/backend/modules.cpp@307: iam-devices:rabbitMq: /home/iam/deploy/jake/moveBolt-pkg//external/com_nvidia_isaac/packages/iam-devices/librabbitMq_module.so: cannot open shared object file: No such file or directory 2019-09-23 09:26:01.850 PANIC engine/alice/backend/modules.cpp@309: Could not load all required modules for application” rabbitMq is the module I created in my build file where my actual project is located. Removing any mention of the rabbitMq file will let me run my application without any issue and other modules I created and added have no problem. The main difference between this one and the others is that I have a third_party dependency referencing all the above comments I added. I have run into a similar issue like this before. When deploying, librabbitMq.so module is put in my package folder under ~/deploy/jake/moveBolt-pkg/packages/iam-devices just like all my other modules, but when running the program, the location that is searched for the rabbitMq module is in: “/home/iam/deploy/jake/moveBolt-pkg//external/com_nvidia_isaac/packages/iam-devices/librabbitMq_module.so” This does not exist. Below is the creation of my module: isaac_cc_module( name=“rabbitMq”, srcs=[“isaac/OrchestratorGoalListener.cpp”], hdrs=[“isaac/OrchestratorGoalListener.hpp”, “isaac/conn_handler.h”], deps=["//third_party:amqpcpp", “//third_party:libevent”] ) It is also included at the top of the build file under mdoules as “//packages/iam-devices:rabbitMq”. It is also in my “*.app.json” file under modules as “iam-devices:rabbitMq”. (iam-devices is under the packages folder of my isaac root directory) I have narrowed down the problem even further. I am using the conn_handler.h file from: I did have to change line 9 to LibEventHandlerMyError(struct event_base* evbase) : LibEventHandler(evbase), evbase_(evbase) {} Bazel did not like the self initialization. This takes care of the events for the amqpcpp. I have a codelet that includes the above .h file. When I try to delcare a handle in my codelet, such as: ConnHandler handler; This is when I get the error from post #6. Otherwise, the application will run everything else without issue before I start trying to use the conn_handler.h file or any of the ampqcpp library. Is it possible the new libraries are just not being deployed to the robot? So when I try to access them, there is a crash because they don’t exist on the TX2 possibly? When I do a bazel build of my target application, there is not problem, probably because the libraries exist for sure on my machine in these locations: /usr/include /usr/lib /usr/aarch64-linux-gnu/lib /usr/aarch64-linux-gnu/include /usr/lib/aarch64-linux-gnu /usr/lib/aarch64-linux-gnu Under the last 2, the folder for openssl, amqpcpp, and libevents have their own folders with includes and lib folders. The only location I manually placed files, was in /usr/aarch64-linux-gnu/ directories. I had to do this in order to build the project and deploy.
__label__pos
0.528114
parachains.rs 30.1 KB Newer Older // Copyright 2017 Parity Technologies (UK) Ltd. // This file is part of Polkadot. // Polkadot is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // Polkadot is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see <http://www.gnu.org/licenses/>. //! Main parachains logic. For now this is just the determination of which validators do what. use rstd::prelude::*; use parity_codec::{Decode, HasCompact}; use srml_support::{decl_storage, decl_module, fail, ensure}; use bitvec::{bitvec, BigEndian}; Gavin Wood's avatar Gavin Wood committed use sr_primitives::traits::{Hash as HashT, BlakeTwo256, Member}; use primitives::{Hash, parachain::{Id as ParaId, Chain, DutyRoster, AttestedCandidate, Statement, AccountIdConversion}}; Gavin Wood's avatar Gavin Wood committed use srml_support::{StorageValue, StorageMap, Parameter, dispatch::Result}; #[cfg(feature = "std")] use srml_support::storage::hashed::generator; use inherents::{ProvideInherent, InherentData, RuntimeString, MakeFatalError, InherentIdentifier}; #[cfg(any(feature = "std", test))] Gav Wood's avatar Gav Wood committed use sr_primitives::{StorageOverlay, ChildrenStorageOverlay}; #[cfg(any(feature = "std", test))] use rstd::marker::PhantomData; thiolliere's avatar thiolliere committed use system::ensure_none; Gavin Wood's avatar Gavin Wood committed /// Parachain registration API. pub trait ParachainRegistrar<AccountId> { /// An identifier for a parachain. type ParaId: Member + Parameter + Default + AccountIdConversion<AccountId> + Copy + HasCompact; /// Create a new unique parachain identity for later registration. fn new_id() -> Self::ParaId; /// Register a parachain with given `code` and `initial_head_data`. `id` must not yet be registered or it will /// result in a error. fn register_parachain(id: Self::ParaId, code: Vec<u8>, initial_head_data: Vec<u8>) -> Result; /// Deregister a parachain with given `id`. If `id` is not currently registered, an error is returned. fn deregister_parachain(id: Self::ParaId) -> Result; } impl<T: Trait> ParachainRegistrar<T::AccountId> for Module<T> { type ParaId = ParaId; fn new_id() -> ParaId { <NextFreeId<T>>::mutate(|n| { let r = *n; *n = ParaId::from(u32::from(*n) + 1); r }) } fn register_parachain(id: ParaId, code: Vec<u8>, initial_head_data: Vec<u8>) -> Result { let mut parachains = Self::active_parachains(); match parachains.binary_search(&id) { Ok(_) => fail!("Parachain already exists"), Err(idx) => parachains.insert(idx, id), } <Code<T>>::insert(id, code); <Parachains<T>>::put(parachains); <Heads<T>>::insert(id, initial_head_data); Ok(()) } fn deregister_parachain(id: ParaId) -> Result { let mut parachains = Self::active_parachains(); match parachains.binary_search(&id) { Ok(idx) => { parachains.remove(idx); } Err(_) => return Ok(()), } <Code<T>>::remove(id); <Heads<T>>::remove(id); // clear all routing entries to and from other parachains. for other in parachains.iter().cloned() { <Routing<T>>::remove((id, other)); <Routing<T>>::remove((other, id)); } <Parachains<T>>::put(parachains); Ok(()) } } pub trait Trait: session::Trait { } // result of <NodeCodec<Blake2Hasher> as trie_db::NodeCodec<Blake2Hasher>>::hashed_null_node() const EMPTY_TRIE_ROOT: [u8; 32] = [ 3, 23, 10, 46, 117, 151, 183, 183, 227, 216, 76, 5, 57, 29, 19, 154, 98, 177, 87, 231, 135, 134, 216, 192, 130, 242, 157, 207, 76, 17, 19, 20 ]; Gav's avatar Gav committed trait Store for Module<T: Trait> as Parachains { // Vector of all parachain IDs. pub Parachains get(active_parachains): Vec<ParaId>; Gav's avatar Gav committed // The parachains registered at present. pub Code get(parachain_code): map ParaId => Option<Vec<u8>>; // The heads of the parachains registered at present. pub Heads get(parachain_head): map ParaId => Option<Vec<u8>>; // message routing roots (from, to). pub Routing: map (ParaId, ParaId) => Option<Hash>; Gav's avatar Gav committed // Did the parachain heads get updated in this block? DidUpdate: bool; Gavin Wood's avatar Gavin Wood committed /// The next unused ParaId value. NextFreeId: ParaId; } add_extra_genesis { config(parachains): Vec<(ParaId, Vec<u8>, Vec<u8>)>; config(_phdata): PhantomData<T>; Gav Wood's avatar Gav Wood committed build(|storage: &mut StorageOverlay, _: &mut ChildrenStorageOverlay, config: &GenesisConfig<T>| { let mut p = config.parachains.clone(); p.sort_unstable_by_key(|&(ref id, _, _)| id.clone()); p.dedup_by_key(|&mut (ref id, _, _)| id.clone()); let only_ids: Vec<_> = p.iter().map(|&(ref id, _, _)| id).cloned().collect(); <Parachains<T> as generator::StorageValue<_>>::put(&only_ids, storage); for (id, code, genesis) in p { // no ingress -- a chain cannot be routed to until it is live. <Code<T> as generator::StorageMap<_, _>>::insert(&id, &code, storage); <Heads<T> as generator::StorageMap<_, _>>::insert(&id, &genesis, storage); } }); } } decl_module! { /// Parachains module. pub struct Module<T: Trait> for enum Call where origin: T::Origin { /// Provide candidate receipts for parachains, in ascending order by id. fn set_heads(origin, heads: Vec<AttestedCandidate>) -> Result { thiolliere's avatar thiolliere committed ensure_none(origin)?; ensure!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block"); let active_parachains = Self::active_parachains(); // perform integrity checks before writing to storage. { let n_parachains = active_parachains.len(); ensure!(heads.len() <= n_parachains, "Too many parachain candidates"); let mut last_id = None; let mut iter = active_parachains.iter(); for head in &heads { // proposed heads must be ascending order by parachain ID without duplicate. ensure!( last_id.as_ref().map_or(true, |x| x < &head.parachain_index()), "Parachain candidates out of order by ID" ); // must be unknown since active parachains are always sorted. ensure!( iter.find(|x| x == &&head.parachain_index()).is_some(), "Submitted candidate for unregistered or out-of-order parachain {}" ); Self::check_egress_queue_roots(&head, &active_parachains)?; last_id = Some(head.parachain_index()); Self::check_attestations(&heads)?; for head in heads { let id = head.parachain_index(); <Heads<T>>::insert(id, head.candidate.head_data.0); // update egress. for &(to, root) in &head.candidate.egress_queue_roots { <Routing<T>>::insert((id, to), root); } } <DidUpdate<T>>::put(true); Ok(()) } /// Register a parachain with given code. /// Fails if given ID is already used. pub fn register_parachain(id: ParaId, code: Vec<u8>, initial_head_data: Vec<u8>) -> Result { Gavin Wood's avatar Gavin Wood committed <Self as ParachainRegistrar<T::AccountId>>::register_parachain(id, code, initial_head_data) } /// Deregister a parachain with given id pub fn deregister_parachain(id: ParaId) -> Result { Gavin Wood's avatar Gavin Wood committed <Self as ParachainRegistrar<T::AccountId>>::deregister_parachain(id) Gav Wood's avatar Gav Wood committed fn on_finalize(_n: T::BlockNumber) { assert!(<Self as Store>::DidUpdate::take(), "Parachain heads must be updated once in the block"); } Gav's avatar Gav committed } fn majority_of(list_len: usize) -> usize { list_len / 2 + list_len % 2 } fn localized_payload(statement: Statement, parent_hash: ::primitives::Hash) -> Vec<u8> { use parity_codec::Encode; let mut encoded = statement.encode(); encoded.extend(parent_hash.as_ref()); encoded } impl<T: Trait> Module<T> { /// Calculate the current block's duty roster using system's random seed. pub fn calculate_duty_roster() -> DutyRoster { let parachains = Self::active_parachains(); let parachain_count = parachains.len(); let validator_count = <consensus::Module<T>>::authorities().len(); let validators_per_parachain = if parachain_count != 0 { (validator_count - 1) / parachain_count } else { 0 }; let mut roles_val = (0..validator_count).map(|i| match i { i if i < parachain_count * validators_per_parachain => { let idx = i / validators_per_parachain; Chain::Parachain(parachains[idx].clone()) } _ => Chain::Relay, }).collect::<Vec<_>>(); let mut seed = { let phrase = b"validator_role_pairs"; let seed = system::Module::<T>::random(&phrase[..]); let seed_len = seed.as_ref().len(); let needed_bytes = validator_count * 4; // hash only the needed bits of the random seed. // if earlier bits are influencable, they will not factor into // the seed used here. let seed_off = if needed_bytes >= seed_len { 0 } else { seed_len - needed_bytes }; BlakeTwo256::hash(&seed.as_ref()[seed_off..]) }; // shuffle for i in 0..(validator_count - 1) { // 4 bytes of entropy used per cycle, 32 bytes entropy per hash let offset = (i * 4 % 32) as usize; // number of roles remaining to select from. let remaining = (validator_count - i) as usize; // 8 32-bit ints per 256-bit seed. let val_index = u32::decode(&mut &seed[offset..offset + 4]).expect("using 4 bytes for a 32-bit quantity") as usize % remaining; if offset == 28 { // into the last 4 bytes - rehash to gather new entropy seed = BlakeTwo256::hash(seed.as_ref()); } // exchange last item with randomly chosen first. roles_val.swap(remaining - 1, val_index); } DutyRoster { validator_duty: roles_val, } } /// Calculate the ingress to a specific parachain. /// /// Yields a list of parachains being routed from, and the egress /// queue roots to consider. pub fn ingress(to: ParaId) -> Option<Vec<(ParaId, Hash)>> { let active_parachains = Self::active_parachains(); if !active_parachains.contains(&to) { return None } Some(active_parachains.into_iter().filter(|i| i != &to) .filter_map(move |from| { <Routing<T>>::get((from, to.clone())).map(move |h| (from, h)) }) .collect()) } fn check_egress_queue_roots(head: &AttestedCandidate, active_parachains: &[ParaId]) -> Result { let mut last_egress_id = None; let mut iter = active_parachains.iter(); for (egress_para_id, root) in &head.candidate.egress_queue_roots { // egress routes should be ascending order by parachain ID without duplicate. ensure!( last_egress_id.as_ref().map_or(true, |x| x < &egress_para_id), "Egress routes out of order by ID" ); // a parachain can't route to self ensure!( *egress_para_id != head.candidate.parachain_index, "Parachain routing to self" ); // no empty trie roots ensure!( *root != EMPTY_TRIE_ROOT.into(), "Empty trie root included" ); // can't route to a parachain which doesn't exist ensure!( iter.find(|x| x == &egress_para_id).is_some(), "Routing to non-existent parachain" ); last_egress_id = Some(egress_para_id) } Ok(()) } // check the attestations on these candidates. The candidates should have been checked // that each candidates' chain ID is valid. fn check_attestations(attested_candidates: &[AttestedCandidate]) -> Result { use primitives::parachain::ValidityAttestation; use sr_primitives::traits::Verify; // returns groups of slices that have the same chain ID. // assumes the inner slice is sorted by id. struct GroupedDutyIter<'a> { next_idx: usize, inner: &'a [(usize, ParaId)], } impl<'a> GroupedDutyIter<'a> { fn new(inner: &'a [(usize, ParaId)]) -> Self { GroupedDutyIter { next_idx: 0, inner } } fn group_for(&mut self, wanted_id: ParaId) -> Option<&'a [(usize, ParaId)]> { while let Some((id, keys)) = self.next() { if wanted_id == id { return Some(keys) } } None } } impl<'a> Iterator for GroupedDutyIter<'a> { type Item = (ParaId, &'a [(usize, ParaId)]); fn next(&mut self) -> Option<Self::Item> { if self.next_idx == self.inner.len() { return None } let start_idx = self.next_idx; self.next_idx += 1; let start_id = self.inner[start_idx].1; while self.inner.get(self.next_idx).map_or(false, |&(_, ref id)| id == &start_id) { self.next_idx += 1; } Some((start_id, &self.inner[start_idx..self.next_idx])) } } let authorities = super::Consensus::authorities(); let duty_roster = Self::calculate_duty_roster(); // convert a duty roster, which is originally a Vec<Chain>, where each // item corresponds to the same position in the session keys, into // a list containing (index, parachain duty) where indices are into the session keys. // this list is sorted ascending by parachain duty, just like the // parachain candidates are. let make_sorted_duties = |duty: &[Chain]| { let mut sorted_duties = Vec::with_capacity(duty.len()); for (val_idx, duty) in duty.iter().enumerate() { let id = match duty { Chain::Relay => continue, Chain::Parachain(id) => id, }; let idx = sorted_duties.binary_search_by_key(&id, |&(_, ref id)| id) .unwrap_or_else(|idx| idx); sorted_duties.insert(idx, (val_idx, *id)); } sorted_duties }; let sorted_validators = make_sorted_duties(&duty_roster.validator_duty); let parent_hash = super::System::parent_hash(); let localized_payload = |statement: Statement| localized_payload(statement, parent_hash); let mut validator_groups = GroupedDutyIter::new(&sorted_validators[..]); for candidate in attested_candidates { let validator_group = validator_groups.group_for(candidate.parachain_index()) .ok_or("no validator group for parachain")?; ensure!( candidate.validity_votes.len() >= majority_of(validator_group.len()), "Not enough validity attestations" ); let mut candidate_hash = None; let mut encoded_implicit = None; let mut encoded_explicit = None; // track which voters have voted already, 1 bit per authority. let mut track_voters = bitvec![0; authorities.len()]; for (auth_index, validity_attestation) in &candidate.validity_votes { let auth_index = *auth_index as usize; // protect against double-votes. match validator_group.iter().find(|&(idx, _)| *idx == auth_index) { None => return Err("Attesting validator not on this chain's validation duty."), Some(&(idx, _)) => { if track_voters.get(idx) { return Err("Voter already attested validity once") } track_voters.set(idx, true) } } let (payload, sig) = match validity_attestation { ValidityAttestation::Implicit(sig) => { let payload = encoded_implicit.get_or_insert_with(|| localized_payload( Statement::Candidate(candidate.candidate.clone()), )); (payload, sig) } ValidityAttestation::Explicit(sig) => { let hash = candidate_hash .get_or_insert_with(|| candidate.candidate.hash()) .clone(); let payload = encoded_explicit.get_or_insert_with(|| localized_payload( Statement::Valid(hash), )); (payload, sig) } }; ensure!( sig.verify(&payload[..], &authorities[auth_index]), "Candidate validity attestation signature is bad." ); } } Ok(()) } // TODO: Consider integrating if needed. (https://github.com/paritytech/polkadot/issues/223) /// Extract the parachain heads from the block. pub fn parachain_heads(&self) -> &[CandidateReceipt] { let x = self.inner.extrinsics.get(PARACHAINS_SET_POSITION as usize).and_then(|xt| match xt.function { Call::Parachains(ParachainsCall::set_heads(ref x)) => Some(&x[..]), _ => None }); match x { Some(x) => x, None => panic!("Invalid polkadot block asserted at {:?}", self.file_line), pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"newheads"; pub type InherentType = Vec<AttestedCandidate>; impl<T: Trait> ProvideInherent for Module<T> { type Call = Call<T>; type Error = MakeFatalError<RuntimeString>; const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER; fn create_inherent(data: &InherentData) -> Option<Self::Call> { let data = data.get_data::<InherentType>(&INHERENT_IDENTIFIER) .expect("Parachain heads could not be decoded.") .expect("No parachain heads found in inherent data."); Some(Call::set_heads(data)) } } #[cfg(test)] mod tests { use super::*; use sr_io::{TestExternalities, with_externalities}; use substrate_primitives::{H256, Blake2Hasher}; use substrate_trie::NodeCodec; use sr_primitives::{generic, BuildStorage}; Gav Wood's avatar Gav Wood committed use sr_primitives::traits::{BlakeTwo256, IdentityLookup}; use primitives::{parachain::{CandidateReceipt, HeadData, ValidityAttestation, ValidatorIndex}, SessionKey}; use keyring::{AuthorityKeyring, AccountKeyring}; use srml_support::{impl_outer_origin, assert_ok}; use {consensus, timestamp}; impl_outer_origin! { pub enum Origin for Test {} } Gav Wood's avatar Gav Wood committed #[derive(Clone, Eq, PartialEq)] pub struct Test; impl consensus::Trait for Test { type InherentOfflineReport = (); type SessionKey = SessionKey; type Log = crate::Log; } impl system::Trait for Test { type Origin = Origin; type Index = crate::Nonce; type BlockNumber = u64; type Hash = H256; Gav Wood's avatar Gav Wood committed type Hashing = BlakeTwo256; type Digest = generic::Digest<crate::Log>; type AccountId = crate::AccountId; type Lookup = IdentityLookup<crate::AccountId>; type Header = crate::Header; Gav's avatar Gav committed type Event = (); type Log = crate::Log; } impl session::Trait for Test { type ConvertAccountIdToSessionKey = (); type OnSessionChange = (); Gav's avatar Gav committed type Event = (); } impl timestamp::Trait for Test { type Moment = u64; type OnTimestampSet = (); impl Trait for Test {} type Parachains = Module<Test>; type System = system::Module<Test>; fn new_test_ext(parachains: Vec<(ParaId, Vec<u8>, Vec<u8>)>) -> TestExternalities<Blake2Hasher> { let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0; AuthorityKeyring::Alice, AuthorityKeyring::Bob, AuthorityKeyring::Charlie, AuthorityKeyring::Dave, AuthorityKeyring::Eve, AuthorityKeyring::Ferdie, AuthorityKeyring::One, AuthorityKeyring::Two, ]; let validator_keys = [ AccountKeyring::Alice, AccountKeyring::Bob, AccountKeyring::Charlie, AccountKeyring::Dave, AccountKeyring::Eve, AccountKeyring::Ferdie, AccountKeyring::One, AccountKeyring::Two, t.extend(consensus::GenesisConfig::<Test>{ code: vec![], authorities: authority_keys.iter().map(|k| SessionKey::from(*k)).collect(), }.build_storage().unwrap().0); t.extend(session::GenesisConfig::<Test>{ session_length: 1000, validators: validator_keys.iter().map(|k| crate::AccountId::from(*k)).collect(), keys: vec![], }.build_storage().unwrap().0); t.extend(GenesisConfig::<Test>{ parachains: parachains, _phdata: Default::default(), }.build_storage().unwrap().0); fn make_attestations(candidate: &mut AttestedCandidate) { let mut vote_implicit = false; let parent_hash = crate::System::parent_hash(); let duty_roster = Parachains::calculate_duty_roster(); let candidate_hash = candidate.candidate.hash(); let authorities = crate::Consensus::authorities(); let extract_key = |public: SessionKey| { AuthorityKeyring::from_raw_public(public.0).unwrap() }; let validation_entries = duty_roster.validator_duty.iter() .enumerate(); for (idx, &duty) in validation_entries { if duty != Chain::Parachain(candidate.parachain_index()) { continue } vote_implicit = !vote_implicit; let key = extract_key(authorities[idx].clone()); let statement = if vote_implicit { Statement::Candidate(candidate.candidate.clone()) } else { Statement::Valid(candidate_hash.clone()) }; let payload = localized_payload(statement, parent_hash); let signature = key.sign(&payload[..]).into(); candidate.validity_votes.push((idx as ValidatorIndex, if vote_implicit { ValidityAttestation::Implicit(signature) ValidityAttestation::Explicit(signature) })); fn new_candidate_with_egress_roots(egress_queue_roots: Vec<(ParaId, H256)>) -> AttestedCandidate { AttestedCandidate { validity_votes: vec![], candidate: CandidateReceipt { parachain_index: 0.into(), collator: Default::default(), signature: Default::default(), head_data: HeadData(vec![1, 2, 3]), balance_uploads: vec![], egress_queue_roots, fees: 0, block_data_hash: Default::default(), } } } fn active_parachains_should_work() { let parachains = vec![ (5u32.into(), vec![1,2,3], vec![1]), (100u32.into(), vec![4,5,6], vec![2]), ]; with_externalities(&mut new_test_ext(parachains), || { assert_eq!(Parachains::active_parachains(), vec![5u32.into(), 100u32.into()]); assert_eq!(Parachains::parachain_code(&5u32.into()), Some(vec![1,2,3])); assert_eq!(Parachains::parachain_code(&100u32.into()), Some(vec![4,5,6])); fn register_deregister() { let parachains = vec![ (5u32.into(), vec![1,2,3], vec![1]), (100u32.into(), vec![4,5,6], vec![2,]), ]; with_externalities(&mut new_test_ext(parachains), || { assert_eq!(Parachains::active_parachains(), vec![5u32.into(), 100u32.into()]); assert_eq!(Parachains::parachain_code(&5u32.into()), Some(vec![1,2,3])); assert_eq!(Parachains::parachain_code(&100u32.into()), Some(vec![4,5,6])); assert_ok!(Parachains::register_parachain(99u32.into(), vec![7,8,9], vec![1, 1, 1])); assert_eq!(Parachains::active_parachains(), vec![5u32.into(), 99u32.into(), 100u32.into()]); assert_eq!(Parachains::parachain_code(&99u32.into()), Some(vec![7,8,9])); assert_ok!(Parachains::deregister_parachain(5u32.into())); assert_eq!(Parachains::active_parachains(), vec![99u32.into(), 100u32.into()]); assert_eq!(Parachains::parachain_code(&5u32.into()), None); }); } #[test] fn duty_roster_works() { let parachains = vec![ (0u32.into(), vec![], vec![]), (1u32.into(), vec![], vec![]), ]; with_externalities(&mut new_test_ext(parachains), || { let check_roster = |duty_roster: &DutyRoster| { assert_eq!(duty_roster.validator_duty.len(), 8); for i in (0..2).map(ParaId::from) { assert_eq!(duty_roster.validator_duty.iter().filter(|&&j| j == Chain::Parachain(i)).count(), 3); } assert_eq!(duty_roster.validator_duty.iter().filter(|&&j| j == Chain::Relay).count(), 2); }; let duty_roster_0 = Parachains::calculate_duty_roster(); check_roster(&duty_roster_0); System::initialize(&1, &H256::from([1; 32]), &Default::default()); let duty_roster_1 = Parachains::calculate_duty_roster(); check_roster(&duty_roster_1); assert!(duty_roster_0 != duty_roster_1); System::initialize(&2, &H256::from([2; 32]), &Default::default()); let duty_roster_2 = Parachains::calculate_duty_roster(); check_roster(&duty_roster_2); assert!(duty_roster_0 != duty_roster_2); assert!(duty_roster_1 != duty_roster_2); }); } #[test] fn unattested_candidate_is_rejected() { let parachains = vec![ (0u32.into(), vec![], vec![]), (1u32.into(), vec![], vec![]), ]; with_externalities(&mut new_test_ext(parachains), || { let candidate = AttestedCandidate { validity_votes: vec![], candidate: CandidateReceipt { parachain_index: 0.into(), collator: Default::default(), signature: Default::default(), head_data: HeadData(vec![1, 2, 3]), balance_uploads: vec![], egress_queue_roots: vec![], fees: 0, block_data_hash: Default::default(), thiolliere's avatar thiolliere committed assert!(Parachains::dispatch(Call::set_heads(vec![candidate]), Origin::NONE).is_err()); }) } #[test] fn attested_candidates_accepted_in_order() { let parachains = vec![ (0u32.into(), vec![], vec![]), (1u32.into(), vec![], vec![]), ]; with_externalities(&mut new_test_ext(parachains), || { let mut candidate_a = AttestedCandidate { validity_votes: vec![], candidate: CandidateReceipt { parachain_index: 0.into(), collator: Default::default(), signature: Default::default(), head_data: HeadData(vec![1, 2, 3]), balance_uploads: vec![], egress_queue_roots: vec![], fees: 0, block_data_hash: Default::default(), } }; let mut candidate_b = AttestedCandidate { validity_votes: vec![], candidate: CandidateReceipt { parachain_index: 1.into(), collator: Default::default(), signature: Default::default(), head_data: HeadData(vec![2, 3, 4]), balance_uploads: vec![], egress_queue_roots: vec![], fees: 0, block_data_hash: Default::default(), } }; make_attestations(&mut candidate_a); make_attestations(&mut candidate_b); assert!(Parachains::dispatch( Call::set_heads(vec![candidate_b.clone(), candidate_a.clone()]), thiolliere's avatar thiolliere committed Origin::NONE, ).is_err()); assert!(Parachains::dispatch( Call::set_heads(vec![candidate_a.clone(), candidate_b.clone()]), thiolliere's avatar thiolliere committed Origin::NONE, ).is_ok()); }); } #[test] fn duplicate_vote_is_rejected() { let parachains = vec![ (0u32.into(), vec![], vec![]), (1u32.into(), vec![], vec![]), ]; with_externalities(&mut new_test_ext(parachains), || { let mut candidate = AttestedCandidate { validity_votes: vec![], candidate: CandidateReceipt { parachain_index: 0.into(), collator: Default::default(), signature: Default::default(), head_data: HeadData(vec![1, 2, 3]), balance_uploads: vec![], egress_queue_roots: vec![], fees: 0, block_data_hash: Default::default(), } }; make_attestations(&mut candidate); let mut double_validity = candidate.clone(); double_validity.validity_votes.push(candidate.validity_votes[0].clone()); assert!(Parachains::dispatch( Call::set_heads(vec![double_validity]), thiolliere's avatar thiolliere committed Origin::NONE, #[test] fn ingress_works() { let parachains = vec![ (0u32.into(), vec![], vec![]), (1u32.into(), vec![], vec![]), (99u32.into(), vec![1, 2, 3], vec![4, 5, 6]), ]; with_externalities(&mut new_test_ext(parachains), || { let from_a = vec![(1.into(), [1; 32].into())]; let mut candidate_a = AttestedCandidate { validity_votes: vec![], candidate: CandidateReceipt { parachain_index: 0.into(), collator: Default::default(), signature: Default::default(), head_data: HeadData(vec![1, 2, 3]), balance_uploads: vec![], egress_queue_roots: from_a.clone(), fees: 0, block_data_hash: Default::default(), } }; let from_b = vec![(99.into(), [1; 32].into())]; let mut candidate_b = AttestedCandidate { validity_votes: vec![], candidate: CandidateReceipt { parachain_index: 1.into(), collator: Default::default(), signature: Default::default(), head_data: HeadData(vec![1, 2, 3]), balance_uploads: vec![], egress_queue_roots: from_b.clone(), fees: 0, block_data_hash: Default::default(), } }; make_attestations(&mut candidate_a); make_attestations(&mut candidate_b); assert_eq!(Parachains::ingress(ParaId::from(1)), Some(Vec::new())); assert_eq!(Parachains::ingress(ParaId::from(99)), Some(Vec::new())); assert!(Parachains::dispatch( Call::set_heads(vec![candidate_a, candidate_b]), thiolliere's avatar thiolliere committed Origin::NONE, ).is_ok()); assert_eq!( Parachains::ingress(ParaId::from(1)), Some(vec![(0.into(), [1; 32].into())]), ); assert_eq!( Parachains::ingress(ParaId::from(99)), Some(vec![(1.into(), [1; 32].into())]), ); assert_ok!(Parachains::deregister_parachain(1u32.into())); // after deregistering, there is no ingress to 1 and we stop routing // from 1. assert_eq!(Parachains::ingress(ParaId::from(1)), None); assert_eq!(Parachains::ingress(ParaId::from(99)), Some(Vec::new())); }); } #[test] fn egress_routed_to_non_existent_parachain_is_rejected() { // That no parachain is routed to which doesn't exist let parachains = vec![ (0u32.into(), vec![], vec![]), (1u32.into(), vec![], vec![]), ]; with_externalities(&mut new_test_ext(parachains), || { // parachain 99 does not exist let non_existent = vec![(99.into(), [1; 32].into())]; let mut candidate = new_candidate_with_egress_roots(non_existent); make_attestations(&mut candidate); let result = Parachains::dispatch( Call::set_heads(vec![candidate.clone()]), thiolliere's avatar thiolliere committed Origin::NONE, ); assert_eq!(Err("Routing to non-existent parachain"), result); }); } #[test] fn egress_routed_to_self_is_rejected() { // That the parachain doesn't route to self let parachains = vec![ (0u32.into(), vec![], vec![]), (1u32.into(), vec![], vec![]), ]; with_externalities(&mut new_test_ext(parachains), || { // parachain 0 is self let to_self = vec![(0.into(), [1; 32].into())]; let mut candidate = new_candidate_with_egress_roots(to_self); make_attestations(&mut candidate); let result = Parachains::dispatch( Call::set_heads(vec![candidate.clone()]), thiolliere's avatar thiolliere committed Origin::NONE, ); assert_eq!(Err("Parachain routing to self"), result); }); } #[test] fn egress_queue_roots_out_of_order_rejected() { // That the list of egress queue roots is in ascending order by `ParaId`. let parachains = vec![ (0u32.into(), vec![], vec![]), (1u32.into(), vec![], vec![]), ]; with_externalities(&mut new_test_ext(parachains), || { // parachain 0 is self let out_of_order = vec![(1.into(), [1; 32].into()), ((0.into(), [1; 32].into()))]; let mut candidate = new_candidate_with_egress_roots(out_of_order); make_attestations(&mut candidate); let result = Parachains::dispatch( Call::set_heads(vec![candidate.clone()]), thiolliere's avatar thiolliere committed Origin::NONE, ); assert_eq!(Err("Egress routes out of order by ID"), result); }); } #[test] fn egress_queue_roots_empty_trie_roots_rejected() { let parachains = vec![ (0u32.into(), vec![], vec![]), (1u32.into(), vec![], vec![]), (2u32.into(), vec![], vec![]), ]; with_externalities(&mut new_test_ext(parachains), || { // parachain 0 is self let contains_empty_trie_root = vec![(1.into(), [1; 32].into()), ((2.into(), EMPTY_TRIE_ROOT.into()))]; let mut candidate = new_candidate_with_egress_roots(contains_empty_trie_root); make_attestations(&mut candidate); let result = Parachains::dispatch( Call::set_heads(vec![candidate.clone()]), thiolliere's avatar thiolliere committed Origin::NONE, ); assert_eq!(Err("Empty trie root included"), result); }); } #[test] For faster browsing, not all history is shown. View entire blame
__label__pos
0.967653
Awesome Open Source Awesome Open Source Maven Central GitHub release license Why async-await? Asynchronous programming has long been a useful way to perform operations that don’t necessarily need to hold up the flow or responsiveness of an application. Generally, these are either compute-bound operations or I/O bound operations. Compute-bound operations are those where computations can be done on a separate thread, leaving the main thread to continue its own processing, while I/O bound operations involve work that takes place externally and may not need to block a thread while such work takes place. Common examples of I/O bound operations are file and network operations. Traditional asynchronous programming involves using callbacks these are executed on operation completion. The API differs across languages and libraries, but the idea is always the same: you are firing some asynchronous operation, get back some kind of Promise as a result and attach success/failure calbacks that are executed once asynchronous operation is completed. However, these approach is associated numerous hardships: 1. You should explicitly pass contextual variables to callbacks. Sure, you can use lambdas to capture lexical context, but this does not eliminate the problem completly. And sometimes even sacrifies readability of the code - when you have a lot of lambda functions with complex body. 2. Coordination of asynchronous operations with callbacks is dificult: any branching logic inside the chain of asynchronous callbacks is a pain; resource management provided by try-with-resources constructs are not possible with asynchronous callbacks as well as many other control flow statements; handling failures is radically different from the familiar try/catch used in synchronous code. 3. Different callbacks are executed on different threads. Hence special care should be taken where the application flow resumes. The issue is very critical when application runs in managed environment like JEE or UI framework (JavaFX, Swing, etc). To alleviate aforementioned readability and maintainability issues some languages provides async/await asynchronous programming model. This lets developer make asynchronous calls just as easily as she can invoke synchronous ones, with the tiny addition of a keyword await and without sacrifying any of asynchronous programming benefits. With await keyword asynchronous calls may be used inside regular control flow statements (including exception handling) as naturally as calls to synchronous methods. The list of the languages that support this model is steadly growing: C# 5, ECMAScript 7, Kotlin, Scala. Tascalate Async/Await library enables async/await model for projects built with the Java 8 and beyond. The implementation is based on continuations for Java and provides runtime API + bytecode enchancement tools to let developers use syntax constructs similar to C# 5 or ECMAScript 2017/2018 with pure Java. How to use? First, add Maven dependency to the library runtime: <dependency> <groupId>net.tascalate.async</groupId> <artifactId>net.tascalate.async.runtime</artifactId> <version>1.0.0</version> </dependency> Second, add the following build plugins in the specified order: <build> <plugins> <plugin> <groupId>net.tascalate.async</groupId> <artifactId>net.tascalate.async.tools.maven</artifactId> <version>1.0.0</version> <executions> <execution> <phase>process-classes</phase> <goals> <goal>tascalate-async-enhance</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>net.tascalate.javaflow</groupId> <artifactId>net.tascalate.javaflow.tools.maven</artifactId> <version>2.3.1</version> <executions> <execution> <phase>process-classes</phase> <goals> <goal>javaflow-enhance</goal> </goals> </execution> </executions> </plugin> </plugins> </build> You are ready to start coding! Asynchronous tasks The first type of functions the library supports is asycnhronous task. Asynchronous task is a method (either instance or class method) that is annotated with net.tascalate.async.async annotation and returns CompletionStage<T> or void. In the later case it is a "fire-and-forget" task that is intended primarly to be used for event handlers inside UI framework (like JavaFX or Swing). Let us write a simple example: import static net.tascalate.async.CallСontext.async; import static net.tascalate.async.CallСontext.await; import net.tascalate.async.async; import java.util.concurrent.CompletionStage; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; class MyClass { public @async CompletionStage<String> mergeStrings() { StringBuilder result = new StringBuilder(); for (int i = 1; i <= 10; i++) { String v = await( decorateStrings(i, "async ", " awaited") ); result.append(v).append('\n'); } return async(result.toString()); } public @async CompletionStage<String> decorateStrings(int i, String prefix, String suffix) { String value = prefix + await( produceString("value " + i) ) + suffix; return async(value); } // Emulate some asynchronous business service call private static CompletionStage<String> produceString(String value) { return CompletableFuture.supplyAsync(() -> value, executor); } private static final ExecutorService executor = Executors.newFixedThreadPool(4); } Thanks to statically imported methods of net.tascalate.async.CallСontext the code looks very close to the one developed with languages having native support for async/await. Both mergeStrings and decorateStrings are asynchronous methods -- they are marked with net.tascalate.async.async annotation and returns CompletionStage<T>. Inside these methods you may call await to suspend the method till the CompletionStage<T> supplied as the argument is resolved (either sucessfully or exceptionally). Please notice, that you can await for any CompletionStage<T> implementation obtained from different libraries - like inside the decorateStrings method, including pending result of another asynchronous method - like in mergeStrings. To return a result from the asynchronous method you have to use syntatic construct return async(value). You must always treat both of these statements (calling async method and return-ing its result) as the single syntatic construct and don't call async method separately or store it return value to variable while these will lead to unpredicatble results. It's especially important if your method body is not linear. Depending on your established coding practice how to deal with multiple returns you should use either... public @async CompletionStage<String> foo(int i) { switch (i) { case 1: return async("A"); case 2: return async("B"); case 3: return async("C"); default: return async("<UNKNOWN>"); } } ...or... public @async CompletionStage<String> bar(int i) { String result; switch (i) { case 1: result = "A"; break; case 2: result = "B"; break; case 3: result = "C"; break; default: result = "<UNKNOWN>"; } return async(result); } It's worth to mention, that when developing code with async/await you should avoid so-called "async/await hell". In short, pay special attention what parts of your code may be executed in parallel and what parts require serial execution. Consider the following example: public @async CompletionStage<Long> calculateTotalPrice(Order order) { Long rawItemsPrice = await( calculateRawItemsPrice(order) ); Long shippingCost = await( calculateShippingCost(order) ); Long taxes = await( calculateTaxes(order) ); return async(rawItemsPrice + shippingCost + taxes); } protected @async CompletionStage<Long> calculateRawItemsPrice(Order order) { ... } protected @async CompletionStage<Long> calculateShippingCost(Order order) { ... } protected @async CompletionStage<Long> calculateTaxes(Order order) { ... } In the above example all async methods calculateRawItemsPrice, calculateShippingCost, calculateTaxes are executed serially, one by one, hence the performance is degraded comparing to the following parallelized solution: public @async CompletionStage<Long> calculateTotalPrice(Order order) { CompletionStage<Long> rawItemsPrice = calculateRawItemsPrice(order); CompletionStage<Long> shippingCost = calculateShippingCost(order); CompletionStage<Long> taxes = calculateTaxes(order); return async( await(rawItemsPrice) + await(shippingCost) + await(taxes) ); } This way all inner async operations are started (almost) simualtenously and are running in parallel, unlike in the first example. Generators Suspendable methods Scheduler - where is my code executed? SchedulerResolver - what Scheduler to use? Get A Weekly Email With Trending Projects For These Topics No Spam. Unsubscribe easily at any time. java (30,358 async (463 coroutines (175 async-await (86 asynchronous-programming (27 concurrent-programming (26 Find Open Source By Browsing 7,000 Topics Across 59 Categories
__label__pos
0.983322
json-msg-react Make form validation easier Usage no npm install needed! <script type="module"> import jsonMsgReact from 'https://cdn.skypack.dev/json-msg-react'; </script> README React json-msg logo json-msg-react NPM JavaScript Style Guide This might be similar to Formik but in a hook form , and this is also use json-msg as a validator. Json-msg is a lightweight alternative for yup and joi or any other schema validator. Prerequisite • Basic knowledge of json-msg for building schema Check json-msg documentation here Install npm install json-msg-react or yarn add json-msg-react Usage import React from "react"; import jm, { useForm } from "json-msg-react"; const schema = { username: jm.str({ min: 5 }), password: jm.str({ min: 8, max: 40 }), pin: jm.num({ digit: 4 }), }; const initialData = { username: "", password: "", pin: 0, }; const Example = () => { const { handleChange, handleSubmit, errors } = useForm(initialData, schema); function submit(data) { console.log(data); } return ( <> <form onSubmit={handleSubmit(submit)}> <input name="username" onChange={handleChange} /> {errors.username && <p> {errors.username} </p>} <input name="password" type="password" onChange={handleChange} /> {errors.username && <p> {errors.username} </p>} <input name="pin" type="number" onChange={handleChange} /> {errors.password && <p> {errors.password} </p>} </form> </> ); }; API useForm(initialData,schema, option) • initialData:? Object • schema:? Object option type default description showAllErrors boolean false Show all the errors in array form trim boolean false Trim all the string in the data validateOnChange boolean true Validate on change the data validateOnMount boolean false Validate the data on mount
__label__pos
0.972502
How to Install Darktable on Ubuntu Follow us Install Darktable In the realm of digital photography, image editing plays a pivotal role in bringing out the best in captured moments. Ubuntu, being a popular Linux distribution, offers a robust platform for creative individuals seeking powerful photo editing tools. One such tool is Darktable, an open-source photography workflow application that empowers users with a wide range of features for enhancing and refining their images. In this article, we will guide you through the seamless process of installing Darktable on your Ubuntu system, ensuring you have access to a professional-grade photo editing experience. Install Darktable Ubuntu Step-by-Step Guide to Installing Darktable on Ubuntu: 1. Update Your System: Before diving into the installation process, ensure that your Ubuntu system is up-to-date. Open a terminal and run the following commands: sudo apt update sudo apt upgrade 2. Install Darktable: Darktable is readily available in the official Ubuntu repositories. Execute the following command to install it: sudo apt install darktable 3. Launch Darktable: Once the installation is complete, you can launch Darktable either through the application menu or by using the terminal: darktable In conclusion, installing Darktable on your Ubuntu system opens up a world of possibilities for photo editing. This comprehensive guide has walked you through the installation process and highlighted some key features of Darktable. Whether you're a photography enthusiast or a professional, Darktable on Ubuntu provides a powerful and flexible platform to unleash your creative potential. Start exploring the endless possibilities of photo editing with Darktable today. How to Install Darktable on Ubuntu How to Download Songs on Spotify ID Telegram Yang Mana? Cara Mencari Id Telegram How to Turn Off Notifications for Apps on iPhone Simple Python Script Example With Main © 2024 MyPurTech
__label__pos
0.96356
Skip over navigation Contents Introduction to Trees Summary and Introduction to Trees Table of Contents Terms A major skill in computer programming is understanding how to work with data. The simplest way to store data is in a simple variable: int my_int = 3; A slightly more complicated storage mechanism is the array: int my_array[MAX_SIZE]; Trees are simply another way of arranging and storing the data. Trees get their name because the general shape of the structure (if you draw it out) resembles a tree. All of the elements in the tree are called nodes. Just like a family tree, there is one node from which all the other nodes descend. This is the root node. Each of the descendents can also have descendents. In other words, each child of the root can be seen as the root of its own tree. It is in this way that a tree is naturally recursive. This means that at each level, we find essentially the same structure. If you pick any node in the tree and consider from it down, you still have a tree. Even if you pick a leaf, you have a tree, albeit a branchless one. The next question is when and why you might want to use such a structure. There are situations in which the data itself can naturally be thought of as a tree. Such an example is a family genealogy, where each person is always a child of someone else and has the potential to have children. In addition, there are many situations where trees make implementing certain algorithms very simple. In the section on binary search trees we will see such an application. The fact that the data in a tree is arranged hierarchically makes it easier (quicker in terms of the number of branches between the root and any other node) to access nodes. This makes a tree a very appropriate structure for holding data that must be searched often.
__label__pos
0.998074
Browse Source WIP: remove charger i2c comms for ref2d3 master mntmn 1 year ago parent commit 7351f1f4f1 1 changed files with 29 additions and 86 deletions 1. +29 -86   src/boards/reform2/board_reform2.c + 29 - 86 src/boards/reform2/board_reform2.c View File @@ -28,7 +28,7 @@ #include "protocol/protocol.h" #endif //#define REF2_DEBUG #define REF2_DEBUG 0 #define INA260_ADDRESS 0x4e #define LTC4162F_ADDRESS 0x68 @@ -159,8 +159,12 @@ void measure_cell_voltages_and_control_discharge() { spir[1] = 0xc7; spir[2] = 0xe1; // set cdc to 2 = continuous measurement spir[3] = discharge_bits&0xff; // first 8 bits of discharge switches spir[4] = (discharge_bits&0x700)>>8; // last 4 bits of discharge switches //spir[3] = discharge_bits&0xff; // first 8 bits of discharge switches //spir[4] = (discharge_bits&0x700)>>8; // last 4 bits of discharge switches spir[3] = 0x0; spir[4] = 0x0; spir[5] = 0x0; spir[6] = 0x0; spir[7] = 0x0; @@ -296,84 +300,21 @@ float chg_vin; float chg_vbat; void configure_charger(int charge_current) { // disable jeita i2c_write16_be(LTC4162F_ADDRESS, 0x29, 0); // set charge current i2c_write16_be(LTC4162F_ADDRESS, 0x1a, charge_current); // disable max_cv_time i2c_write16_be(LTC4162F_ADDRESS, 0x1d, 0); // set charge voltage // 27 = 30V // default 31 = 28.8V i2c_write16_be(LTC4162F_ADDRESS, 0x1b, 31); if (charge_current > 0) { // config_bits_reg: unsuspend charger i2c_write16_be(LTC4162F_ADDRESS, 0x14, 0); } else { // config_bits_reg: suspend charger i2c_write16_be(LTC4162F_ADDRESS, 0x14, 1<<5); } // set recharge threshold // signed 16-bit number, max 32767! default 17424 i2c_write16_be(LTC4162F_ADDRESS, 0x2e, 30000); // read some charger regs charger_state = i2c_read16_be(LTC4162F_ADDRESS, 0x34); charge_status = i2c_read16_be(LTC4162F_ADDRESS, 0x35); limit_alerts = i2c_read16_be(LTC4162F_ADDRESS, 0x36); charger_alerts = i2c_read16_be(LTC4162F_ADDRESS, 0x37); status_alerts = i2c_read16_be(LTC4162F_ADDRESS, 0x38); system_status = i2c_read16_be(LTC4162F_ADDRESS, 0x39); chg_vbat = i2c_read16_be(LTC4162F_ADDRESS, 0x3a); chg_vin = i2c_read16_be(LTC4162F_ADDRESS, 0x3b); float chg_vout = i2c_read16_be(LTC4162F_ADDRESS, 0x3c); //float chg_ibat = i2c_read16_be(LTC4162F_ADDRESS, 0x3d); //float chg_iin = i2c_read16_be(LTC4162F_ADDRESS, 0x3e); //int16_t chg_chem = (i2c_read16_be(LTC4162F_ADDRESS, 0x43) >> 8) & 0xf; //int16_t chg_cell_count = (i2c_read16_be(LTC4162F_ADDRESS, 0x43)) & 0xf; //uint16_t tchargetimer = i2c_read16_be(LTC4162F_ADDRESS, 0x30); //uint16_t tcvtimer = i2c_read16_be(LTC4162F_ADDRESS, 0x31); //uint16_t tabsorbtimer = i2c_read16_be(LTC4162F_ADDRESS, 0x32); chg_vin*=1.649; chg_vbat*=(8.0*0.1924); chg_vout*=1.653; #ifdef REF2_DEBUG sprintf(uartBuffer,"ltc state: %x status: %x system: %x\r\n",charger_state,charge_status,system_status); uartSend((uint8_t *)uartBuffer, strlen(uartBuffer)); #endif //sprintf(uartBuffer,"ltc vbat: %f vin: %f vout: %f\r\n",chg_vbat,chg_vin,chg_vout); //uartSend((uint8_t *)uartBuffer, strlen(uartBuffer)); //sprintf(uartBuffer,"ltc chemistry: %d cell count: %d\r\n",chg_chem,chg_cell_count); //uartSend((uint8_t *)uartBuffer, strlen(uartBuffer)); //sprintf(uartBuffer,"config: jeita: %d thermal_reg: %d ilim_reg: %d vin_uvcl: %d iin_limit: %d\r\n",charger_config&1, !!(charge_status&16), !!(charge_status&32), !!(charge_status&8), !!(charge_status&4)); //uartSend((uint8_t *)uartBuffer, strlen(uartBuffer)); //sprintf(uartBuffer,"tchgt: %d tcvt: %d tabsorbt: %d\r\n\r\n",tchargetimer,tcvtimer,tabsorbtimer); //uartSend((uint8_t *)uartBuffer, strlen(uartBuffer)); } void turn_som_power_on(void) { LPC_GPIO->CLR[1] = (1 << 16); // 3v3, low = on LPC_GPIO->CLR[0] = (1 << 20); // PCIe, low = on LPC_GPIO->SET[1] = (1 << 16); // 3v3, high = on // FIXME this turns 1v5 off :/ LPC_GPIO->SET[0] = (1 << 20); // PCIe, low = on LPC_GPIO->SET[1] = (1 << 15); // 5v, high = on LPC_GPIO->SET[1] = (1 << 19); // 1v2, high = on } void turn_som_power_off(void) { LPC_GPIO->CLR[1] = (1 << 19); // 1v2, high = on LPC_GPIO->CLR[1] = (1 << 15); // 5v, high = on LPC_GPIO->SET[0] = (1 << 20); // PCIe, low = on LPC_GPIO->SET[1] = (1 << 16); // 3v3, low = on LPC_GPIO->CLR[0] = (1 << 20); // PCIe, low = on LPC_GPIO->CLR[1] = (1 << 16); // 3v3, high = on // FIXME experiment: temp. disable charger to reset its timers configure_charger(0); @@ -423,10 +364,12 @@ void boardInit(void) LPC_GPIO->DIR[1] |= (1 << 15); // 3V3 rail transistor on/off LPC_GPIO->DIR[1] |= (1 << 16); // 1V2 regulator on/off LPC_GPIO->DIR[1] |= (1 << 19); // PCIe 1 power supply transistor LPC_GPIO->DIR[0] |= (1 << 20); turn_som_power_off(); turn_som_power_on(); uartInit(CFG_UART_BAUDRATE); i2cInit(I2CMASTER); @@ -439,16 +382,18 @@ void boardInit(void) // SPI chip select LPC_GPIO->DIR[1] |= (1 << 23); LPC_GPIO->SET[1] = (1 << 23); // active low //sprintf(uartBuffer, "\r\nMNT Reform 2.0 MCU initialized.\r\n"); //uartSend((uint8_t*)uartBuffer, strlen(uartBuffer)); #ifdef REF2_DEBUG sprintf(uartBuffer, "\r\nMNT Reform 2.0 MCU initialized.\r\n"); uartSend((uint8_t*)uartBuffer, strlen(uartBuffer)); #endif } char remote_cmd = 0; uint8_t remote_arg = 0; unsigned char cmd_state = ST_EXPECT_DIGIT_0; unsigned int cmd_number = 0; int cmd_echo = 0; int cmd_echo = 1; void handle_commands() { if (!uartRxBufferDataPending()) return; @@ -608,17 +553,15 @@ void handle_commands() { int main(void) { boardInit(); reset_discharge_bits(); //reset_discharge_bits(); state = ST_CHARGE; cycles_in_state = 0; delay(500); last_second = delayGetSecondsActive(); // WIP, not yet tested watchdog_setup(); //watchdog_setup(); //sprintf(uartBuffer, "\r\nwatchdog_setup() completed.\r\n"); //uartSend((uint8_t*)uartBuffer, strlen(uartBuffer)); @@ -636,12 +579,12 @@ int main(void) // charge current 2: ~0.2A watchdog_feed(); //watchdog_feed(); measure_and_accumulate_current(); measure_cell_voltages_and_control_discharge(); if (state == ST_CHARGE) { /*if (state == ST_CHARGE) { configure_charger(charge_current); if (cycles_in_state > 5) { @@ -692,7 +635,7 @@ int main(void) cycles_in_state = 0; } } } }*/ handle_commands(); cur_second = delayGetSecondsActive();
__label__pos
0.919058
Vim documentation: vim_diff main help file *vim_diff.txt* Nvim NVIM REFERENCE MANUAL Differences between Nvim and Vim *vim-differences* Nvim differs from Vim in many ways, big and small. This document is a complete and centralized reference of those differences. Type |gO| to see the table of contents. ============================================================================== 1. Configuration *nvim-configuration* - Use `$XDG_CONFIG_HOME/nvim/init.vim` instead of `.vimrc` for storing configuration. - Use `$XDG_CONFIG_HOME/nvim` instead of `.vim` to store configuration files. - Use `$XDG_DATA_HOME/nvim/shada/main.shada` instead of `.viminfo` for persistent session information. ============================================================================== 2. Defaults *nvim-defaults* - Syntax highlighting is enabled by default - ":filetype plugin indent on" is enabled by default - 'autoindent' is set by default - 'autoread' is set by default - 'backspace' defaults to "indent,eol,start" - 'backupdir' defaults to .,~/.local/share/nvim/backup (|xdg|) - 'belloff' defaults to "all" - 'complete' doesn't include "i" - 'directory' defaults to ~/.local/share/nvim/swap// (|xdg|), auto-created - 'display' defaults to "lastline" - 'formatoptions' defaults to "tcqj" - 'history' defaults to 10000 (the maximum) - 'hlsearch' is set by default - 'incsearch' is set by default - 'langnoremap' is enabled by default - 'langremap' is disabled by default - 'laststatus' defaults to 2 (statusline is always shown) - 'listchars' defaults to "tab:> ,trail:-,nbsp:+" - 'nocompatible' is always set - 'nrformats' defaults to "bin,hex" - 'ruler' is set by default - 'sessionoptions' doesn't include "options" - 'showcmd' is set by default - 'smarttab' is set by default - 'tabpagemax' defaults to 50 - 'tags' defaults to "./tags;,tags" - 'ttyfast' is always set - 'undodir' defaults to ~/.local/share/nvim/undo (|xdg|), auto-created - 'viminfo' includes "!" - 'wildmenu' is set by default ============================================================================== 3. New Features *nvim-features* MAJOR COMPONENTS API |API| Lua scripting |lua| Job control |job-control| Remote plugins |remote-plugin| Providers Clipboard |provider-clipboard| Python plugins |provider-python| Ruby plugins |provider-ruby| Shared data |shada| Embedded terminal |terminal| XDG base directories |xdg| USER EXPERIENCE Working intuitively and consistently is a major goal of Nvim. *feature-compile* - Nvim always includes ALL features, in contrast to Vim (which ships with various combinations of 100+ optional features). Think of it as a leaner version of Vim's "HUGE" build. This reduces surface area for bugs, and removes a common source of confusion and friction for users. - Nvim avoids features that cannot be provided on all platforms; instead that is delegated to external plugins/extensions. E.g. the `-X` platform-specific option is "sometimes" available in Vim (with potential surprises: http://stackoverflow.com/q/14635295. - Vim's internal test functions (test_autochdir(), test_settime(), etc.) are not exposed (nor implemented); instead Nvim has a robust API. - Behaviors, options, documentation are removed if they cost users more time than they save. Usability details have been improved where the benefit outweighs any backwards-compatibility cost. Some examples: - |K| in help documents can be used like |CTRL-]|. - Directories for 'directory' and 'undodir' are auto-created. - Terminal features such as 'guicursor' are enabled where possible. ARCHITECTURE External plugins run in separate processes. |remote-plugin| This improves stability and allows those plugins to work without blocking the editor. Even "legacy" Python and Ruby plugins which use the old Vim interfaces (|if_py| and |if_ruby|) run out-of-process. Platform and I/O facilities are built upon libuv. Nvim benefits from libuv features and bug fixes, and other projects benefit from improvements to libuv by Nvim developers. FEATURES "Outline": Type |gO| in |:Man| and |:help| pages to see a document outline. |META| (ALT) chords are recognized, even in the terminal. Any |<M-| mapping will work. Some examples: <M-1>, <M-2>, <M-BS>, <M-Del>, <M-Ins>, <M-/>, <M-\>, <M-Space>, <M-Enter>, <M-=>, <M-->, <M-?>, <M-$>, ... META chords are case-sensitive: <M-a> and <M-A> are two different keycodes. Some `CTRL-SHIFT-...` key chords are distinguished from `CTRL-...` variants (even in the terminal). Specifically, the following are known to work: <C-Tab>, <C-S-Tab>, <C-BS>, <C-S-BS>, <C-Enter>, <C-S-Enter> Options: 'cpoptions' flags: |cpo-_| 'guicursor' works in the terminal 'inccommand' shows interactive results for |:substitute|-like commands 'scrollback' 'statusline' supports unlimited alignment sections 'tabline' %@[email protected]%X can call any function on mouse-click 'winhighlight' window-local highlights Variables: |v:event| |v:exiting| |v:progpath| is always absolute ("full") |v:windowid| is always available (for use by external UIs) Commands: |:checkhealth| |:drop| is available on all platforms |:Man| is available by default, with many improvements such as completion |:tchdir| tab-local |current-directory| Functions: |dictwatcheradd()| notifies a callback whenever a |Dict| is modified |dictwatcherdel()| |menu_get()| |msgpackdump()|, |msgpackparse()| provide msgpack de/serialization Events: |DirChanged| |TabNewEntered| |TermClose| |TermOpen| |TextYankPost| Highlight groups: |hl-NormalNC| highlights non-current windows |hl-QuickFixLine| |hl-Substitute| |hl-TermCursor| |hl-TermCursorNC| |hl-Whitespace| highlights 'listchars' whitespace |expr-highlight| highlight groups (prefixed with "Nvim") Command-line highlighting: The expression prompt (|@=|, |c_CTRL-R_=|, |i_CTRL-R_=|) is highlighted using a built-in VimL expression parser. |expr-highlight| *E5408* *E5409* |input()|, |inputdialog()| support custom highlighting. |input()-highlight| *g:Nvim_color_cmdline* (Experimental) Command-line (|:|) is colored by callback defined in `g:Nvim_color_cmdline` (this callback is for testing only, and will be removed in the future). ============================================================================== 4. Changed features *nvim-features-changed* Nvim always builds with all features, in contrast to Vim which may have certain features removed/added at compile-time. This is like if Vim's "HUGE" build was the only Vim release type (except Nvim is smaller than Vim's "HUGE" build). If a Python interpreter is available on your `$PATH`, |:python| and |:python3| are always available and may be used simultaneously in separate plugins. The `neovim` pip package must be installed to use Python plugins in Nvim (see |provider-python|). Because of general |256-color| usage whereever possible, Nvim will even use 256-colour capability on Linux virtual terminals. Vim uses only 8 colours plus bright foreground on Linux VTs. Vim combines what is in its |builtin-terms| with what it reads from termcap, and has a |ttybuiltin| setting to control how that combination works. Nvim uses either one or the other of an external |terminfo| entry or the built-in one. It does not attempt to mix data from the two. |:!| does not support "interactive" commands. Use |:terminal| instead. (GUI Vim has a similar limitation, see ":help gui-pty" in Vim.) |system()| does not support writing/reading "backgrounded" commands. |E5677| |:redir| nested in |execute()| works. Nvim may throttle (skip) messages from shell commands (|:!|, |:grep|, |:make|) if there is too much output. No data is lost, this only affects display and makes things faster. |:terminal| output is never throttled. |mkdir()| behaviour changed: 1. Assuming /tmp/foo does not exist and /tmp can be written to mkdir('/tmp/foo/bar', 'p', 0700) will create both /tmp/foo and /tmp/foo/bar with 0700 permissions. Vim mkdir will create /tmp/foo with 0755. 2. If you try to create an existing directory with `'p'` (e.g. mkdir('/', 'p')) mkdir() will silently exit. In Vim this was an error. 3. mkdir() error messages now include strerror() text when mkdir fails. 'encoding' is always "utf-8". |string()| and |:echo| behaviour changed: 1. No maximum recursion depth limit is applied to nested container structures. 2. |string()| fails immediately on nested containers, not when recursion limit was exceeded. 2. When |:echo| encounters duplicate containers like let l = [] echo [l, l] it does not use "[...]" (was: "[[], [...]]", now: "[[], []]"). "..." is only used for recursive containers. 3. |:echo| printing nested containers adds "@level" after "..." designating the level at which recursive container was printed: |:echo-self-refer|. Same thing applies to |string()| (though it uses construct like "{[email protected]}"), but this is not reliable because |string()| continues to error out. 4. Stringifyed infinite and NaN values now use |str2float()| and can be evaled back. 5. (internal) Trying to print or stringify VAR_UNKNOWN in Vim results in nothing, |E908|, in Neovim it is internal error. |json_decode()| behaviour changed: 1. It may output |msgpack-special-dict|. 2. |msgpack-special-dict| is emitted also in case of duplicate keys, while in Vim it errors out. 3. It accepts only valid JSON. Trailing commas are not accepted. |json_encode()| behaviour slightly changed: now |msgpack-special-dict| values are accepted, but |v:none| is not. *v:none* variable is absent. In Vim it represents “no value” in “js” strings like "[,]" parsed as "[v:none]" by |js_decode()|. *js_encode()* and *js_decode()* functions are also absent. Viminfo text files were replaced with binary (messagepack) ShaDa files. Additional differences: - |shada-c| has no effect. - |shada-s| now limits size of every item and not just registers. - 'viminfo' option got renamed to 'shada'. Old option is kept as an alias for compatibility reasons. - |:wviminfo| was renamed to |:wshada|, |:rviminfo| to |:rshada|. Old commands are still kept. - ShaDa file format was designed with forward and backward compatibility in mind. |shada-compatibility| - Some errors make ShaDa code keep temporary file in-place for user to decide what to do with it. Vim deletes temporary file in these cases. |shada-error-handling| - ShaDa file keeps search direction (|v:searchforward|), viminfo does not. |printf()| returns something meaningful when used with `%p` argument: in Vim it used to return useless address of the string (strings are copied to the newly allocated memory all over the place) and fail on types which cannot be coerced to strings. See |id()| for more details, currently it uses `printf("%p", {expr})` internally. |c_CTRL-R| pasting a non-special register into |cmdline| omits the last <CR>. Lua interface (|if_lua.txt|): - `:lua print("a\0b")` will print `a^@b`, like with `:echomsg "a\nb"` . In Vim that prints `a` and `b` on separate lines, exactly like `:lua print("a\nb")` . - `:lua error('TEST')` will print “TEST” as the error in Vim and “E5105: Error while calling lua chunk: [string "<VimL compiled string>"]:1: TEST” in Neovim. - Lua has direct access to Nvim |API| via `vim.api`. - Lua package.path and package.cpath are automatically updated according to 'runtimepath': |lua-require|. |input()| and |inputdialog()| support for each other’s features (return on cancel and completion respectively) via dictionary argument (replaces all other arguments if used). |input()| and |inputdialog()| support user-defined cmdline highlighting. Highlight groups: |hl-ColorColumn|, |hl-CursorColumn| are lower priority than most other groups VimL (Vim script) compatibility: `count` does not alias to |v:count| ============================================================================== 5. Missing legacy features *nvim-features-missing* Some legacy Vim features are not implemented: - |if_py|: vim.bindeval() and vim.Function() are not supported - |if_lua|: the `vim` object is missing most legacy methods - *if_perl* - *if_mzscheme* - *if_tcl* ============================================================================== 6. Removed features *nvim-features-removed* These Vim features were intentionally removed from Nvim. *'cp'* *'nocompatible'* *'nocp'* *'compatible'* Nvim is always "non-compatible" with Vi. ":set nocompatible" is ignored ":set compatible" is an error *'ed'* *'edcompatible'* *'noed'* *'noedcompatible'* Ed-compatible mode: ":set noedcompatible" is ignored ":set edcompatible" is an error *t_xx* *termcap-options* *t_AB* *t_Sb* *t_vb* *t_SI* Nvim does not have special `t_XX` options nor <t_XX> keycodes to configure terminal capabilities. Instead Nvim treats the terminal as any other UI. For example, 'guicursor' sets the terminal cursor style if possible. *:set-termcap* Start Nvim with 'verbose' level 3 to see the terminal capabilities. nvim -V3 *'term'* *E529* *E530* *E531* 'term' reflects the terminal type derived from |$TERM| and other environment checks. For debugging only; not reliable during startup. :echo &term "builtin_x" means one of the |builtin-terms| was chosen, because the expected terminfo file was not found on the system. *termcap* Nvim never uses the termcap database, only |terminfo| and |builtin-terms|. *xterm-8bit* *xterm-8-bit* Xterm can be run in a mode where it uses true 8-bit CSI. Supporting this requires autodetection of whether the terminal is in UTF-8 mode or non-UTF-8 mode, as the 8-bit CSI character has to be written differently in each case. Vim issues a "request version" sequence to the terminal at startup and looks at how the terminal is sending CSI. Nvim does not issue such a sequence and always uses 7-bit control sequences. 'ttyfast': ":set ttyfast" is ignored ":set nottyfast" is an error Encryption support: *'cryptmethod'* *'cm'* *'key'* MS-DOS support: 'bioskey' 'conskey' Test functions: test_alloc_fail() test_autochdir() test_disable_char_avail() test_garbagecollect_now() test_null_channel() test_null_dict() test_null_job() test_null_list() test_null_partial() test_null_string() test_settime() Other options: 'antialias' 'cpoptions' (g j k H w < * - and all POSIX flags were removed) 'encoding' ("utf-8" is always used) 'esckeys' 'guioptions' "t" flag was removed *'guipty'* (Nvim uses pipes and PTYs consistently on all platforms.) 'highlight' (Names of builtin |highlight-groups| cannot be changed.) *'imactivatefunc'* *'imaf'* *'imactivatekey'* *'imak'* *'imstatusfunc'* *'imsf'* *'macatsui'* *'restorescreen'* *'rs'* *'norestorescreen'* *'nors'* 'shelltype' *'shortname'* *'sn'* *'noshortname'* *'nosn'* *'swapsync'* *'sws'* *'termencoding'* *'tenc'* (Vim 7.4.852 also removed this for Windows) 'textauto' 'textmode' *'toolbar'* *'tb'* *'toolbariconsize'* *'tbis'* *'ttybuiltin'* *'tbi'* *'nottybuiltin'* *'notbi'* *'ttymouse'* *'ttym'* *'ttyscroll'* *'tsl'* *'ttytype'* *'tty'* 'weirdinvert' Other commands: :Print :fixdel :helpfind :mode (no longer accepts an argument) :open :shell :smile :tearoff Other compile-time features: EBCDIC Emacs tags support X11 integration (see |x11-selection|) Nvim does not have a built-in GUI and hence the following aliases have been removed: gvim, gex, gview, rgvim, rgview "Easy mode" (eview, evim, nvim -y) "(g)vimdiff" (alias for "(g)nvim -d" |diff-mode|) "Vi mode" (nvim -v) The ability to start nvim via the following aliases has been removed in favor of just using their command line arguments: ex nvim -e exim nvim -E view nvim -R rvim nvim -Z rview nvim -RZ ============================================================================== top - main help file
__label__pos
0.950909
Mappings for External Sources-oracle Field type mismatch Hi everyone, The data source of oracle is configured in dremio, and the table is awh_ Test, field name is A, field type is VARCHAR2 (30) Execute " desc awh_test " in SQL Runner; The type of A found is displayed as CHARACTER VARYING Testing the dremio environment: version 22 Document description on official website: VARCHAR2 (Oracle Data Type) —>>>VARCHAR (Dremio Type) is inconsistent. How do I explain this inconsistency I’m not sure I understand your question, but I think you might be wondering why DESC shows “CHARACTER VARYING” but Dremio docs say it should be VARCHAR? If so, the answer is that VARCHAR and CHARACTER VARYING are the same thing. Your understanding is correct. Thank you for your reply
__label__pos
0.916571
/* * Copyright (C) 2020 Max-Planck-Society * Author: Martin Reinecke */ #include #include #include #include #include "mr_util/math/constants.h" #include "mr_util/math/gl_integrator.h" #include "mr_util/math/es_kernel.h" #include "mr_util/infra/mav.h" #include "mr_util/sharp/sharp.h" #include "mr_util/sharp/sharp_almhelpers.h" #include "mr_util/sharp/sharp_geomhelpers.h" #include "alm.h" #include "mr_util/math/fft.h" #include "mr_util/bindings/pybind_utils.h" using namespace std; using namespace mr; namespace py = pybind11; namespace { template class Interpolator { protected: size_t lmax, kmax, nphi0, ntheta0, nphi, ntheta; double ofactor; size_t supp; ES_Kernel kernel; mav cube; // the data cube (theta, phi, 2*mbeam+1[, IQU]) void correct(mav &arr) { mav tmp({nphi,nphi}); auto tmp0=tmp.template subarray<2>({0,0},{nphi0, nphi0}); fmav ftmp0(tmp0); for (size_t i=0; i=nphi0) j2-=nphi0; tmp0.v(i2,j) = arr(i,j2); } // FFT to frequency domain on minimal grid r2r_fftpack(ftmp0,ftmp0,{0,1},true,true,1./(nphi0*nphi0),0); auto fct = kernel.correction_factors(nphi, nphi0, 0); for (size_t i=0; i({0,0},{nphi, nphi0}); fmav ftmp1(tmp1); // zero-padded FFT in theta direction r2r_fftpack(ftmp1,ftmp1,{0},false,false,1.,0); auto tmp2=tmp.template subarray<2>({0,0},{ntheta, nphi}); fmav ftmp2(tmp2); fmav farr(arr); // zero-padded FFT in phi direction r2r_fftpack(ftmp2,farr,{1},false,false,1.,0); } public: Interpolator(const Alm> &slmT, const Alm> &blmT, double epsilon) : lmax(slmT.Lmax()), kmax(blmT.Mmax()), nphi0(2*good_size_real(lmax+1)), ntheta0(nphi0/2+1), nphi(2*good_size_real(2*lmax+1)), ntheta(nphi/2+1), ofactor(double(nphi)/(2*lmax+1)), supp(ES_Kernel::get_supp(epsilon, ofactor)), kernel(supp, ofactor, 1), cube({ntheta+2*supp, nphi+2*supp, 2*kmax+1}) { MR_assert((supp<=ntheta) && (supp<=nphi), "support too large!"); MR_assert(slmT.Mmax()==lmax, "Sky lmax must be equal to Sky mmax"); MR_assert(blmT.Lmax()==lmax, "Sky and beam lmax must be equal"); Alm> a1(lmax, lmax), a2(lmax,lmax); auto ginfo = sharp_make_cc_geom_info(ntheta0,nphi0,0,cube.stride(1),cube.stride(0)); auto ainfo = sharp_make_triangular_alm_info(lmax,lmax,1); vectorlnorm(lmax+1); for (size_t i=0; i<=lmax; ++i) lnorm[i]=sqrt(4*pi/(2*i+1.)); for (size_t k=0; k<=kmax; ++k) { double spinsign = (k==0) ? 1. : -1.; for (size_t m=0; m<=lmax; ++m) { T mfac=T((m&1) ? -1.:1.); for (size_t l=m; l<=lmax; ++l) { if (l v1=slmT(l,m)*blmT(l,k), v2=conj(slmT(l,m))*blmT(l,k)*mfac; a1(l,m) = (v1+conj(v2)*mfac)*T(0.5*spinsign*lnorm[l]); if (k>0) { complex tmp = (v1-conj(v2)*mfac)*T(-spinsign*0.5*lnorm[l]); a2(l,m) = complex(-tmp.imag(), tmp.real()); } } } } size_t kidx1 = (k==0) ? 0 : 2*k-1, kidx2 = (k==0) ? 0 : 2*k; auto quadrant=k%4; if (quadrant&1) swap(kidx1, kidx2); auto m1 = cube.template subarray<2>({supp,supp,kidx1},{ntheta,nphi,0}); auto m2 = cube.template subarray<2>({supp,supp,kidx2},{ntheta,nphi,0}); if (k==0) sharp_alm2map(a1.Alms().data(), m1.vdata(), *ginfo, *ainfo, 0, nullptr, nullptr); else sharp_alm2map_spin(k, a1.Alms().data(), a2.Alms().data(), m1.vdata(), m2.vdata(), *ginfo, *ainfo, 0, nullptr, nullptr); correct(m1); if (k!=0) correct(m2); if ((quadrant==1)||(quadrant==2)) m1.apply([](T &v){v=-v;}); if ((k>0) &&((quadrant==0)||(quadrant==1))) m2.apply([](T &v){v=-v;}); } // fill border regions for (size_t i=0; i=nphi) j2-=nphi; cube.v(supp-1-i,j2+supp,k) = cube(supp+1+i,j+supp,k); cube.v(supp+ntheta+i,j2+supp,k) = cube(supp+ntheta-2-i, j+supp,k); } for (size_t i=0; i &ptg, mav &res) const { MR_assert(ptg.shape(0)==res.shape(0), "dimension mismatch"); MR_assert(ptg.shape(1)==3, "second dimension must have length 3"); vector wt(supp), wp(supp); vector psiarr(2*kmax+1); double delta = 2./supp; double xdtheta = (ntheta-1)/pi, xdphi = nphi/(2*pi); for (size_t i=0; i class PyInterpolator: public Interpolator { public: PyInterpolator(const py::array &slmT, const py::array &blmT, int64_t lmax, int64_t kmax, double epsilon) : Interpolator(Alm>(to_mav,1>(slmT), lmax, lmax), Alm>(to_mav,1>(blmT), lmax, kmax), epsilon) {} using Interpolator::interpolx; py::array interpol(const py::array &ptg) { auto ptg2 = to_mav(ptg); auto res = make_Pyarr({ptg2.shape(0)}); auto res2 = to_mav(res,true); interpolx(ptg2, res2); return res; } }; } // unnamed namespace PYBIND11_MODULE(interpol_ng, m) { using namespace pybind11::literals; py::class_> (m, "PyInterpolator") .def(py::init(), "sky"_a, "beam"_a, "lmax"_a, "kmax"_a, "epsilon"_a) .def ("interpol", &PyInterpolator::interpol, "ptg"_a); }
__label__pos
0.970477
Which category of the switches does meet the customer’s needs? A customer needs Layer 2 switches that provide basic functionality. In the future, this customer might need to use the switches’ CLI to configure VLAN and STP features.Which category of the switches does meet the customer’s needs? Question: Which category of the switches does meet the customer’s needs? Options: unmanaged managed VLAN-based software distributed switch Correct Answer The Correct Answer for this Question is managed Leave a Comment
__label__pos
0.999927
CSS QUOTES This property determines the type of quotation marks that will be used in a document. One or more quotation mark pairs are given, with the basic quotation characters being the left-most pair. Each subsequent pair represents the quotation characters used at progressively deeper element nesting contexts. Values of the ‘content’ property are used to specify where the open/close quotation marks should or should not occur – the “open-quote”, “close-quote”, “no-open-quote”, and “no-close-quote” values. “Open-quote” refers to the left (first) of a given pair of specified quotes, while “close-quote” refers to the second (right) quote character in the pair. Quotes can be skipped at a particular location by using the “no-close-quote” and “no-open-quote” value. In the event that the quote character nesting depth is not covered in the ‘quotes’ property specification, the last valid quotation pair set should be used. Example blockquote[lang-=fr] { quotes: "\201C" "\201D" } blockquote[lang-=en] { quotes: "\00AB" "\00BB" } blockquote:before { content: open-quote } blockquote:after { content: close-quote } Possible Values inherit: Explicitly sets the value of this property to that of the parent. none: The ‘open-quote’ and ‘close-quote’ values of the ‘content’ property produce no quotations marks. ([string] [string]): Values for the ‘open-quote’ and ‘close-quote’ values of the ‘content’ property are taken from this list of quote mark pairs. The first or possibly only) pair on the left represents the outermost level of quotation embedding, the pair to the right (if any) is the first level of quote embedding, etc.
__label__pos
0.903874
LogoMethodology of Window Management Jump To Main Content Jump Over Banner Home Jump Over Left Menu Window Management Overview Preface Acknowledgements Participants Contents 1 Introduction 2 Unix 3 Comparison 4 Ten Years 5 SunDew 6 Issues 7 Modular 8 Standards 9 Standards View 10 Structure 11 Partitioning 12 Low-Cost 13 Gosling 14 Issues 15 API WG 16 API WG 17 UI WG 18 UI WG 19 Arch WG 20 Arch WG 21 API Task Group 22 Structure Task Group 23 Future 24 Bibliography 25 Acronyms Return This site is best viewed using a browser with either native SVG support or an SVG Plug-in Access Key Details 2. Introducing Windows to Unix: User Expectations Colin Prosser 2.1 INTRODUCTION This talk is aimed at giving a general overview of the main issues to do with window managers without going into details. My position paper (see Chapter 10) raises many other issues, but my view was that these are probably best discussed in the Working Groups. The focus is on introducing windows to Unix environments because of the interest of the Alvey Programme in the problem of window managers under Unix systems. Considering windowing in Unix systems does, however, force a wider context on wind owing issues, and other or future operating systems should not be forgotten. 2.2 USER EXPECTATIONS When introducing windows to Unix environments we are trying to provide the user with good facilities. What will the user expect? Considering windowing in Unix systems from this point of view, five key expectations may be discerned: 1. Compatibility. The benefits of the windowing system should apply to existing (not just new) applications. The windowing system must provide an environment in which existing applications and commands continue to work unchanged. But it must do more than just that; it must also provide the means for enhancing those programs. There seem to be two methods of doing this. One way is through a better shell facility where a graphical interface provides general-purpose text-oriented command manipulation. Another way is to take an existing command or application and build a specialized graphical interface around it. The former approach is being investigated at RAL. The latter approach has been applied successfully, for example, by Office Workstations Limited who have produced a graphically oriented higher level debugger (called hld) based around sdb running on PNX. 2. Intercommunication. Windows enable several separate contexts to be presented in one overall context. It seems natural to allow operations to apply across the separate contexts as well as within contexts. This leads to the idea of being able to select from the output of an application running in one window and to supply this as input to an application running in another window. This concept is often called cut and paste between windows. A simple example might be to run 'Is' to obtain a directory listing in one window and to use this output to provide a filename as input to a program running in a different window. On systems known to the author, this sort of operation can only be applied to limited kinds of objects and frequently only to text. 3. Portability. There is an expectation of software portability among Unix systems. Similar considerations apply to applications using windowing facilities. How are we to achieve portability? We have to look at the problem in terms of variants of the same system as well as in terms of quite different systems. The SPY editor (see section 3.3.1) was quite difficult to port to different Unix systems. Why? What makes it easy, generally, to port things between versions of Unix systems? A standard programming interface is important in resolving this difficulty. We must tackle the issue of standards for windowing systems. Can we take GKS [28] as a basis for building or should we start again? There will be problems if we try to address too large a goal - look at CORE [24]. So should we go for a minimal system? These are some of the alternatives to be considered. 4. Distributed Systems. With networks of (possibly mixed) systems, use of windowing systems should apply elegantly network-wide. With networks, such as the Newcastle Connection on PERQs, we are confronted with a whole new set of problems. For example, PERQ PNX uses a window special file to associate a name in the filestore with a window, and the Newcastle Connection allows transparent access over the network. However, if you try to archive a window special file on a PERQ using a VAX archiver over the network, it may not work quite as expected if the VAX archiving system does not have any knowledge of that type of special file. We must account for applications not knowing about windows. As another example, what should happen if I perform a remote login from a PERQ to a SUN? What does it mean? What window system applies to that login session: the one on the PERQ or the one on the SUN? Issues such as these have yet to be tackled. 5. Graphical Toolkit. The programmer needs tools to assist effective exploitation of windowing capabilities, both to create new applications and to modify existing software. The notion of tools includes examples to follow which provide guidelines for good design. What graphical primitives should the system support in libraries and as system calls to provide a graphical toolkit? To give an idea of the richness of the toolkit I am contemplating, I would consider that most existing windowing packages for Unix systems, including PERQ PNX, are, at present, relatively bare of tools. That is not to say that high quality applications cannot be built with today's windowing systems. However, experience shows that it can take considerable effort. It would be difficult for the unskilled user to write, for example, SPY without any assistance. What is a graphical toolkit and what support is required from the operating system? What guidelines can we provide to encourage good design? 2.3 DISCUSSION Chairman - Bob Hopgood Rosenthal: On point (2), there are two systems on the SUN next door that allow this: SunWindows and Andrew. Prosser: I would be interested to see what you have done. Hopgood: They should be more general than that. What does it mean to pass a picture to a text processing program? Williams: Or worse still, spreadsheets with complete expressions. Are we moving the bitmap or the representation of the expressions? Hopgood: There is a whole problem in specifying what you are passing. Prosser: We could pass structured display files with type tags, but we must extend the model of window management defined in Tony Williams' paper (see Chapter 3) as it does not cope with it at the moment. Hopgood: Was your reference to GKS in point (3) meant to be provocative? Prosser: If you like. GKS just does not address window management problems. Rosenthal: On point (4), we have done this on our system. It allows uniform access to all windows on our 4.2. We have even tried running it over SNA. Prosser: You have assumed an application program interface and a network standard that the other system must support also. Can we agree on it? There are many different solutions. Yours is one, but is it for everyone? There are many people who would prefer a solution within an ISO standards context. Rosenthal: Anything with an 8-bit byte stream is enough. Teitelman: Also missing from the list is the graceful migration between applications written for displays with varying resolutions and from colour to black and white. That is an issue: device independence. Myers: I am disturbed that there is no one here to represent other than the general purpose window manager interface we all know, namely a specific interface like the Macintosh. Its user interface is set. Teitelman: A general purpose window manager should allow you to emulate the Macintosh, or have good reason why not. Prosser: You still land up with conflicts for somebody who has a context editor for his work, Macintosh-style, and some other applications bought in from different companies using a different user interface. Rosenthal: The big Macintosh book lists all the routines you can call and tells you what they will look like on the screen. It is difficult to see how you can take these routines and produce a different interface. You could provide a virtual Macintosh with a window or some other system but to provide the set of routines to do something different would be difficult. Another issue is that standards take too long to produce. A de facto standard window manager which is freely distributed and widely used may be the only way to achieve consensus on the interfaces and capabilities of window managers. Bono: I also do not see any user expectations about performance issues in the list. When building a product there must be performance requirements. Is there nothing we can say, or do people have an implicit model: "as fast as possible"? We should talk a little about performance. Williams: Some feedback techniques do not work if the window manager's performance is too slow. Some machines do not move bits fast enough. Bono: There are also size performance issues, as on small machines. There are tradeoffs between precalculation for a faster user interface versus keeping raw data. There is a lot of practical experience that needs to be documented. Prosser: Yes, I think performance is important to get slick user interfaces, but we cannot enforce them on everyone. There are cost tradeoffs when building a machine. Some people can live with the degraded performance sometimes and therefore you may tailor your user interface in that direction. Bono: You are looking for a single answer. There may not be one. It is an issue. There is lots of experience in this room and we may be able to categorize things. Myers: There are representatives of 60% of the world's window managers here and they have virtually identical appearance. Their differences are listable. Is this because they are based on two systems from PARC or because there are, say, only seven ways to write a window manager? Hopgood: They all look different to me, although I agree they all have square things on the screen! Rosenthal: They are all the same. The difference in application programming level between a tiling and an overlapping window manager is very small.
__label__pos
0.870714
Categories PHP Regular Expressions A regular expression or regex is used for searching, editing, extracting and manipulating data. Using regular expressions (regex) you can verify if a specific string matches a given text pattern or to find out a set of characters from a sentence or large batch of characters. Regular expressions are patterns that can be matched with strings. Regular expressions are also used in replacing, splitting, and rearranging text. Regular expressions generally follow a similar pattern in most programming languages. For example, you want to match the following HTML tags <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, and</h1>, </h2>, </h3>, </h4>, </h5>, </h6>, simply write a regex pattern like this: /<\/?h[1-6]>/. See the following code: <?php $html = '<H1>Heading 1</H1>'; $pattern = '/<\/?h[1-6]>/i'; echo preg_match($pattern, $html); //Prints 1 preg_match function searches the string for a match using the pattern (/ is the pattern delimiter) and returns 1 if the pattern matches, 0 if it does not match, or false if an error occurred. PHP uses preg_match and preg_match_all functions for matching and preg_replace function for replacement. You’ll read about these functions later. JavaScript example: As we already mentioned that regular expressions generally follow a similar pattern in most programming languages. In the following example, we use the same pattern in our JavaScript code. var html = '<H1>Heading 1</H1>'; var pattern = /<\/?h[1-6]>/i; regex.test(html); //true This tutorial covers the following topics: 1. Regular Expression Syntax 2. Pattern delimiter 3. Anchors – matching the start and end of a string 4. Quantifiers 5. Character classes 6. Negation character classes 7. Named character classes 8. Matching any character with wildcard 9. Groups or Subpatterns 10. Backreferences 11. Alternation – multiple regular expressions 12. Escape sequences 13. Pattern modifiers Regular Expression Syntax 1. Regular expressions must always be quoted as strings, for example, '/pattern/' or "/pattern/". 2. You can use any pair of punctuation characters as the delimiters, for example, '/pattern/', '#pattern#', "%pattern%", etc. The following example shows how the preg_match() is called to find the literal pattern "cat" in the subject string “raining cats and dogs”: <?php $string = 'raining cats and dogs'; $pattern= '/cat/'; if (preg_match($pattern, $string) === 1) echo 'Found "cat"'; //Prints: Found "cat" Pattern delimiter As we already mentioned above, a delimiter can be any non-alphanumeric, non-backslash, non-whitespace character. The following are equivalent: <?php $pattern = "/cat/"; //same as previous, but different delimiter $pattern = '~cat~'; //same as previous, but different delimiter $pattern = '!cat!'; //same as previous, but different delimiter $pattern = '#cat#'; If the regex delimiter occurs within the regex, it must be escaped with a backslash. To avoid this, choose a delimiter that does not occur in the regex. For example, you can use the pipe sign | if the forward slash / occurs in the regex, '|reg/ex|', otherwise, always use the forward slash / it is the standard delimiter and most programming languages use it as a regex delimiter. See the following example: <?php //Escape forward slashes $pattern = '/https:\/\//'; //Not need to escape $pattern = '#https://#'; Meta Characters The $^*()+.?[]\{}| punctuation letters are called metacharacters which make regular expressions work. Here is an overview of these special characters: Anchors – start and end of a string A regular expression can specify that a pattern occurs at the start or end of a subject string using anchors. MetaDescription ^Beginning of text $End of the text, define where the pattern ends • /^hello$/ – If you look for the word “hello”, the “h” must be at the beginning, while “o” is at the end. To search this string exactly (and nothing before and after). • /^hello/ – If the word you’re looking for is at the beginning of the text. • /hello$/ – If the word you’re looking for is at the end of the text. • /hello/ – If the word you’re looking for is anywhere in the text. <?php // Matches if string start with "hello" echo preg_match('/^hello/', 'hello, world'); #Prints: 1 echo preg_match('/^hello/', 'hi, world'); #Prints: 0 // Matches if string ends with "world" echo preg_match('/world$/', 'hi, world'); #Prints: 1 echo preg_match('/world$/', 'hi, friends'); #Prints: 0 // Must match "hello" exactly echo preg_match('/^hello$/', 'hello'); #Prints: 1 echo preg_match('/^hello$/', 'hello, world'); #Prints: 0 Quantifiers *, +, ?, {, } interprets as quantifiers unless they are included in a character class. Quantifiers specify how many instances of a character, group, or character class must be present in the input for a match to be found. MetaDescription ?Once or not at all (0 – 1), equivalent to {0, 1} /hi!?/ matches hi and hi! *Zero or more times (0 – ∞), equivalent to {0, } /hi!*/ matches hi, hi!, hi!!, hi!!!, and so on. +One or more times (1 – ∞), equivalent to {1, } /hi!+/ matches hi!, hi!!, hi!!!, and so on. {n}Exactly n times (where n is a number) /hi!{3}/ matches hi!!! {n, }At least n times (n – ∞) /hi!{0, }/ works similar to * /hi!{1, }/ works similar to + { ,m}No or m times (0 – m) where m is a number /hi!{ ,3}/ matches hi and hi!!! {n,m}At least n but not more than m times /hi!{0,1}/ works similar to ? /hi!{0,2}/ matches hihi! and hi!! Character classes [ ] Character class, match only characters that are listed in the class. Defines one character out of the group of letters or digits. [aeiou] match either a, e, i, o, or u. A hyphen - creates a range when it is placed between two characters. The range includes the character before the hyphen, the character after the hyphen, and all characters that lie between them in numerical order. See the following examples: MetaDescription [0-9]Matches any digit. [a-z]Matches any small alphabet character. [A-Z]Matches any capital alphabet character. [a-zA-Z0-9]Matches any alphanumeric character. gr[ae]yMatches grey or gray but not graey. For example, to match a three-character string that starts with a b, ends with a ll, and contains a vowel as the middle letter, the expression: <?php echo preg_match('/b[aeiou]ll/', 'bell'); #Prints: 1 Match any string that contains “ball, bell, bill, boll, or bull”. Negation (match all except that do not exist in the pattern) The caret ^ at the beginning of the class means “No“. If a character class starts with the ^ meta-character it will match only those characters that are not in that class. MetaDescription [^A-Z]matches everything except the upper case letters A through Z [^a-z]matches everything except the lowercase letters a through z [^0-9]matches everything except digits 0 through 9 [^a-zA-Z0-9]combination of all the above-mentioned examples The following code matches anything other than alphabet (lower or upper): <?php $pattern = '/^[^a-zA-Z]+$/'; echo preg_match($pattern, 'hello'); #Prints: 0 echo preg_match($pattern, '1234'); #Prints: 1 echo preg_match($pattern, 'hi12'); #Prints: 0 Named character classes Named ClassDescription [:alnum:]Matches all ASCII letters and numbers. Equivalent to [a-zA-Z0-9]. [:alpha:]Matches all ASCII letters. Equivalent to [a-zA-Z]. [:blank:]Matches spaces and tab characters. Equivalent to [ \t]. [:space:]Matches any whitespace characters, including space, tab, newlines, and vertical tabs. Equivalent to [\n\r\t \x0b]. [:cntrl:]Matches unprintable control characters. Equivalent to [\x01-\x1f]. [:digit:]Matches ASCII digits. Equivalent to [0-9]. [:lower:]Matches lowercase letters. Equivalent to [a-z]. [:upper:]Matches uppercase letters. Equivalent to [A-Z]. <?php $ptrn = '/[[:digit:]]/'; echo preg_match($ptrn, 'Hello'); # Prints 0 echo preg_match($ptrn, '150'); # Prints 1 Wild Card – dot or period to match any character To represent any character in a pattern, a . (period) is used as a wildcard. The pattern "/e../" matches any three-letter string that begins with a lowercase "e"; for example, eateggend, etc. To express a pattern that actually matches a period use the backslash character \ for example, “/brainbell\.com/” matches brainbell.com but not brainbell_com. Groups or subpatterns Parentheses ( ) are used to define groups in regular expressions. You can use the set operators *, +, and ? in such a group, too. Groups show how we can extract data from the input provided. MetaDescription ( )Capturing group (?<name>)Named capturing group (?:)Non-capturing group (?=)Positive look-ahead (?!)Negative look-ahead (?<=)Positive look-behind (?<!)Negative look-behind Applying repeating operators (or quantifiers) to groups, the following pattern matches “123”, “123123”, “123123123”, and so on. <?php $pattern = '/(123)+/'; echo preg_match($pattern, '123'); # Prints 1 echo preg_match($pattern, '123123'); # Prints 1 echo preg_match($pattern, '123123123'); # Prints 1 The following example matches a URL: <?php $pattern = '!^(https?://)?[a-zA-Z]+(\.[a-zA-z]+)+$!'; echo preg_match($pattern, 'brainbell.com'); //Prints: 1 echo preg_match($pattern, 'http://brainbell.com'); //Prints: 1 echo preg_match($pattern, 'https://brainbell.com'); //Prints: 1 Backreferences You can refer to a group (or subpattern) captured earlier in a pattern with a backreference. The \1 refers to the first subpattern, \2 refers to the second subpattern, and so on. <?php $subject = 'PHP PHP Tutorials'; $pattern = '/(PHP)\s+\1/'; echo preg_match($pattern, $subject); //Prints: 1 You can not use backreferences with a non-capturing subpattern (?:), see the following code: <?php $subject = 'PHP PHP Tutorials'; $pattern = '/(?:PHP)\s+\1/'; echo preg_match($pattern, $subject); /*Warning: preg_match(): Compilation failed: reference to non-existent subpattern*/ If a pattern is enclosed in double quotes, the backreferences are referenced as \\1, \\2, \\3, and so on. <?php $subject = 'PHP PHP Tutorials'; $pattern = "/(PHP)\s+\\1/"; echo preg_match($pattern, $subject); //Prints: 1 For more information visit: Using backreferences with preg_replace(). Alternation – combine multiple regex The | operator has the lowest precedence of the regular expression operators, treating the largest surrounding expressions as alternative patterns. This operator splits the regular expression into multiple alternatives. School|College|University matches School, College, or University with each match attempt. Only one name matches each time, but a different name can match each time. /a|b|c/ matches a, or b, or c with each match attempt. <?php $pattern = '/(c|b|r)at/'; echo preg_match($pattern, 'cat'); // 1 echo preg_match($pattern, 'rat'); // 1 echo preg_match($pattern, 'bat'); // 1 Escape characters \ \ (the backslash) masks metacharacters and special characters so they no longer possess a special meaning. If you want to look for a metacharacter as a regular character, you have to put a backslash in front of it. For example, if you want to match one of these characters: $^*()+.?[\{|, you should have to escape that character with \. The following example matches $100: <?php echo preg_match('/\$[0-9]+/', '$100'); #Prints: 1 Note: To include a backslash in a double-quoted string, you need to escape the meaning of the backslash with a backslash. The following example shows how the regular expression pattern “\$” is represented: <?php //Escaping $ with \\ in a double-quoted pattern echo preg_match("/\\$[0-9]+/", '$100'); #Prints: 1 //Escaping $ with \ will not match the pattern echo preg_match("/\$[0-9]+/", '$100'); #Prints: 0 It’s better to avoid confusion and use single quotes when passing a string as a regular expression: <?php echo preg_match('/\$[0-9]+/', '$100'); #Prints: 1 The backslash itself is a metacharacter, too. If you look for the backslash, you write \\\. <?php #Single-quoted string echo preg_match('/\\\/', '\ backslash'); #Prints: 1 #Doouble-quoted string, must use \\\ echo preg_match("/\\/", '\ backslash'); #Warning: preg_match(): No ending delimiter '/' found Read more details on Escaping special characters in a regular expression. You can also use the backslash to specify generic character types: • \d any decimal digit, equivalent to [0-9] • \D any character that is not a decimal digit, equivalent to [^0-9] • \s any whitespace character • \S any character that is not a whitespace character • \w any “word” character • \W any “non-word” character See the full list of escape sequences on php.net. If you want to search for a date, simply use '/\d{2}.\d{2}.\d{4}/', it matches 01-12-2020, 10/10/2023 or 12.04.2025 • \d is equivalent to [0-9]. • \d{2} matches exactly two digits. • \d{4} matches exactly four digits. Pattern Modifiers You can change the behavior of a regular expression by placing a pattern modifier at the end of the regular expression after the closing delimiter. . For example, for case insensitive pattern match, use the i modifier /pattern/i. <?php $string = 'Hello, World'; $pattern = '/hello/i'; echo preg_match($pattern, $string); Following is the list of pattern modifiers: • i modifier Perform case insensitive match. • m modifier This modifier has no effect if there are no \n (newline) characters in a subject string, or no occurrences of ^ or $ in a pattern, otherwise, instead of matching the beginning and end of the string, the ^ and $ symbols will match the beginning and end of the line. • s modifier The . will also match newlines. By default, the dot . character in a pattern matches any character except newline characters. By adding this modifier you can make the dot character match newlines too. • x modifier Ignores the whitespace in the pattern unless you escape it with a backslash or within brackets, for example, use " \ " (for a space), " \t " (for a tab), or " \s " (for any whitespace character). Whitespace inside a character class is never ignored. This allows you to split a long regular expression over lines and indent it similar to the PHP code. • A modifier Anchors the pattern to the beginning of the string. Matches only to the beginning of a string even if newlines are embedded and the m modifier is used. Only used by preg_replace() function. • D modifier Matches only at the end of the string. Without this modifier, a dollar sign is ignored if the m modifier is set. • S modifier Studying a pattern if it is used often to optimize the search time. • U modifier This modifier makes the quantifiers lazy by default and using the ? after them instead marks them as greedy. • X modifier Any backslash in a pattern followed by a letter that has no special meaning causes an error. • J modifier Allow duplicate names for subpatterns. • u modifier Treats the pattern and subject as being UTF-8 encoded. More Regular Expressions Tutorials: 1. Regular Expressions 2. Matching patterns using preg_match() and preg_match_all() 3. Search and replace with preg_replace() and preg_filter() 4. Search and replace with preg_replace_callback() and preg_replace_callback_array() 5. Regular expression to find in an array and to split a string 6. Escaping special characters in regular expressions 7. Handling errors in regular expressions 8. Matching word boundaries 9. Data validation with regular expressions
__label__pos
0.919091
A Gentle Introduction To Method Of Lagrange Multipliers The method of Lagrange multipliers is a simple and elegant method of finding the local minima or local maxima of a function subject to equality or inequality constraints. Lagrange multipliers are also called undetermined multipliers. In this tutorial we’ll talk about this method when given equality constraints.  In this tutorial, you will discover the method of Lagrange multipliers and how to find the local minimum or maximum of a function when equality constraints are present. After completing this tutorial, you will know: • How to find points of local maximum or minimum of a function with equality constraints • Method of Lagrange multipliers with equality constraints Let’s get started. A Gentle Introduction To Method Of Lagrange Multipliers. Photo by Mehreen Saeed, some rights reserved. Tutorial Overview This tutorial is divided into 2 parts; they are: 1. Method of Lagrange multipliers with equality constraints 2. Two solved examples  Prerequisites For this tutorial, we assume that you already know what are: You can review these concepts by clicking on the links given above. What Is The Method Of Lagrange Multipliers With Equality Constraints? Suppose we have the following optimization problem: Minimize f(x) Subject to:  g_1(x) = 0 g_2(x) = 0 g_n(x) = 0 The method of Lagrange multipliers first constructs a function called the Lagrange function as given by the following expression. L(x, ????) = f(x) + ????_1 g_1(x) + ????_2 g_2(x) + … + ????_n g_n(x)  Here ???? represents a vector of Lagrange multipliers, i.e., ???? = [ ????_1, ????_2, …, ????_n]^T To find the points of local minimum of f(x) subject to the equality constraints, we find the stationary points of the Lagrange function L(x, ????), i.e., we solve the following equations: ∇xL = 0  ∂L/∂????_i = 0 (for i = 1..n) Hence, we get a total of m+n equations to solve, where m = number of variables in domain of f n = number of equality constraints.  In short, the points of local minimum would be the solution of the following equations: ∂L/∂x_j = 0 (for j = 1..m) g_i(x) = 0 (for i = 1..n) Want to Get Started With Calculus for Machine Learning? Take my free 7-day email crash course now (with sample code). Click to sign-up and also get a free PDF Ebook version of the course. Solved Examples This section contains two solved examples. If you solve both of them, you’ll get a pretty good idea on how to apply the method of Lagrange multipliers to functions of more than two variables, and a higher number of equality constraints. Example 1: One Equality Constraint Let’s solve the following minimization problem: Minimize: f(x) = x^2 + y^2 Subject to: x + 2y – 1 = 0 The first step is to construct the Lagrange function: L(x, y, ????) = x^2 + y^2 + ????(x + 2y – 1) We have the following three equations to solve: ∂L/∂x = 0  2x + ???? = 0      (1) ∂L/∂y = 0 2y + 2???? = 0     (2) ∂L/∂???? = 0 x + 2y -1 = 0    (3) Using (1) and (2), we get: ???? = -2x = -y Plugging this in (3) gives us: x = 1/5 y = 2/5 Hence, the local minimum point lies at (1/5, 2/5) as shown in the right figure. The left figure shows the graph of the function. Graph of function (left), contours, constraint and local minima (right) Graph of function (left). Contours, constraint and local minima (right) Example 2: Two Equality Constraints Suppose we want to find the minimum of the following function subject to the given constraints: minimize g(x, y) = x^2 + 4y^2 Subject to: x + y = 0 x^2 + y^2 – 1 = 0 The solution of this problem can be found by first constructing the Lagrange function: L(x, y, ????_1, ????_2) = x^2 + 4y^2 + ????_1(x + y) + ????_2(x^2 + y^2 – 1) We have 4 equations to solve: ∂L/∂x = 0 2x + ????_1 + 2x ????_2 = 0    (1) ∂L/∂y = 0 8y + ????_1 + 2y ????_2 = 0    (2) ∂L/∂????_1 = 0 x + y = 0         (3) ∂L/∂????_2 = 0 x^2 + y^2 – 1 = 0    (4) Solving the above system of equations gives us two solutions for (x,y), i.e. we get the two points:  (1/sqrt(2), -1/sqrt(2)) (-1/sqrt(2), 1/sqrt(2)) The function along with its constraints and local minimum are shown below. Graph of function (left). Contours, constraint and local minima (right) Graph of function (left). Contours, constraint and local minima (right) Relationship to Maximization Problems If you have a function to maximize, you can solve it in a similar manner, keeping in mind that maximization and minimization are equivalent problems, i.e., maximize f(x)                 is equivalent to                   minimize -f(x) Importance Of The Method Of Lagrange Multipliers In Machine Learning Many well known machine learning algorithms make use of the method of Lagrange multipliers. For example, the theoretical foundations of principal components analysis (PCA) are built using the method of Lagrange multipliers with equality constraints. Similarly, the optimization problem in support vector machines SVMs is also solved using this method. However, in SVMS, inequality constraints are also involved. Extensions This section lists some ideas for extending the tutorial that you may wish to explore. • Optimization with inequality constraints • KKT conditions • Support vector machines If you explore any of these extensions, I’d love to know. Post your findings in the comments below. Further Reading This section provides more resources on the topic if you are looking to go deeper. Tutorials Resources Books • Thomas’ Calculus, 14th edition, 2017. (based on the original works of George B. Thomas, revised by Joel Hass, Christopher Heil, Maurice Weir) • Calculus, 3rd Edition, 2017. (Gilbert Strang) • Calculus, 8th edition, 2015. (James Stewart) Summary In this tutorial, you discovered what is the method of Lagrange multipliers. Specifically, you learned: • Lagrange multipliers and the Lagrange function • How to solve an optimization problem when equality constraints are given Do you have any questions? Ask your questions in the comments below and I will do my best to answer. Get a Handle on Calculus for Machine Learning! Calculus For Machine Learning Feel Smarter with Calculus Concepts ...by getting a better sense on the calculus symbols and terms Discover how in my new Ebook: Calculus for Machine Learning It provides self-study tutorials with full working code on: differntiation, gradient, Lagrangian mutiplier approach, Jacobian matrix, and much more... Bring Just Enough Calculus Knowledge to Your Machine Learning Projects See What's Inside , , , 7 Responses to A Gentle Introduction To Method Of Lagrange Multipliers 1. Avatar Dr. Fouz Sattar September 4, 2021 at 5:02 am # Well written and well articulated. 2. Avatar Ryan Gardner December 10, 2021 at 5:04 am # Great article. Clear and concise. 3. Avatar Akash February 25, 2022 at 8:17 pm # Really appreciate your efforts, well explained • Avatar James Carmichael February 26, 2022 at 12:32 pm # Thank you for the feedback Akash! 4. Avatar Marina September 23, 2022 at 8:04 pm # Great article. Is it possible with Lagrange multipliers method also to find multiple optima and how? Thank you in advance. Leave a Reply
__label__pos
0.976599
Malware analysis Malware spotlight: Wabbit January 21, 2020 by Greg Belding Introduction Beginnings are often steeped in myth, legend and a good helping of storytelling, with malware being no exception to this rule. Way back in 1974, before many of our readers were born, malware was still in its infancy, with early pioneers inventing different types of malware to simply explore what could be done.  One such creation was the Wabbit — the first self-replicating malware. It was simple and crude, to be sure, and while the original Wabbit was not malicious, variants of the Wabbit can be programmed to exhibit malicious capabilities.  This article will detail the Wabbit type of malware and will explore what Wabbit is, the history of Wabbit, how Wabbit works, the fork-bomb Wabbit variant, and potential applications for this early type of malware.  What is Wabbit? To properly discuss Wabbit, we first need to discuss the proverbial rabbit — I mean, elephant — in the room. The name Wabbit is in reference to Elmer Fudd’s way of saying rabbit from the old Looney Tunes cartoons.  This name is incredibly accurate for what this malware is, as it refers to the fact that rabbits reproduce very fast. Wabbit is the first self-replicating malware to ever exist (some historians will argue that Creeper was) and can reproduce so fast that the system it is installed on literally chokes as its resources are all used up by Wabbit. While the first instance of Wabbit was not malicious per se, killing a computer system is certainly malicious to the system owner if they are not expecting it. Moreover, Wabbit can be programmed to perform conscious malicious actions. One such variant of Wabbit is called the fork-bomb, which will be discussed later in this article.  Due to the rarity of Wabbit and some of its unique peculiarities, modern malware discussions do not mention it as a type of malware. Looking back at it historically, however, it is clear to see that not only is it malware but possibly one of the best, as it has solid potential as an educational tool and for historical purposes as well. The history of Wabbit The history of Wabbit begins at literally the origin of malware as a concept, and like all good creation stories, this one is steeped in legend.  There is only one known instance of Wabbit in its original, non-malicious form and this occurred back in 1974. In 1988, an individual known as Bill Kennedy recounted a story about a coworker who was working on an IBM OS/360 mainframe. This “bright young fellow” wrote a program named Wabbit that, as it ran, would eat up the resources of the system and cause a kind of resource constipation.  Instead of infecting other network devices, Wabbit was only capable of infecting the system it was installed on. This constipation ultimately killed the system and ended up costing this bright young fellow his job. Since then, variants have been created that have had a more pointedly malicious intention.  Wabbit is indeed a relic of a past computing age, essentially designed to take advantage of the way the IBM OS processed information. You see, IBM used to use what was called the ASP job stream, which would communicate with its console less and less as resources were consumed. Looking at this malware through modern eyes, Wabbit most closely matches up to the denial-of-service attack (DoS).  How does Wabbit work? The original inception of Wabbit worked a little differently than modern variants. This was mainly because of the older system framework (IBM OS) in place back in 1974, but the basic idea is the same. Wabbit creates an infinite loop that continually creates system processes and creates copies of Wabbit. This consumes operating system resources and creates a high number of CPU cycles which constipates the system, causing it to get slower and slower until it eventually crashes. Later variants took this wascally Wabbit (pardon the Elmer Fudd reference) ability to newer operating systems — most notably Unix and Linux.  The fork-bomb variant The most well-known Wabbit variant is the fork-bomb. This version of Wabbit had the ability to run on Linux, Unix and Unix-like operating systems (Debian, Ubuntu, Red Hat and so on).  In fork-bomb attacks, child processes self-replicate and consume a high amount of operating system resources, which ultimately stops legitimate processes from being created and running. As the attack progresses, the infected system ignores keyboard inputs, including logout attempts. The fork-loop consumes resources until the maximum allowed processes is reached which causes what is called kernel panic — where the kernel crashes because it cannot keep up with the fork loop.  Most systems infected with fork-bomb stay frozen until restart, most commonly in the form of a hard restart. This will most certainly cause data loss.  Wabbit application Wabbit is most applicable in the arena of computer science and information security education. While Wabbit can cause damage to systems, it is a relatively simple piece of malware that can be used to demonstrate process and program replication in education.  Computer science students can be given a time limit to stop Wabbit, where the natural end of the exercise is either stopping Wabbit or the infected system crashing. This would also have value in teaching students about just how simple malware can be and how you sometimes need to understand it to stop it. Conclusion Wabbit is one of the first instances of malware ever to exist. While simple, it can devastate a system by squandering all operating system resources until the infected system crashes.  Wabbit was originally meant to be more tongue-in-cheek than malicious. However, this malware can easily be programmed to not only be malicious but also to infect modern systems, making it a bona fide type of malware.   Sources 1. Two old viruses, Risks Digest 2. Rabbit, Malware Wiki 3. The very first viruses: Creeper, Wabbit and Brain, InfoCarnivore 4. What is a Rabbit Virus or Fork Bomb or Wabbit?, The Security Buddy 5. Fork bomb attack (Rabbit virus), Imperva Posted: January 21, 2020 Articles Author Greg Belding View Profile Greg is a Veteran IT Professional working in the Healthcare field. He enjoys Information Security, creating Information Defensive Strategy, and writing – both as a Cybersecurity Blogger as well as for fun.
__label__pos
0.821055
Complex numbers question Creating a new topic here requires registration. All other forums are without registration. Complex numbers question Postby umricky » Sun Nov 12, 2023 11:45 am If z=1+2i is a root of the equation z^2 = az+ b find the values of a and b I have no idea how to answer this, but I'm sure it's pretty simple. Thanks in advance! umricky   Posts: 2 Joined: Sun Nov 12, 2023 11:37 am Reputation: 0 Re: Complex numbers question Postby Guest » Mon Nov 13, 2023 7:31 am We will first find the complex conjugate of z. Given that z = 1 + 2i, the complex conjugate of z, denoted as z*, is 1 - 2i. Now, we'll use the property that if z is a root, its conjugate z* is also a root. Therefore, we can write the equation as: [tex](1+2i)^2 = a(1+2i) + b[/tex] and [tex](1-2i)^2 = a(1-2i) + b[/tex] Solving these two simultaneous equations: Hence, [tex]a = -2 + 2i[/tex] [tex]b = 3 + 8i[/tex] Guest   Return to Math Problem of the Week Who is online Users browsing this forum: No registered users and 1 guest
__label__pos
0.957292
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required. Sign up Here's how it works: 1. Anybody can ask a question 2. Anybody can answer 3. The best answers are voted up and rise to the top I've heard that you can use mod_rewrite to clean up your URLs, and basically I'd like to make it so the .php file extension isn't shown in the URL. For example, let's say I have the following file structure on a site: /index.php /about.php /contact.php /css/main.css /img/animage.jpg /admin/index.php /admin/login.php /admin/admin.php I would like to make the following basic changes with mod_rewrite: • When a request is made to the root i.e. /about, if a directory is found called about, then it should behave as a directory nomrally does (i.e. load the index.php from the direcotry). • If a directory is not found, it should point to about.php • If a request for a .php file is made, it should 301 redirect to the filename without the .php extension. • Only the directories which would actually be viewed directly in the browser should have these URL changes (i.e. the root and the admin directory), therefore css and img should have their URLs unchanged. How can I make those changes using mod_rewrite? share|improve this question In .htaccess file: RewriteEngine On RewriteBase / # Abort on directories, skip sub-requests RewriteCond %{REQUEST_FILENAME} -d RewriteRule .? - [L,NS] # Check if there is php file (add extension) RewriteCond %{REQUEST_URI}\.php -f RewriteRule (^.*) $1\.php [L] #Redirect explicit php requests (if file exist) RewriteCond %{REQUEST_FILENAME} -f # strange - REQUEST_URI always contains .php # have to parse whole request line # look for .php in URI (fields are space separated) but before '?' (query string) RewriteCond %{THE_REQUEST} ^[^\ ]+\ /[^\ \?]*\.php RewriteRule (.*)\.php$ $1 [NS,R=301] mod_rewrite is extremely powerful :) share|improve this answer      Oops, I missed the options in RewriteCond. Love how powerful Apache is. – couling Feb 13 '12 at 9:40      It's so powerfull! You've just discovered the top of the iceberg! – Olivier Pons Mar 23 '12 at 8:21 Your Answer   discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged or ask your own question.
__label__pos
0.784771
Over the past few years, I've been working a lot with the JavaScript language and building large-scale web applications. Although I have "Stockholm Syndrome" (JavaScript is one of my favorite programming languages), other developers don't share my affection for the language. Developers don't like JavaScript for many reasons. One of the main reasons is that JavaScript is difficult to maintain in a large-scale code base. In addition, JavaScript lacks certain language features, such as modules, classes, and interfaces. Developers can use two main approaches to avoid JavaScript pitfalls. The first approach is to use plain JavaScript with JavaScript design patterns to mimic the behavior of modules, classes, and other missing JavaScript language features. I use this approach most of the time, but it can be very difficult for junior JavaScript developers because you need know JavaScript quite well to avoid its pitfalls. Related: Is TypeScript Ready for Prime Time? The second approach is to use JavaScript preprocessors. JavaScript preprocessors are design-time tools that use custom languages or known languages that later compile into JavaScript. Using this approach helps you create a more object-oriented–like code base and helps code maintainability. JavaScript preprocessors such as CoffeeScript, Dart, or GWT are very popular, but they force you to learn a new language or use languages such as Java or C# that are later compiled into JavaScript. What if you could use JavaScript instead, or a variation of JavaScript? You're probably asking yourself why you would use JavaScript or a JavaScript variant to compile into JavaScript. One reason is that ECMAScript 6, the latest JavaScript specifications, introduces a lot of the missing features in the JavaScript language. Also, because at the end of the process you get JavaScript code anyway, why not write the code in plain JavaScript from the start? This is where TypeScript becomes very useful. TypeScript to the Rescue A year ago Microsoft released the first preview of a new language, TypeScript, written by a team led by Anders Hejlsberg, creator of the C# language. TypeScript is a JavaScript preprocessor that compiles into plain JavaScript. Unlike other JavaScript preprocessors, TypeScript was built as a typed superset of JavaScript, and it adds support for missing JavaScript features that aren't included in the current version of ECMAScript. TypeScript aligns to the new JavaScript keywords that will be available when ECMAScript 6, the next version of JavaScript specifications, becomes the JavaScript standard. This means that you can use language constructs such as modules and classes in TypeScript now, and later on when ECMAScript 6 becomes the standard, your code will already be regular JavaScript code. TypeScript is cross-platform and can run on any OS because it can run wherever JavaScript can run. You can use the language to generate server-side code written in JavaScript along with client-side code also written in JavaScript. This option can help you write an end-to-end application with only one language—TypeScript. To install TypeScript, go to the TypeScript website. On the website you'll find download links and an online playground that you can use to test the language. You can also view TypeScript demos in the website's "run it" section. The website can be very helpful for new TypeScript developers. I don't go into great detail about TypeScript's features in this article; for a more detailed explanation of the language, see Dan Wahlin's "Build Enterprise-Scale JavaScript Applications with TypeScript." I recommend that you read Wahlin's article before you proceed any further with this article. You'll need a good understanding of what TypeScript is before you jump into writing a simple end-to-end application using the language. Creating the Server Side with Node.js To demonstrate the ease of using TypeScript to write an application, let's create a simple gallery of DevConnections conference photos. First, you need to create the server side. The application will use the node.js runtime to run the application back end. Node.js is a platform to build web servers using the JavaScript language. It runs inside a Google V8 engine environment. V8 is the Chrome browser's JavaScript engine. Node.js uses an event-driven model that helps create an efficient I/O-intensive back end. This article assumes that you know a little bit about node.js and Node Packaged Modules (npm). If you aren't familiar with node.js, you should stop reading and go to the node.js website first. Our application will also use the Express framework, which is a node.js web application framework. Express helps organize the web application server side into MVC architecture. Express lets you use view engines such as EJS and Jade to create the HTML that's sent to the client. In addition, Express includes a routes module that you can use to create application routes and to access other features that help speed up the creation of a node.js server. For further details about Express, go to the Express website. Creating the project. To create the application, you need to install node.js Tools for Visual Studio (NTVS). (As I write this article, NTVS is currently in first alpha and might be unstable.) NTVS includes project templates for node.js projects, IntelliSense for node.js code, debugging tools, and many other features that can help you with node.js development inside Visual Studio IDE. After you install NTVS, create a blank Express application and call it DevConnectionsPhotos. Figure 1 shows the New Project dialog box, which includes all the installed NTVS project templates. Figure 1: Creating a Blank Express Application When NTVS asks you whether to run npm to install the missing dependencies for the project, you should select the option to run npm and allow it to retrieve all the Express packages. Creating the views. In the Views folder, you should replace the layout.jade file with the code in Listing 1. This code is written in Jade view engine style, and it will render the HTML layout of the main application page. Listing 1: Rendering the HTML Layout of the Main Application Page doctype html html   head     title='DevConnections Photo Gallery'     link(rel='stylesheet', href='/Content/app.css')     link(rel='stylesheet', href='/Content/themes/classic/galleria.classic.css')     script(src='/Scripts/lib/jquery-1.9.0.js')     script(src='/Scripts/lib/galleria-1.2.9.js')     script(src='/Content/themes/classic/galleria.classic.js')     script(src='/Scripts/app/datastructures.js')     script(src='/Scripts/app/dataservice.js')     script(src='/Scripts/app/bootstrapper.js')     script(src='/Scripts/app/app.js')   body     block content You should also replace the index.jade file, which includes the content block that will be injected into the layout.jade file during runtime. The new code for the index.jade file should look like that in Listing 2. Listing 2: The index.jade File extends layout block content   div#container      header         img#DevConnectionsLogo(src='/Content/Images/DevConnctionsLogo.png', alt='DevConnections Logo')         h1='DevConnections Photo Gallery'      section.main         div#galleria      img#light(src="/Content/Images/Light.png") The index.jade file includes a declaration of a DIV element with a Galleria ID. You'll use that DIV later on the client side to show the photo gallery that you're implementing. Implementing the server side. Before you use TypeScript, you should import the TypeScript runtime to the NTVS project. To do so, add the following line of code to the DevConnectionsPhotos.njsproj file: <Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" /> This line of code imports TypeScript to the project and allows you to use it to compile TypeScript files. (Note that the TypeScript Visual Studio runtime wasn't a part of NTVS projects at the time I wrote this article.) Now that the environment is ready and you've created the main web page, you should rename the app.js file, which exists in the root of the project, to app.ts by changing its postfix to .ts. Performing this action forces the code to run as TypeScript code rather than JavaScript code. Because TypeScript is a JavaScript superset, you can transform the app.js file, which is a simple Express template, to app.ts without any problems. In the app.ts file, you should add a module dependency on the node.js file system module. This module exists under the name fs. To use this module, you should create a new variable called fs under the Module dependencies comment, as Listing 3 shows. Listing 3: Creating the fs Variable /**  * Module dependencies.  */ var express = require('express'); var routes = require('./routes'); var user = require('./routes/user'); var http = require('http'); var path = require('path'); var fs = require('fs'); You should use a function called getAllFileURIs, as in Listing 4, that receives a folder name and a callback function. The getAllFileURIs function will use the folder name to open that folder; later, it will return all the file URIs in that folder. Listing 4: The getAllFileURIs Function var getAllFileURIs = function(folder: string, callback: Function): void {     var results = [],         relativePath = folder.substr(8);     fs.readdir(folder, (err, files) => {         if (err) {             callback([]);         };         files.forEach(function(file) {             file = relativePath + '/' + file;             results.push(file);         });         callback(results);     }); }; You can see that I used lambdas in the code and types for the arguments that the function receives. These features come from TypeScript and aren't currently part of JavaScript. After you write the getAllFileURIs function, you should add an endpoint called getAllImages on your server. This endpoint uses the getAllFileURIs function to fetch all the URIs for files that exist in the /public/Content/Photos folder. Listing 5 shows what the implementation of this endpoint should look like. In Listing 5, whenever a request arrives to the getAllImages endpoint, an array of image URIs is serialized to JSON format and is written to the response. Listing 5: Implementing the getAllImages Endpoint app.get('/getAllImages', (req, res) => {     getAllFileURIs('./public/Content/Photos', (imageUris) => {         res.writeHead(200, { 'Content-Type': 'application/json' });         res.write(JSON.stringify(imageUris));         res.end();     }); }); Your server code is now ready to run. Be sure to set the generated app.js file as the startup file for the node.js application. Figure 2 shows a running DevConnections photo gallery with only the server implementation. (Notice that there are no photos in the gallery yet.) Now that you have a working server side, you need to create the client side. Figure 2: DevConnections Photo Gallery with only the Server Implementation Creating the Client Side Using JavaScript Libraries You'll use two libraries on the client side: jQuery and Galleria. You're probably already familiar with jQuery; Galleria is a JavaScript library that's used to create a gallery from an image array. You can download Galleria, or you can use your own gallery library as long as you adjust the code, as I show you later in this article Setting up the folders. In the public folder that was created by the Express project template, create a Scripts folder that you'll use to hold all the scripts that the application uses. Under the Scripts folder, add two new folders named app and lib. Put all the application TypeScript files and the generated JavaScript files in the app folder. Put the jQuery and Galleria JavaScript files in the lib folder. To use JavaScript libraries as though they were created with TypeScript, you need to import the libraries' declaration files to the project. A declaration file is a file that ends with the .d.ts postfix; it describes the interfaces of the library. Having a declaration file can help the TypeScript environment understand the types included in a typed library. However, not all libraries have a declaration file. A known GitHub repository called DefinitelyTyped includes most of the major libraries' declaration files. You should download the jquery.d.ts declaration file and put it under the lib folder. Unfortunately, Galleria isn't included in DefinitelyTyped. Now you're ready to create the TypeScript files and use the libraries. Creating the client-side implementation. The first step in configuring the client side is to create the data structures for Galleria image information and for Galleria configuration options. Create a new TypeScript file in the app folder that exists in the Scripts folder. Call the new file datastructures.ts. Both of the classes you'll create will be a part of the app.data.structures module. The code in Listing 6 implements the data structures. The data structure implementation is very simple. The data structures include properties that the application will later use to configure the image gallery. After you've created the data structures, you need to configure the interaction with the server, and you need to fetch the images for the gallery. To accomplish these tasks, you need to implement a data service class. Create a new TypeScript file in the app folder that exists in the Scripts folder. Call the new file dataservice.ts. The data service's responsibility will be to call the getAllImages endpoint and use the array of image URIs to create Galleria images, as Listing 7 shows. Listing 7: Implementing a Data Service Class /// <reference path="../lib/jquery.d.ts" /> /// <reference path="datastructures.ts" /> module app.data {     import structures = app.data.structures;     export interface IDataService {         getImages: () => JQueryPromise;     }     export class DataService implements IDataService {         getImages(): JQueryPromise {             var deferred = $.Deferred();             var result: structures.GalleriaImage[] = [];             $.getJSON("/getAllImages", {}, (imageUris) => {                 $.each(imageUris, (index, item) => {                     result.push(new structures.GalleriaImage(new structures.GalleriaImageConfigOptions(item, "", "", "My title" + index, "My description" + index, "")));                 });                 deferred.resolve(result);             });             return deferred.promise();         }     } } As you can see in Listing 7, one of the first steps is to import the app.data.structures module. Later on, you declare an interface that exposes a getImages function. The getImages function returns a JQueryPromise object that will help defer the execution of the getImages operation until the getJSON function returns and runs its success callback. When the getJSON success callback runs, it creates a GalleriaImage object for each image URI that's part of the array that was returned by the server. Now that you have data structures and a data service, you need to configure the Galleria object. Create a new TypeScript file in the app folder that exists in the Scripts folder. Call the new file bootstrapper.ts. In the bootstrapper.ts file, create a Bootstrapper class that's responsible for running the Galleria object, as Listing 8 shows. Listing 8: Configuring the Galleria Object /// <reference path="../lib/jquery.d.ts" /> /// <reference path="dataservice.ts" /> declare var Galleria; module app {     import data = app.data;     export interface IBootstrapper {         run: () => void;     }     export class Bootstrapper implements IBootstrapper {         run() {             this.getData().then((images) => {                 Galleria.configure({                     imageCrop: true,                     transition: 'fade',                     dataSource: images,                     autoplay: true                 });                 Galleria.run('#galleria');             });         }         getData(): JQueryPromise {             var dataService = new data.DataService();             return dataService.getImages();         }     } } One of the interesting things in the implementation is the call to declare var Galleria. Because Galleria doesn't have a declaration file, you need to declare its object. This is where the declare keyword becomes very handy. You use the declare keyword to inform the TypeScript runtime that the declared variable is dynamic and should be used with the any type. The last part of the puzzle is the app.ts file. You need to create this file in the app folder that exists in the Scripts folder. Don't be confused between the app.ts file of node.js and this app.ts file, which is used to run the application. The code in Listing 9 implements the client-side app.ts file. Listing 9: Implementing the Client-Side app.ts File /// <reference path="bootstrapper.ts" /> module app {     // start the app on load     window.addEventListener("DOMContentLoaded", (evt) => {         var bootstrapper = new app.Bootstrapper();         bootstrapper.run();     }, false); } Now that all the parts are in place, the final result is an image gallery (see Figure 3). You can put images in the Images folder, which exists under the Content folder. You can download the complete application that I used to create the DevConnections photo gallery. Figure 3: Final DevConnections Photo Gallery The TypeScript Advantage In this article you learned how to use TypeScript to build a simple application. TypeScript can help you bridge the missing JavaScript features that will eventually be available in ECMAScript 6. TypeScript allows you to write large-scale JavaScript code and maintain it more easily. You can use TypeScript both in the application front end and in the application back end with frameworks and environments that run JavaScript. For More on TypeScript, see Blair Greenwood's article "TypeScript Moves Toward Final Release with Visual Studio 2013 Update 2 CTP2."
__label__pos
0.640341
  Knowledge Center What Are Pitfalls of Automated Testing? It is commonly known that any mobile testing, desktop testing or web site testing can hardly be performed without automation. Automated testing is very useful. It helps to save time and efforts and increases efficiency of software testing. But use of automated testing programs demands considering all the project peculiarities and careful estimation of reasonability of the testing programs application. Hidden Dangers of Utilizing Automated Testing Programs Are: 1. Forgetting the Aim of Testing Process When an instrument is bought or elaborated it may take much time and efforts to adjust it to the project. Frequently a software testing company spends more time on the instrument adjustments than on the software testing at the beginning. Testers may get carried away by the testing program and forget that their main objective is to check the system. software testing company So, when utilizing automated testing programs one should remember that the programs are part of the software testing process but not more important than the software testing itself. 2. Automated Testing Programs May Operate Not as Anticipated Despite careful elaboration and testing an automated testing program may contain errors and function incorrectly. It can take a lot of time and efforts to discover and fix them. Such incidents reduce efficiency of any web site testing, desktop testing or mobile application testing. 3. Off-The-Shelf Testing Tools Often Are Not as Effective as Expected There are many automated testing programs on the market. Vendors always assure that their tools are suitable for your project. But off-the-shelf testing tools are not customized. For example, an instrument can capture tester’s keystrokes and on their basis create code that repeats tester’s action. Received testing program needs considerable modifications to become efficient and reusable. TEST MY PROJECT
__label__pos
0.852777
? Log in No account? Create an account Previous Entry Share Next Entry "Current Location?" photogeek crschmidt Current location is cool. I've wanted to upload it myself in various capacities for a long time. But linking somethign that people will typically type in as free form to Google Maps is stupid. People will type 'Home', and linking that to google maps won't get you anywhere! So, I went through and fixed my style so that the location would no longer be linked to Google maps, as well as reordering the 'currents' so that location would be on the bottom instead of the top. So now, when I type 'Home" in my current location, it won't be displayed as "Maps.google.com/?q=Home" -- because it's not. It's home, in Cambridge. Of course, the rest of you will still see the links on your friends pages, but I've never optimized my journal for the users who are reading through friends pages: I've optimized it for *me*, and for my journal view pages. I can see why this was done, but I think this is a case where the engineers (or engineer *cough* Brad *cough*) should have pulled in their usability person before pushing it live :p It's still a pretty cool little box, but I don't like to see it off to what I see as a negative start. Then again, is there much on LJ that I *don't* see as a negative start? ;) Updated code is in Entry::print_metadata in my custom layer if anyone wants to crib it. Tags: , • 1 Works great for me. What was the spec? Usually, crying "usability" means that someone doesn't like something, and to avoid looking selfish by describing it in terms of things they want to do, they explain how some set of fictional users -- usually ridiculously helpless ones -- will be injured, and that's what this looked like. Chris explained up a bit how he'd prefer it to have been done and why, which is great, but there's a big difference between something that outright does not work and something that one wishes worked differently. Calling the latter the former seriously cuts down on the credibility of the points raised. I'm sorry, let me be more clear: I'm selfish, and I think that linking to http://maps.google.com/?q=home is non-ideal because it doesn't fit the way I think of things. I also think that this is true of most people using the site, but that's an obviously-biased opinion. (If everyone agreed with me on everything, my life would be so much easier.) Hopefully that makes how I feel more clear :) I know you're being a bit sarcastic there, but it's not only more clear, but easier to agree with! Let your opinions stand backed up by your own expertise, instead of getting caught up in usability and development process problems which end up amounting to an appeal to authority. Not entirely sarcastic: I know full well that I don't have the strength of numbers, or evidence, to back me up. I still know that linking to Google Maps *feels* wrong, and it feels wrong in a way that seems like it should be universally wrong for others. I probably was appealing to authority subconciously because I know that I have no more experience in this kind of thing than anyone else, so I'm no better an authority on the topic, therefore my opinion/expertise in this case is just as easily wrong as I consider others to be. So, if I just whine loud enough, everyone will ignore that and give me what I want, right? ... Right? • 1
__label__pos
0.701337
Results 1 to 4 of 4 Math Help - General Solution 1. #1 Member Joined Sep 2009 Posts 181 General Solution Hello, Can someone please help me figure out the general solution for this matrix? x+y+z = 0 2x+2y+2z = 0 3x+3y+3z = 0 Thanks! l Flipboi l Follow Math Help Forum on Facebook and Google+ 2. #2 Master Of Puppets pickslides's Avatar Joined Sep 2008 From Melbourne Posts 5,233 Thanks 29 Set it up as Ax = b \implies x = A^{-1}b where A is the coefficient matrix of x,y,z Follow Math Help Forum on Facebook and Google+ 3. #3 Member Joined Sep 2009 Posts 181 Quote Originally Posted by pickslides View Post Set it up as Ax = b \implies x = A^{-1}b where A is the coefficient matrix of x,y,z so take the inverse of A and multiple by b? [ 1 1 1 ]^-1 [ 0 ] [ 2 2 2 ] [ 0 ] [ 3 3 3 ] [ 0 ] the books says the answer is: x = -s-t y = s z = t what i did earlier was reduced it to row echelon form and obtained the matrix [ 1 1 1 ] [ 0 0 0 ] [ 0 0 0 ] but i don't get how y=s and z=t Follow Math Help Forum on Facebook and Google+ 4. #4 MHF Contributor Joined Apr 2005 Posts 17,089 Thanks 2041 Pickslides, the fact that the problem mentions a "general" solution should tell you that this problem does NOT have one unique solution and so the matrix A is NOT invertible! |flipboi| you did not write the original equations as a matrix and I see no reason to do so. You are making this much more difficult that it should be. x+y+z = 0 2x+2y+2z = 0 3x+3y+3z= 0 are all the same equation! So you really just have z= -x- y. That is the "general solution". x and y can be any numbers at all and z= -x- y. If you really intended \begin{bmatrix}1 & 1 & 1 \\ 2 & 2 & 2 \\ 3 & 3 & 3\end{bmatrix}\begin{bmatrix}x \\ y \\ z \end{bmatrix}= \begin{bmatrix}0 \\0 \\ 0\end{bmatrix} then the vector solution is \begin{bmatrix} x \\ y \\ z\end{bmatrix}= \begin{bmatrix}x \\ y \\ -x-y\end{bmatrix}= x\begin{bmatrix}1 \\ 0 \\ -1\end{bmatrix}+ y\begin{bmatrix}0 \\ 1 \\ -1\end{bmatrix} Row reducing to \begin{bmatrix}1 & 1 & 1 \\ 0 & 0 & 0 \\ 0 & 0 & 0\end{bmatrix} just tells you, again, that all three equations reduce to x+ y+ z= 0 so that z= -x -y. "but i don't get how y=s and z= t". I solved for z= -x- y so I could use x and y as parameters or just rename them "s" and "t" and write the solution as x= s, y= t, z= -s- t. Apparently in your text, they solve for x= -y- z. You don't "get" y= s and z= t, you assign those names. Just rename "y" as "s" and "z" as "t". Then x= -s- t, y= s, z= t. There are an infinite number of ways to write parametric equations for a "general" solution. Last edited by HallsofIvy; October 27th 2010 at 05:34 AM. Follow Math Help Forum on Facebook and Google+ Similar Math Help Forum Discussions 1. General Solution of a differential solution Posted in the Differential Equations Forum Replies: 4 Last Post: September 11th 2010, 02:49 AM 2. GENERAL SOLUTION f(x,t) please help Posted in the Differential Equations Forum Replies: 3 Last Post: April 11th 2010, 04:36 PM 3. General Solution Posted in the Differential Equations Forum Replies: 0 Last Post: March 8th 2010, 09:06 PM 4. Finding the general solution from a given particular solution. Posted in the Differential Equations Forum Replies: 5 Last Post: October 7th 2009, 01:44 AM 5. find the general solution when 1 solution is given Posted in the Differential Equations Forum Replies: 4 Last Post: March 4th 2009, 09:09 PM Search Tags /mathhelpforum @mathhelpforum
__label__pos
0.98887
xplodnow xplodnow - 7 months ago 38 Python Question Merge two arrays into an list of arrays Hi I am trying compile a bunch of arrays that I have in a dictionary using a for loop and I cant seem to find proper solution for this. Essentially what I have in a simplified form: dict['w1']=[1,2,3] dict['w2']=[4,5,6] dict['w3']=[7,8] x = [] for i in range(3): x = np.concatenate([x],[dict['w'+str(i+1)].values],axis=0) what it gives: x = [1,2,3,4,5,6,7,8] what I want: x = [[1,2,3],[4,5,6],[6,7]] I want to use the for loop because I have too many arrays to 'compile' and cant key in them one by one would be very inefficient. This way I can use the created array to plot a boxplot directly. A simiiliar question exists with no loop requirement but still does not have proper solution. Link Answer Comprehension: # using name as "dict" is not proper use "_dict" otherwise. dict['w1']=[1,2,3] dict['w2']=[4,5,6] dict['w3']=[7,8] x = [dict["w"+str(i)] for i in range(1, 4)] gives output: [[1, 2, 3], [4, 5, 6], [7, 8]]
__label__pos
0.546339